Completed
Branch EDTR/asset-purge (8983a0)
by
unknown
17:28 queued 09:00
created
core/admin/EE_Admin_Page_CPT.core.php 1 patch
Indentation   +1489 added lines, -1489 removed lines patch added patch discarded remove patch
@@ -27,474 +27,474 @@  discard block
 block discarded – undo
27 27
 {
28 28
 
29 29
 
30
-    /**
31
-     * This gets set in _setup_cpt
32
-     * It will contain the object for the custom post type.
33
-     *
34
-     * @var EE_CPT_Base
35
-     */
36
-    protected $_cpt_object;
37
-
38
-
39
-    /**
40
-     * a boolean flag to set whether the current route is a cpt route or not.
41
-     *
42
-     * @var bool
43
-     */
44
-    protected $_cpt_route = false;
45
-
46
-
47
-    /**
48
-     * This property allows cpt classes to define multiple routes as cpt routes.
49
-     * //in this array we define what the custom post type for this route is.
50
-     * array(
51
-     * 'route_name' => 'custom_post_type_slug'
52
-     * )
53
-     *
54
-     * @var array
55
-     */
56
-    protected $_cpt_routes = array();
57
-
58
-
59
-    /**
60
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
-     * in this format:
62
-     * array(
63
-     * 'post_type_slug' => 'edit_route'
64
-     * )
65
-     *
66
-     * @var array
67
-     */
68
-    protected $_cpt_edit_routes = array();
69
-
70
-
71
-    /**
72
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
73
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
74
-     * _cpt_model_names property should be in the following format: array(
75
-     * 'route_defined_by_action_param' => 'Model_Name')
76
-     *
77
-     * @var array $_cpt_model_names
78
-     */
79
-    protected $_cpt_model_names = array();
80
-
81
-
82
-    /**
83
-     * @var EE_CPT_Base
84
-     */
85
-    protected $_cpt_model_obj = false;
86
-
87
-
88
-    /**
89
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
90
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
91
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
92
-     * Registration of containers should be done before load_page_dependencies() is run.
93
-     *
94
-     * @var array()
95
-     */
96
-    protected $_autosave_containers = array();
97
-    protected $_autosave_fields = array();
98
-
99
-    /**
100
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
101
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
102
-     *
103
-     * @var array
104
-     */
105
-    protected $_pagenow_map;
106
-
107
-
108
-    /**
109
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
110
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
111
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
112
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
113
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
114
-     *
115
-     * @access protected
116
-     * @abstract
117
-     * @param  string      $post_id The ID of the cpt that was saved (so you can link relationally)
118
-     * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
119
-     * @return void
120
-     */
121
-    abstract protected function _insert_update_cpt_item($post_id, $post);
122
-
123
-
124
-    /**
125
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
126
-     *
127
-     * @abstract
128
-     * @access public
129
-     * @param  string $post_id The ID of the cpt that was trashed
130
-     * @return void
131
-     */
132
-    abstract public function trash_cpt_item($post_id);
133
-
134
-
135
-    /**
136
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
137
-     *
138
-     * @param  string $post_id theID of the cpt that was untrashed
139
-     * @return void
140
-     */
141
-    abstract public function restore_cpt_item($post_id);
142
-
143
-
144
-    /**
145
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
146
-     * from the db
147
-     *
148
-     * @param  string $post_id the ID of the cpt that was deleted
149
-     * @return void
150
-     */
151
-    abstract public function delete_cpt_item($post_id);
152
-
153
-
154
-    /**
155
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
156
-     *
157
-     * @access protected
158
-     * @return void
159
-     */
160
-    protected function _before_page_setup()
161
-    {
162
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
163
-        $this->_cpt_routes = array_merge(
164
-            array(
165
-                'create_new' => $this->page_slug,
166
-                'edit'       => $this->page_slug,
167
-                'trash'      => $this->page_slug,
168
-            ),
169
-            $this->_cpt_routes
170
-        );
171
-        // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
172
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ])
173
-            ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
174
-            : get_post_type_object($page);
175
-        // tweak pagenow for page loading.
176
-        if (! $this->_pagenow_map) {
177
-            $this->_pagenow_map = array(
178
-                'create_new' => 'post-new.php',
179
-                'edit'       => 'post.php',
180
-                'trash'      => 'post.php',
181
-            );
182
-        }
183
-        add_action('current_screen', array($this, 'modify_pagenow'));
184
-        // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
185
-        // get current page from autosave
186
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
187
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
188
-            : null;
189
-        $this->_current_page = isset($this->_req_data['current_page'])
190
-            ? $this->_req_data['current_page']
191
-            : $current_page;
192
-        // autosave... make sure its only for the correct page
193
-        // if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
194
-        // setup autosave ajax hook
195
-        // add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
196
-        // }
197
-    }
198
-
199
-
200
-    /**
201
-     * Simply ensure that we simulate the correct post route for cpt screens
202
-     *
203
-     * @param WP_Screen $current_screen
204
-     * @return void
205
-     */
206
-    public function modify_pagenow($current_screen)
207
-    {
208
-        global $pagenow, $hook_suffix;
209
-        // possibly reset pagenow.
210
-        if (! empty($this->_req_data['page'])
211
-            && $this->_req_data['page'] == $this->page_slug
212
-            && ! empty($this->_req_data['action'])
213
-            && isset($this->_pagenow_map[ $this->_req_data['action'] ])
214
-        ) {
215
-            $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
216
-            $hook_suffix = $pagenow;
217
-        }
218
-    }
219
-
220
-
221
-    /**
222
-     * This method is used to register additional autosave containers to the _autosave_containers property.
223
-     *
224
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
225
-     *       automatically register the id for the post metabox as a container.
226
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
227
-     *                    you would send along the id of a metabox container.
228
-     * @return void
229
-     */
230
-    protected function _register_autosave_containers($ids)
231
-    {
232
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
233
-    }
234
-
235
-
236
-    /**
237
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
238
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
239
-     */
240
-    protected function _set_autosave_containers()
241
-    {
242
-        global $wp_meta_boxes;
243
-        $containers = array();
244
-        if (empty($wp_meta_boxes)) {
245
-            return;
246
-        }
247
-        $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
248
-        foreach ($current_metaboxes as $box_context) {
249
-            foreach ($box_context as $box_details) {
250
-                foreach ($box_details as $box) {
251
-                    if (is_array($box) && is_array($box['callback'])
252
-                        && (
253
-                            $box['callback'][0] instanceof EE_Admin_Page
254
-                            || $box['callback'][0] instanceof EE_Admin_Hooks
255
-                        )
256
-                    ) {
257
-                        $containers[] = $box['id'];
258
-                    }
259
-                }
260
-            }
261
-        }
262
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
263
-        // add hidden inputs container
264
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
265
-    }
266
-
267
-
268
-    protected function _load_autosave_scripts_styles()
269
-    {
270
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
30
+	/**
31
+	 * This gets set in _setup_cpt
32
+	 * It will contain the object for the custom post type.
33
+	 *
34
+	 * @var EE_CPT_Base
35
+	 */
36
+	protected $_cpt_object;
37
+
38
+
39
+	/**
40
+	 * a boolean flag to set whether the current route is a cpt route or not.
41
+	 *
42
+	 * @var bool
43
+	 */
44
+	protected $_cpt_route = false;
45
+
46
+
47
+	/**
48
+	 * This property allows cpt classes to define multiple routes as cpt routes.
49
+	 * //in this array we define what the custom post type for this route is.
50
+	 * array(
51
+	 * 'route_name' => 'custom_post_type_slug'
52
+	 * )
53
+	 *
54
+	 * @var array
55
+	 */
56
+	protected $_cpt_routes = array();
57
+
58
+
59
+	/**
60
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
+	 * in this format:
62
+	 * array(
63
+	 * 'post_type_slug' => 'edit_route'
64
+	 * )
65
+	 *
66
+	 * @var array
67
+	 */
68
+	protected $_cpt_edit_routes = array();
69
+
70
+
71
+	/**
72
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
73
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
74
+	 * _cpt_model_names property should be in the following format: array(
75
+	 * 'route_defined_by_action_param' => 'Model_Name')
76
+	 *
77
+	 * @var array $_cpt_model_names
78
+	 */
79
+	protected $_cpt_model_names = array();
80
+
81
+
82
+	/**
83
+	 * @var EE_CPT_Base
84
+	 */
85
+	protected $_cpt_model_obj = false;
86
+
87
+
88
+	/**
89
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
90
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
91
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
92
+	 * Registration of containers should be done before load_page_dependencies() is run.
93
+	 *
94
+	 * @var array()
95
+	 */
96
+	protected $_autosave_containers = array();
97
+	protected $_autosave_fields = array();
98
+
99
+	/**
100
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
101
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
102
+	 *
103
+	 * @var array
104
+	 */
105
+	protected $_pagenow_map;
106
+
107
+
108
+	/**
109
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
110
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
111
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
112
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
113
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
114
+	 *
115
+	 * @access protected
116
+	 * @abstract
117
+	 * @param  string      $post_id The ID of the cpt that was saved (so you can link relationally)
118
+	 * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
119
+	 * @return void
120
+	 */
121
+	abstract protected function _insert_update_cpt_item($post_id, $post);
122
+
123
+
124
+	/**
125
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
126
+	 *
127
+	 * @abstract
128
+	 * @access public
129
+	 * @param  string $post_id The ID of the cpt that was trashed
130
+	 * @return void
131
+	 */
132
+	abstract public function trash_cpt_item($post_id);
133
+
134
+
135
+	/**
136
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
137
+	 *
138
+	 * @param  string $post_id theID of the cpt that was untrashed
139
+	 * @return void
140
+	 */
141
+	abstract public function restore_cpt_item($post_id);
142
+
143
+
144
+	/**
145
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
146
+	 * from the db
147
+	 *
148
+	 * @param  string $post_id the ID of the cpt that was deleted
149
+	 * @return void
150
+	 */
151
+	abstract public function delete_cpt_item($post_id);
152
+
153
+
154
+	/**
155
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
156
+	 *
157
+	 * @access protected
158
+	 * @return void
159
+	 */
160
+	protected function _before_page_setup()
161
+	{
162
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
163
+		$this->_cpt_routes = array_merge(
164
+			array(
165
+				'create_new' => $this->page_slug,
166
+				'edit'       => $this->page_slug,
167
+				'trash'      => $this->page_slug,
168
+			),
169
+			$this->_cpt_routes
170
+		);
171
+		// let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
172
+		$this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ])
173
+			? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ])
174
+			: get_post_type_object($page);
175
+		// tweak pagenow for page loading.
176
+		if (! $this->_pagenow_map) {
177
+			$this->_pagenow_map = array(
178
+				'create_new' => 'post-new.php',
179
+				'edit'       => 'post.php',
180
+				'trash'      => 'post.php',
181
+			);
182
+		}
183
+		add_action('current_screen', array($this, 'modify_pagenow'));
184
+		// TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
185
+		// get current page from autosave
186
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
187
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
188
+			: null;
189
+		$this->_current_page = isset($this->_req_data['current_page'])
190
+			? $this->_req_data['current_page']
191
+			: $current_page;
192
+		// autosave... make sure its only for the correct page
193
+		// if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
194
+		// setup autosave ajax hook
195
+		// add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
196
+		// }
197
+	}
198
+
199
+
200
+	/**
201
+	 * Simply ensure that we simulate the correct post route for cpt screens
202
+	 *
203
+	 * @param WP_Screen $current_screen
204
+	 * @return void
205
+	 */
206
+	public function modify_pagenow($current_screen)
207
+	{
208
+		global $pagenow, $hook_suffix;
209
+		// possibly reset pagenow.
210
+		if (! empty($this->_req_data['page'])
211
+			&& $this->_req_data['page'] == $this->page_slug
212
+			&& ! empty($this->_req_data['action'])
213
+			&& isset($this->_pagenow_map[ $this->_req_data['action'] ])
214
+		) {
215
+			$pagenow = $this->_pagenow_map[ $this->_req_data['action'] ];
216
+			$hook_suffix = $pagenow;
217
+		}
218
+	}
219
+
220
+
221
+	/**
222
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
223
+	 *
224
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
225
+	 *       automatically register the id for the post metabox as a container.
226
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
227
+	 *                    you would send along the id of a metabox container.
228
+	 * @return void
229
+	 */
230
+	protected function _register_autosave_containers($ids)
231
+	{
232
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
233
+	}
234
+
235
+
236
+	/**
237
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
238
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
239
+	 */
240
+	protected function _set_autosave_containers()
241
+	{
242
+		global $wp_meta_boxes;
243
+		$containers = array();
244
+		if (empty($wp_meta_boxes)) {
245
+			return;
246
+		}
247
+		$current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array();
248
+		foreach ($current_metaboxes as $box_context) {
249
+			foreach ($box_context as $box_details) {
250
+				foreach ($box_details as $box) {
251
+					if (is_array($box) && is_array($box['callback'])
252
+						&& (
253
+							$box['callback'][0] instanceof EE_Admin_Page
254
+							|| $box['callback'][0] instanceof EE_Admin_Hooks
255
+						)
256
+					) {
257
+						$containers[] = $box['id'];
258
+					}
259
+				}
260
+			}
261
+		}
262
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
263
+		// add hidden inputs container
264
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
265
+	}
266
+
267
+
268
+	protected function _load_autosave_scripts_styles()
269
+	{
270
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
271 271
         wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2
272 272
 
273
-        // filter _autosave_containers
274
-        $containers = apply_filters(
275
-            'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
276
-            $this->_autosave_containers,
277
-            $this
278
-        );
279
-        $containers = apply_filters(
280
-            'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
281
-            $containers,
282
-            $this
283
-        );
284
-
285
-        wp_localize_script(
286
-            'event_editor_js',
287
-            'EE_AUTOSAVE_IDS',
288
-            $containers
289
-        ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
290
-
291
-        $unsaved_data_msg = array(
292
-            'eventmsg'     => sprintf(
293
-                __(
294
-                    "The changes you made to this %s will be lost if you navigate away from this page.",
295
-                    'event_espresso'
296
-                ),
297
-                $this->_cpt_object->labels->singular_name
298
-            ),
299
-            'inputChanged' => 0,
300
-        );
301
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
302
-    }
303
-
304
-
305
-    public function load_page_dependencies()
306
-    {
307
-        try {
308
-            $this->_load_page_dependencies();
309
-        } catch (EE_Error $e) {
310
-            $e->get_error();
311
-        }
312
-    }
313
-
314
-
315
-    /**
316
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
317
-     *
318
-     * @access protected
319
-     * @return void
320
-     */
321
-    protected function _load_page_dependencies()
322
-    {
323
-        // we only add stuff if this is a cpt_route!
324
-        if (! $this->_cpt_route) {
325
-            parent::_load_page_dependencies();
326
-            return;
327
-        }
328
-        // now let's do some automatic filters into the wp_system
329
-        // and we'll check to make sure the CHILD class
330
-        // automatically has the required methods in place.
331
-        // the following filters are for setting all the redirects
332
-        // on DEFAULT WP custom post type actions
333
-        // let's add a hidden input to the post-edit form
334
-        // so we know when we have to trigger our custom redirects!
335
-        // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
336
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
337
-        // inject our Admin page nav tabs...
338
-        // let's make sure the nav tabs are set if they aren't already
339
-        // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
340
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
341
-        // modify the post_updated messages array
342
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
343
-        // add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
344
-        // cpts use the same format for shortlinks as posts!
345
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
346
-        // This basically allows us to change the title of the "publish" metabox area
347
-        // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
348
-        if (! empty($this->_labels['publishbox'])) {
349
-            $box_label = is_array($this->_labels['publishbox'])
350
-                         && isset($this->_labels['publishbox'][ $this->_req_action ])
351
-                ? $this->_labels['publishbox'][ $this->_req_action ]
352
-                : $this->_labels['publishbox'];
353
-            add_meta_box(
354
-                'submitdiv',
355
-                $box_label,
356
-                'post_submit_meta_box',
357
-                $this->_cpt_routes[ $this->_req_action ],
358
-                'side',
359
-                'core'
360
-            );
361
-        }
362
-        // let's add page_templates metabox if this cpt added support for it.
363
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
364
-            add_meta_box(
365
-                'page_templates',
366
-                __('Page Template', 'event_espresso'),
367
-                array($this, 'page_template_meta_box'),
368
-                $this->_cpt_routes[ $this->_req_action ],
369
-                'side',
370
-                'default'
371
-            );
372
-        }
373
-        // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
374
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
375
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
376
-        }
377
-        // add preview button
378
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
379
-        // insert our own post_stati dropdown
380
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
381
-        // This allows adding additional information to the publish post submitbox on the wp post edit form
382
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
383
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
384
-        }
385
-        // This allows for adding additional stuff after the title field on the wp post edit form.
386
-        // This is also before the wp_editor for post description field.
387
-        if (method_exists($this, 'edit_form_after_title')) {
388
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
389
-        }
390
-        /**
391
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
392
-         */
393
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
394
-        parent::_load_page_dependencies();
395
-        // notice we are ALSO going to load the pagenow hook set for this route
396
-        // (see _before_page_setup for the reset of the pagenow global ).
397
-        // This is for any plugins that are doing things properly
398
-        // and hooking into the load page hook for core wp cpt routes.
399
-        global $pagenow;
400
-        add_action('load-' . $pagenow, array($this, 'modify_current_screen'), 20);
401
-        do_action('load-' . $pagenow);
402
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
403
-        // we route REALLY early.
404
-        try {
405
-            $this->_route_admin_request();
406
-        } catch (EE_Error $e) {
407
-            $e->get_error();
408
-        }
409
-    }
410
-
411
-
412
-    /**
413
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
414
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
415
-     * route instead.
416
-     *
417
-     * @param string $good_protocol_url The escaped url.
418
-     * @param string $original_url      The original url.
419
-     * @param string $_context          The context sent to the esc_url method.
420
-     * @return string possibly a new url for our route.
421
-     */
422
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
423
-    {
424
-        $routes_to_match = array(
425
-            0 => array(
426
-                'edit.php?post_type=espresso_attendees',
427
-                'admin.php?page=espresso_registrations&action=contact_list',
428
-            ),
429
-            1 => array(
430
-                'edit.php?post_type=' . $this->_cpt_object->name,
431
-                'admin.php?page=' . $this->_cpt_object->name,
432
-            ),
433
-        );
434
-        foreach ($routes_to_match as $route_matches) {
435
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
436
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
437
-            }
438
-        }
439
-        return $good_protocol_url;
440
-    }
441
-
442
-
443
-    /**
444
-     * Determine whether the current cpt supports page templates or not.
445
-     *
446
-     * @since %VER%
447
-     * @param string $cpt_name The cpt slug we're checking on.
448
-     * @return bool True supported, false not.
449
-     * @throws InvalidArgumentException
450
-     * @throws InvalidDataTypeException
451
-     * @throws InvalidInterfaceException
452
-     */
453
-    private function _supports_page_templates($cpt_name)
454
-    {
455
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
456
-        $custom_post_types = $this->loader->getShared(
457
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
458
-        );
459
-        $cpt_args = $custom_post_types->getDefinitions();
460
-        $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
461
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
462
-
463
-        // if the installed version of WP is > 4.7 we do some additional checks.
464
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
465
-            $post_templates = wp_get_theme()->get_post_templates();
466
-            // if there are $post_templates for this cpt, then we return false for this method because
467
-            // that means we aren't going to load our page template manager and leave that up to the native
468
-            // cpt template manager.
469
-            $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
470
-        }
471
-
472
-        return $cpt_has_support;
473
-    }
474
-
475
-
476
-    /**
477
-     * Callback for the page_templates metabox selector.
478
-     *
479
-     * @since %VER%
480
-     * @return void
481
-     */
482
-    public function page_template_meta_box()
483
-    {
484
-        global $post;
485
-        $template = '';
486
-
487
-        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
488
-            $page_template_count = count(get_page_templates());
489
-        } else {
490
-            $page_template_count = count(get_page_templates($post));
491
-        };
492
-
493
-        if ($page_template_count) {
494
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
495
-            $template = ! empty($page_template) ? $page_template : '';
496
-        }
497
-        ?>
273
+		// filter _autosave_containers
274
+		$containers = apply_filters(
275
+			'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
276
+			$this->_autosave_containers,
277
+			$this
278
+		);
279
+		$containers = apply_filters(
280
+			'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
281
+			$containers,
282
+			$this
283
+		);
284
+
285
+		wp_localize_script(
286
+			'event_editor_js',
287
+			'EE_AUTOSAVE_IDS',
288
+			$containers
289
+		); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
290
+
291
+		$unsaved_data_msg = array(
292
+			'eventmsg'     => sprintf(
293
+				__(
294
+					"The changes you made to this %s will be lost if you navigate away from this page.",
295
+					'event_espresso'
296
+				),
297
+				$this->_cpt_object->labels->singular_name
298
+			),
299
+			'inputChanged' => 0,
300
+		);
301
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
302
+	}
303
+
304
+
305
+	public function load_page_dependencies()
306
+	{
307
+		try {
308
+			$this->_load_page_dependencies();
309
+		} catch (EE_Error $e) {
310
+			$e->get_error();
311
+		}
312
+	}
313
+
314
+
315
+	/**
316
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
317
+	 *
318
+	 * @access protected
319
+	 * @return void
320
+	 */
321
+	protected function _load_page_dependencies()
322
+	{
323
+		// we only add stuff if this is a cpt_route!
324
+		if (! $this->_cpt_route) {
325
+			parent::_load_page_dependencies();
326
+			return;
327
+		}
328
+		// now let's do some automatic filters into the wp_system
329
+		// and we'll check to make sure the CHILD class
330
+		// automatically has the required methods in place.
331
+		// the following filters are for setting all the redirects
332
+		// on DEFAULT WP custom post type actions
333
+		// let's add a hidden input to the post-edit form
334
+		// so we know when we have to trigger our custom redirects!
335
+		// Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
336
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
337
+		// inject our Admin page nav tabs...
338
+		// let's make sure the nav tabs are set if they aren't already
339
+		// if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
340
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
341
+		// modify the post_updated messages array
342
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
343
+		// add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
344
+		// cpts use the same format for shortlinks as posts!
345
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
346
+		// This basically allows us to change the title of the "publish" metabox area
347
+		// on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
348
+		if (! empty($this->_labels['publishbox'])) {
349
+			$box_label = is_array($this->_labels['publishbox'])
350
+						 && isset($this->_labels['publishbox'][ $this->_req_action ])
351
+				? $this->_labels['publishbox'][ $this->_req_action ]
352
+				: $this->_labels['publishbox'];
353
+			add_meta_box(
354
+				'submitdiv',
355
+				$box_label,
356
+				'post_submit_meta_box',
357
+				$this->_cpt_routes[ $this->_req_action ],
358
+				'side',
359
+				'core'
360
+			);
361
+		}
362
+		// let's add page_templates metabox if this cpt added support for it.
363
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
364
+			add_meta_box(
365
+				'page_templates',
366
+				__('Page Template', 'event_espresso'),
367
+				array($this, 'page_template_meta_box'),
368
+				$this->_cpt_routes[ $this->_req_action ],
369
+				'side',
370
+				'default'
371
+			);
372
+		}
373
+		// this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
374
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
375
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
376
+		}
377
+		// add preview button
378
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
379
+		// insert our own post_stati dropdown
380
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
381
+		// This allows adding additional information to the publish post submitbox on the wp post edit form
382
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
383
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
384
+		}
385
+		// This allows for adding additional stuff after the title field on the wp post edit form.
386
+		// This is also before the wp_editor for post description field.
387
+		if (method_exists($this, 'edit_form_after_title')) {
388
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
389
+		}
390
+		/**
391
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
392
+		 */
393
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
394
+		parent::_load_page_dependencies();
395
+		// notice we are ALSO going to load the pagenow hook set for this route
396
+		// (see _before_page_setup for the reset of the pagenow global ).
397
+		// This is for any plugins that are doing things properly
398
+		// and hooking into the load page hook for core wp cpt routes.
399
+		global $pagenow;
400
+		add_action('load-' . $pagenow, array($this, 'modify_current_screen'), 20);
401
+		do_action('load-' . $pagenow);
402
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
403
+		// we route REALLY early.
404
+		try {
405
+			$this->_route_admin_request();
406
+		} catch (EE_Error $e) {
407
+			$e->get_error();
408
+		}
409
+	}
410
+
411
+
412
+	/**
413
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
414
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
415
+	 * route instead.
416
+	 *
417
+	 * @param string $good_protocol_url The escaped url.
418
+	 * @param string $original_url      The original url.
419
+	 * @param string $_context          The context sent to the esc_url method.
420
+	 * @return string possibly a new url for our route.
421
+	 */
422
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
423
+	{
424
+		$routes_to_match = array(
425
+			0 => array(
426
+				'edit.php?post_type=espresso_attendees',
427
+				'admin.php?page=espresso_registrations&action=contact_list',
428
+			),
429
+			1 => array(
430
+				'edit.php?post_type=' . $this->_cpt_object->name,
431
+				'admin.php?page=' . $this->_cpt_object->name,
432
+			),
433
+		);
434
+		foreach ($routes_to_match as $route_matches) {
435
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
436
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
437
+			}
438
+		}
439
+		return $good_protocol_url;
440
+	}
441
+
442
+
443
+	/**
444
+	 * Determine whether the current cpt supports page templates or not.
445
+	 *
446
+	 * @since %VER%
447
+	 * @param string $cpt_name The cpt slug we're checking on.
448
+	 * @return bool True supported, false not.
449
+	 * @throws InvalidArgumentException
450
+	 * @throws InvalidDataTypeException
451
+	 * @throws InvalidInterfaceException
452
+	 */
453
+	private function _supports_page_templates($cpt_name)
454
+	{
455
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
456
+		$custom_post_types = $this->loader->getShared(
457
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
458
+		);
459
+		$cpt_args = $custom_post_types->getDefinitions();
460
+		$cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array();
461
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
462
+
463
+		// if the installed version of WP is > 4.7 we do some additional checks.
464
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
465
+			$post_templates = wp_get_theme()->get_post_templates();
466
+			// if there are $post_templates for this cpt, then we return false for this method because
467
+			// that means we aren't going to load our page template manager and leave that up to the native
468
+			// cpt template manager.
469
+			$cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false;
470
+		}
471
+
472
+		return $cpt_has_support;
473
+	}
474
+
475
+
476
+	/**
477
+	 * Callback for the page_templates metabox selector.
478
+	 *
479
+	 * @since %VER%
480
+	 * @return void
481
+	 */
482
+	public function page_template_meta_box()
483
+	{
484
+		global $post;
485
+		$template = '';
486
+
487
+		if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
488
+			$page_template_count = count(get_page_templates());
489
+		} else {
490
+			$page_template_count = count(get_page_templates($post));
491
+		};
492
+
493
+		if ($page_template_count) {
494
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
495
+			$template = ! empty($page_template) ? $page_template : '';
496
+		}
497
+		?>
498 498
         <p><strong><?php _e('Template', 'event_espresso') ?></strong></p>
499 499
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template', 'event_espresso') ?></label><select
500 500
         name="page_template" id="page_template">
@@ -502,511 +502,511 @@  discard block
 block discarded – undo
502 502
         <?php page_template_dropdown($template); ?>
503 503
     </select>
504 504
         <?php
505
-    }
506
-
507
-
508
-    /**
509
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
510
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
511
-     *
512
-     * @param  string $return    the current html
513
-     * @param  int    $id        the post id for the page
514
-     * @param  string $new_title What the title is
515
-     * @param  string $new_slug  what the slug is
516
-     * @return string            The new html string for the permalink area
517
-     */
518
-    public function preview_button_html($return, $id, $new_title, $new_slug)
519
-    {
520
-        $post = get_post($id);
521
-        if ('publish' !== get_post_status($post)) {
522
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
523
-                       . get_preview_post_link($id)
524
-                       . '" class="button button-small">'
525
-                       . __('Preview', 'event_espresso')
526
-                       . '</a></span>'
527
-                       . "\n";
528
-        }
529
-        return $return;
530
-    }
531
-
532
-
533
-    /**
534
-     * add our custom post stati dropdown on the wp post page for this cpt
535
-     *
536
-     * @return void
537
-     */
538
-    public function custom_post_stati_dropdown()
539
-    {
540
-
541
-        $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
542
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
543
-            ? $statuses[ $this->_cpt_model_obj->status() ]
544
-            : '';
545
-        $template_args = array(
546
-            'cur_status'            => $this->_cpt_model_obj->status(),
547
-            'statuses'              => $statuses,
548
-            'cur_status_label'      => $cur_status_label,
549
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
550
-        );
551
-        // we'll add a trash post status (WP doesn't add one for some reason)
552
-        if ($this->_cpt_model_obj->status() === 'trash') {
553
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
554
-            $statuses['trash'] = __('Trashed', 'event_espresso');
555
-            $template_args['statuses'] = $statuses;
556
-        }
557
-
558
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
559
-        EEH_Template::display_template($template, $template_args);
560
-    }
561
-
562
-
563
-    public function setup_autosave_hooks()
564
-    {
565
-        $this->_set_autosave_containers();
566
-        $this->_load_autosave_scripts_styles();
567
-    }
568
-
569
-
570
-    /**
571
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
572
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
573
-     * for the nonce in here, but then this method looks for two things:
574
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
575
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
576
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
577
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
578
-     * template args.
579
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
580
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
581
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
582
-     *    $this->_template_args['data']['items'] = array(
583
-     *        'event-datetime-ids' => '1,2,3';
584
-     *    );
585
-     *    Keep in mind the following things:
586
-     *    - "where" index is for the input with the id as that string.
587
-     *    - "what" index is what will be used for the value of that input.
588
-     *
589
-     * @return void
590
-     */
591
-    public function do_extra_autosave_stuff()
592
-    {
593
-        // next let's check for the autosave nonce (we'll use _verify_nonce )
594
-        $nonce = isset($this->_req_data['autosavenonce'])
595
-            ? $this->_req_data['autosavenonce']
596
-            : null;
597
-        $this->_verify_nonce($nonce, 'autosave');
598
-        // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
599
-        if (! defined('DOING_AUTOSAVE')) {
600
-            define('DOING_AUTOSAVE', true);
601
-        }
602
-        // if we made it here then the nonce checked out.  Let's run our methods and actions
603
-        $autosave = "_ee_autosave_{$this->_current_view}";
604
-        if (method_exists($this, $autosave)) {
605
-            $this->$autosave();
606
-        } else {
607
-            $this->_template_args['success'] = true;
608
-        }
609
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
610
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
611
-        // now let's return json
612
-        $this->_return_json();
613
-    }
614
-
615
-
616
-    /**
617
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
618
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
619
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
620
-     *
621
-     * @access protected
622
-     * @throws EE_Error
623
-     * @return void
624
-     */
625
-    protected function _extend_page_config_for_cpt()
626
-    {
627
-        // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
628
-        if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
629
-            return;
630
-        }
631
-        // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
632
-        if (! empty($this->_cpt_object)) {
633
-            $this->_page_routes = array_merge(
634
-                array(
635
-                    'create_new' => '_create_new_cpt_item',
636
-                    'edit'       => '_edit_cpt_item',
637
-                ),
638
-                $this->_page_routes
639
-            );
640
-            $this->_page_config = array_merge(
641
-                array(
642
-                    'create_new' => array(
643
-                        'nav'           => array(
644
-                            'label' => $this->_cpt_object->labels->add_new_item,
645
-                            'order' => 5,
646
-                        ),
647
-                        'require_nonce' => false,
648
-                    ),
649
-                    'edit'       => array(
650
-                        'nav'           => array(
651
-                            'label'      => $this->_cpt_object->labels->edit_item,
652
-                            'order'      => 5,
653
-                            'persistent' => false,
654
-                            'url'        => '',
655
-                        ),
656
-                        'require_nonce' => false,
657
-                    ),
658
-                ),
659
-                $this->_page_config
660
-            );
661
-        }
662
-        // load the next section only if this is a matching cpt route as set in the cpt routes array.
663
-        if (! isset($this->_cpt_routes[ $this->_req_action ])) {
664
-            return;
665
-        }
666
-        $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
667
-        // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
668
-        if (empty($this->_cpt_object)) {
669
-            $msg = sprintf(
670
-                __(
671
-                    'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).',
672
-                    'event_espresso'
673
-                ),
674
-                $this->page_slug,
675
-                $this->_req_action,
676
-                get_class($this)
677
-            );
678
-            throw new EE_Error($msg);
679
-        }
680
-        if ($this->_cpt_route) {
681
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
682
-            $this->_set_model_object($id);
683
-        }
684
-    }
685
-
686
-
687
-    /**
688
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
689
-     *
690
-     * @access protected
691
-     * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
692
-     * @param bool   $ignore_route_check
693
-     * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
694
-     * @throws EE_Error
695
-     * @throws InvalidArgumentException
696
-     * @throws InvalidDataTypeException
697
-     * @throws InvalidInterfaceException
698
-     * @throws ReflectionException
699
-     */
700
-    protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
701
-    {
702
-        $model = null;
703
-        if (empty($this->_cpt_model_names)
704
-            || (
705
-                ! $ignore_route_check
706
-                && ! isset($this->_cpt_routes[ $this->_req_action ])
707
-            ) || (
708
-                $this->_cpt_model_obj instanceof EE_CPT_Base
709
-                && $this->_cpt_model_obj->ID() === $id
710
-            )
711
-        ) {
712
-            // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
713
-            return;
714
-        }
715
-        // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
716
-        if ($ignore_route_check) {
717
-            $post_type = get_post_type($id);
718
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
719
-            $custom_post_types = $this->loader->getShared(
720
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
721
-            );
722
-            $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
723
-            if (isset($model_names[ $post_type ])) {
724
-                $model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
725
-            }
726
-        } else {
727
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
728
-        }
729
-        if ($model instanceof EEM_Base) {
730
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
731
-        }
732
-        do_action(
733
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
734
-            $this->_cpt_model_obj,
735
-            $req_type
736
-        );
737
-    }
738
-
739
-
740
-    /**
741
-     * admin_init_global
742
-     * This runs all the code that we want executed within the WP admin_init hook.
743
-     * This method executes for ALL EE Admin pages.
744
-     *
745
-     * @access public
746
-     * @return void
747
-     */
748
-    public function admin_init_global()
749
-    {
750
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
751
-        // its possible this is a new save so let's catch that instead
752
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
753
-        $post_type = $post ? $post->post_type : false;
754
-        $current_route = isset($this->_req_data['current_route'])
755
-            ? $this->_req_data['current_route']
756
-            : 'shouldneverwork';
757
-        $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
758
-            ? $this->_cpt_routes[ $current_route ]
759
-            : '';
760
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
761
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
762
-        if ($post_type === $route_to_check) {
763
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
764
-        }
765
-        // now let's filter redirect if we're on a revision page and the revision is for an event CPT.
766
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
767
-        if (! empty($revision)) {
768
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
769
-            // doing a restore?
770
-            if (! empty($action) && $action === 'restore') {
771
-                // get post for revision
772
-                $rev_post = get_post($revision);
773
-                $rev_parent = get_post($rev_post->post_parent);
774
-                // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
775
-                if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
776
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
777
-                    // restores of revisions
778
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
779
-                }
780
-            }
781
-        }
782
-        // NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
783
-        if ($post_type && $post_type === $route_to_check) {
784
-            // $post_id, $post
785
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
786
-            // $post_id
787
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
788
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
789
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
790
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
791
-        }
792
-    }
793
-
794
-
795
-    /**
796
-     * Callback for the WordPress trashed_post hook.
797
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
798
-     *
799
-     * @param int $post_id
800
-     * @throws \EE_Error
801
-     */
802
-    public function before_trash_cpt_item($post_id)
803
-    {
804
-        $this->_set_model_object($post_id, true, 'trash');
805
-        // if our cpt object isn't existent then get out immediately.
806
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
807
-            return;
808
-        }
809
-        $this->trash_cpt_item($post_id);
810
-    }
811
-
812
-
813
-    /**
814
-     * Callback for the WordPress untrashed_post hook.
815
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
816
-     *
817
-     * @param $post_id
818
-     * @throws \EE_Error
819
-     */
820
-    public function before_restore_cpt_item($post_id)
821
-    {
822
-        $this->_set_model_object($post_id, true, 'restore');
823
-        // if our cpt object isn't existent then get out immediately.
824
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
825
-            return;
826
-        }
827
-        $this->restore_cpt_item($post_id);
828
-    }
829
-
830
-
831
-    /**
832
-     * Callback for the WordPress after_delete_post hook.
833
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
834
-     *
835
-     * @param $post_id
836
-     * @throws \EE_Error
837
-     */
838
-    public function before_delete_cpt_item($post_id)
839
-    {
840
-        $this->_set_model_object($post_id, true, 'delete');
841
-        // if our cpt object isn't existent then get out immediately.
842
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
843
-            return;
844
-        }
845
-        $this->delete_cpt_item($post_id);
846
-    }
847
-
848
-
849
-    /**
850
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
851
-     * accordingly.
852
-     *
853
-     * @return void
854
-     * @throws EE_Error
855
-     * @throws InvalidArgumentException
856
-     * @throws InvalidDataTypeException
857
-     * @throws InvalidInterfaceException
858
-     * @throws ReflectionException
859
-     */
860
-    public function verify_cpt_object()
861
-    {
862
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
863
-        // verify event object
864
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
865
-            throw new EE_Error(
866
-                sprintf(
867
-                    __(
868
-                        'Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
869
-                        'event_espresso'
870
-                    ),
871
-                    $label
872
-                )
873
-            );
874
-        }
875
-        // if auto-draft then throw an error
876
-        if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
877
-            EE_Error::overwrite_errors();
878
-            EE_Error::add_error(
879
-                sprintf(
880
-                    __(
881
-                        'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.',
882
-                        'event_espresso'
883
-                    ),
884
-                    $label
885
-                ),
886
-                __FILE__,
887
-                __FUNCTION__,
888
-                __LINE__
889
-            );
890
-        }
891
-        $admin_config = $this->loader->getShared('EE_Admin_Config');
892
-        if ($admin_config->useAdvancedEditor()) {
893
-            $this->loadEspressoEditorAssetManager();
894
-        }
895
-    }
896
-
897
-
898
-    /**
899
-     * admin_footer_scripts_global
900
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
901
-     * will apply on ALL EE_Admin pages.
902
-     *
903
-     * @access public
904
-     * @return void
905
-     */
906
-    public function admin_footer_scripts_global()
907
-    {
908
-        $this->_add_admin_page_ajax_loading_img();
909
-        $this->_add_admin_page_overlay();
910
-    }
911
-
912
-
913
-    /**
914
-     * add in any global scripts for cpt routes
915
-     *
916
-     * @return void
917
-     */
918
-    public function load_global_scripts_styles()
919
-    {
920
-        parent::load_global_scripts_styles();
921
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
922
-            // setup custom post status object for localize script but only if we've got a cpt object
923
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
924
-            if (! empty($statuses)) {
925
-                // get ALL statuses!
926
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
927
-                // setup object
928
-                $ee_cpt_statuses = array();
929
-                foreach ($statuses as $status => $label) {
930
-                    $ee_cpt_statuses[ $status ] = array(
931
-                        'label'      => $label,
932
-                        'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
933
-                    );
934
-                }
935
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
936
-            }
937
-        }
938
-    }
939
-
940
-
941
-    /**
942
-     * @throws InvalidArgumentException
943
-     * @throws InvalidDataTypeException
944
-     * @throws InvalidInterfaceException
945
-     */
946
-    private function loadEspressoEditorAssetManager()
947
-    {
948
-        EE_Dependency_Map::register_dependencies(
949
-            'EventEspresso\core\domain\services\assets\EspressoEditorAssetManager',
950
-            array(
951
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
952
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
953
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
954
-            )
955
-        );
956
-        $this->loader->getShared(
957
-            'EventEspresso\core\domain\services\assets\EspressoEditorAssetManager'
958
-        );
959
-        add_action('admin_enqueue_scripts', array($this, 'enqueueEspressoEditorAssets'), 100);
960
-    }
961
-
962
-
963
-    /**
964
-     * enqueue_scripts - Load the scripts and css
965
-     *
966
-     * @return void
967
-     * @throws DomainException
968
-     */
969
-    public function enqueueEspressoEditorAssets()
970
-    {
971
-        wp_enqueue_style(EspressoEditorAssetManager::CSS_HANDLE_EDITOR);
972
-        // wp_enqueue_style(EspressoEditorAssetManager::CSS_HANDLE_EDITOR_PROTOTYPE);
973
-        wp_enqueue_script(EspressoEditorAssetManager::JS_HANDLE_EDITOR);
974
-        // wp_enqueue_script(EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE);
975
-    }
976
-
977
-    /**
978
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
979
-     * insert/updates
980
-     *
981
-     * @param  int     $post_id ID of post being updated
982
-     * @param  WP_Post $post    Post object from WP
983
-     * @param  bool    $update  Whether this is an update or a new save.
984
-     * @return void
985
-     * @throws \EE_Error
986
-     */
987
-    public function insert_update($post_id, $post, $update)
988
-    {
989
-        // make sure that if this is a revision OR trash action that we don't do any updates!
990
-        if (isset($this->_req_data['action'])
991
-            && (
992
-                $this->_req_data['action'] === 'restore'
993
-                || $this->_req_data['action'] === 'trash'
994
-            )
995
-        ) {
996
-            return;
997
-        }
998
-        $this->_set_model_object($post_id, true, 'insert_update');
999
-        // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
1000
-        if ($update
1001
-            && (
1002
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
1003
-                || $this->_cpt_model_obj->ID() !== $post_id
1004
-            )
1005
-        ) {
1006
-            return;
1007
-        }
1008
-        // check for autosave and update our req_data property accordingly.
1009
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
505
+	}
506
+
507
+
508
+	/**
509
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
510
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
511
+	 *
512
+	 * @param  string $return    the current html
513
+	 * @param  int    $id        the post id for the page
514
+	 * @param  string $new_title What the title is
515
+	 * @param  string $new_slug  what the slug is
516
+	 * @return string            The new html string for the permalink area
517
+	 */
518
+	public function preview_button_html($return, $id, $new_title, $new_slug)
519
+	{
520
+		$post = get_post($id);
521
+		if ('publish' !== get_post_status($post)) {
522
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
523
+					   . get_preview_post_link($id)
524
+					   . '" class="button button-small">'
525
+					   . __('Preview', 'event_espresso')
526
+					   . '</a></span>'
527
+					   . "\n";
528
+		}
529
+		return $return;
530
+	}
531
+
532
+
533
+	/**
534
+	 * add our custom post stati dropdown on the wp post page for this cpt
535
+	 *
536
+	 * @return void
537
+	 */
538
+	public function custom_post_stati_dropdown()
539
+	{
540
+
541
+		$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
542
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
543
+			? $statuses[ $this->_cpt_model_obj->status() ]
544
+			: '';
545
+		$template_args = array(
546
+			'cur_status'            => $this->_cpt_model_obj->status(),
547
+			'statuses'              => $statuses,
548
+			'cur_status_label'      => $cur_status_label,
549
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
550
+		);
551
+		// we'll add a trash post status (WP doesn't add one for some reason)
552
+		if ($this->_cpt_model_obj->status() === 'trash') {
553
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
554
+			$statuses['trash'] = __('Trashed', 'event_espresso');
555
+			$template_args['statuses'] = $statuses;
556
+		}
557
+
558
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
559
+		EEH_Template::display_template($template, $template_args);
560
+	}
561
+
562
+
563
+	public function setup_autosave_hooks()
564
+	{
565
+		$this->_set_autosave_containers();
566
+		$this->_load_autosave_scripts_styles();
567
+	}
568
+
569
+
570
+	/**
571
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
572
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
573
+	 * for the nonce in here, but then this method looks for two things:
574
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
575
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
576
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
577
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
578
+	 * template args.
579
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
580
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
581
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
582
+	 *    $this->_template_args['data']['items'] = array(
583
+	 *        'event-datetime-ids' => '1,2,3';
584
+	 *    );
585
+	 *    Keep in mind the following things:
586
+	 *    - "where" index is for the input with the id as that string.
587
+	 *    - "what" index is what will be used for the value of that input.
588
+	 *
589
+	 * @return void
590
+	 */
591
+	public function do_extra_autosave_stuff()
592
+	{
593
+		// next let's check for the autosave nonce (we'll use _verify_nonce )
594
+		$nonce = isset($this->_req_data['autosavenonce'])
595
+			? $this->_req_data['autosavenonce']
596
+			: null;
597
+		$this->_verify_nonce($nonce, 'autosave');
598
+		// make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
599
+		if (! defined('DOING_AUTOSAVE')) {
600
+			define('DOING_AUTOSAVE', true);
601
+		}
602
+		// if we made it here then the nonce checked out.  Let's run our methods and actions
603
+		$autosave = "_ee_autosave_{$this->_current_view}";
604
+		if (method_exists($this, $autosave)) {
605
+			$this->$autosave();
606
+		} else {
607
+			$this->_template_args['success'] = true;
608
+		}
609
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
610
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
611
+		// now let's return json
612
+		$this->_return_json();
613
+	}
614
+
615
+
616
+	/**
617
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
618
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
619
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
620
+	 *
621
+	 * @access protected
622
+	 * @throws EE_Error
623
+	 * @return void
624
+	 */
625
+	protected function _extend_page_config_for_cpt()
626
+	{
627
+		// before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
628
+		if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
629
+			return;
630
+		}
631
+		// set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
632
+		if (! empty($this->_cpt_object)) {
633
+			$this->_page_routes = array_merge(
634
+				array(
635
+					'create_new' => '_create_new_cpt_item',
636
+					'edit'       => '_edit_cpt_item',
637
+				),
638
+				$this->_page_routes
639
+			);
640
+			$this->_page_config = array_merge(
641
+				array(
642
+					'create_new' => array(
643
+						'nav'           => array(
644
+							'label' => $this->_cpt_object->labels->add_new_item,
645
+							'order' => 5,
646
+						),
647
+						'require_nonce' => false,
648
+					),
649
+					'edit'       => array(
650
+						'nav'           => array(
651
+							'label'      => $this->_cpt_object->labels->edit_item,
652
+							'order'      => 5,
653
+							'persistent' => false,
654
+							'url'        => '',
655
+						),
656
+						'require_nonce' => false,
657
+					),
658
+				),
659
+				$this->_page_config
660
+			);
661
+		}
662
+		// load the next section only if this is a matching cpt route as set in the cpt routes array.
663
+		if (! isset($this->_cpt_routes[ $this->_req_action ])) {
664
+			return;
665
+		}
666
+		$this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false;
667
+		// add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
668
+		if (empty($this->_cpt_object)) {
669
+			$msg = sprintf(
670
+				__(
671
+					'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).',
672
+					'event_espresso'
673
+				),
674
+				$this->page_slug,
675
+				$this->_req_action,
676
+				get_class($this)
677
+			);
678
+			throw new EE_Error($msg);
679
+		}
680
+		if ($this->_cpt_route) {
681
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
682
+			$this->_set_model_object($id);
683
+		}
684
+	}
685
+
686
+
687
+	/**
688
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
689
+	 *
690
+	 * @access protected
691
+	 * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
692
+	 * @param bool   $ignore_route_check
693
+	 * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
694
+	 * @throws EE_Error
695
+	 * @throws InvalidArgumentException
696
+	 * @throws InvalidDataTypeException
697
+	 * @throws InvalidInterfaceException
698
+	 * @throws ReflectionException
699
+	 */
700
+	protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
701
+	{
702
+		$model = null;
703
+		if (empty($this->_cpt_model_names)
704
+			|| (
705
+				! $ignore_route_check
706
+				&& ! isset($this->_cpt_routes[ $this->_req_action ])
707
+			) || (
708
+				$this->_cpt_model_obj instanceof EE_CPT_Base
709
+				&& $this->_cpt_model_obj->ID() === $id
710
+			)
711
+		) {
712
+			// get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
713
+			return;
714
+		}
715
+		// if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
716
+		if ($ignore_route_check) {
717
+			$post_type = get_post_type($id);
718
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
719
+			$custom_post_types = $this->loader->getShared(
720
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
721
+			);
722
+			$model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
723
+			if (isset($model_names[ $post_type ])) {
724
+				$model = EE_Registry::instance()->load_model($model_names[ $post_type ]);
725
+			}
726
+		} else {
727
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]);
728
+		}
729
+		if ($model instanceof EEM_Base) {
730
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
731
+		}
732
+		do_action(
733
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
734
+			$this->_cpt_model_obj,
735
+			$req_type
736
+		);
737
+	}
738
+
739
+
740
+	/**
741
+	 * admin_init_global
742
+	 * This runs all the code that we want executed within the WP admin_init hook.
743
+	 * This method executes for ALL EE Admin pages.
744
+	 *
745
+	 * @access public
746
+	 * @return void
747
+	 */
748
+	public function admin_init_global()
749
+	{
750
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
751
+		// its possible this is a new save so let's catch that instead
752
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
753
+		$post_type = $post ? $post->post_type : false;
754
+		$current_route = isset($this->_req_data['current_route'])
755
+			? $this->_req_data['current_route']
756
+			: 'shouldneverwork';
757
+		$route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ])
758
+			? $this->_cpt_routes[ $current_route ]
759
+			: '';
760
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
761
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
762
+		if ($post_type === $route_to_check) {
763
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
764
+		}
765
+		// now let's filter redirect if we're on a revision page and the revision is for an event CPT.
766
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
767
+		if (! empty($revision)) {
768
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
769
+			// doing a restore?
770
+			if (! empty($action) && $action === 'restore') {
771
+				// get post for revision
772
+				$rev_post = get_post($revision);
773
+				$rev_parent = get_post($rev_post->post_parent);
774
+				// only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
775
+				if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
776
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
777
+					// restores of revisions
778
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
779
+				}
780
+			}
781
+		}
782
+		// NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
783
+		if ($post_type && $post_type === $route_to_check) {
784
+			// $post_id, $post
785
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
786
+			// $post_id
787
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
788
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
789
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
790
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
791
+		}
792
+	}
793
+
794
+
795
+	/**
796
+	 * Callback for the WordPress trashed_post hook.
797
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
798
+	 *
799
+	 * @param int $post_id
800
+	 * @throws \EE_Error
801
+	 */
802
+	public function before_trash_cpt_item($post_id)
803
+	{
804
+		$this->_set_model_object($post_id, true, 'trash');
805
+		// if our cpt object isn't existent then get out immediately.
806
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
807
+			return;
808
+		}
809
+		$this->trash_cpt_item($post_id);
810
+	}
811
+
812
+
813
+	/**
814
+	 * Callback for the WordPress untrashed_post hook.
815
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
816
+	 *
817
+	 * @param $post_id
818
+	 * @throws \EE_Error
819
+	 */
820
+	public function before_restore_cpt_item($post_id)
821
+	{
822
+		$this->_set_model_object($post_id, true, 'restore');
823
+		// if our cpt object isn't existent then get out immediately.
824
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
825
+			return;
826
+		}
827
+		$this->restore_cpt_item($post_id);
828
+	}
829
+
830
+
831
+	/**
832
+	 * Callback for the WordPress after_delete_post hook.
833
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
834
+	 *
835
+	 * @param $post_id
836
+	 * @throws \EE_Error
837
+	 */
838
+	public function before_delete_cpt_item($post_id)
839
+	{
840
+		$this->_set_model_object($post_id, true, 'delete');
841
+		// if our cpt object isn't existent then get out immediately.
842
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
843
+			return;
844
+		}
845
+		$this->delete_cpt_item($post_id);
846
+	}
847
+
848
+
849
+	/**
850
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
851
+	 * accordingly.
852
+	 *
853
+	 * @return void
854
+	 * @throws EE_Error
855
+	 * @throws InvalidArgumentException
856
+	 * @throws InvalidDataTypeException
857
+	 * @throws InvalidInterfaceException
858
+	 * @throws ReflectionException
859
+	 */
860
+	public function verify_cpt_object()
861
+	{
862
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
863
+		// verify event object
864
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
865
+			throw new EE_Error(
866
+				sprintf(
867
+					__(
868
+						'Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
869
+						'event_espresso'
870
+					),
871
+					$label
872
+				)
873
+			);
874
+		}
875
+		// if auto-draft then throw an error
876
+		if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
877
+			EE_Error::overwrite_errors();
878
+			EE_Error::add_error(
879
+				sprintf(
880
+					__(
881
+						'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.',
882
+						'event_espresso'
883
+					),
884
+					$label
885
+				),
886
+				__FILE__,
887
+				__FUNCTION__,
888
+				__LINE__
889
+			);
890
+		}
891
+		$admin_config = $this->loader->getShared('EE_Admin_Config');
892
+		if ($admin_config->useAdvancedEditor()) {
893
+			$this->loadEspressoEditorAssetManager();
894
+		}
895
+	}
896
+
897
+
898
+	/**
899
+	 * admin_footer_scripts_global
900
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
901
+	 * will apply on ALL EE_Admin pages.
902
+	 *
903
+	 * @access public
904
+	 * @return void
905
+	 */
906
+	public function admin_footer_scripts_global()
907
+	{
908
+		$this->_add_admin_page_ajax_loading_img();
909
+		$this->_add_admin_page_overlay();
910
+	}
911
+
912
+
913
+	/**
914
+	 * add in any global scripts for cpt routes
915
+	 *
916
+	 * @return void
917
+	 */
918
+	public function load_global_scripts_styles()
919
+	{
920
+		parent::load_global_scripts_styles();
921
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
922
+			// setup custom post status object for localize script but only if we've got a cpt object
923
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
924
+			if (! empty($statuses)) {
925
+				// get ALL statuses!
926
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
927
+				// setup object
928
+				$ee_cpt_statuses = array();
929
+				foreach ($statuses as $status => $label) {
930
+					$ee_cpt_statuses[ $status ] = array(
931
+						'label'      => $label,
932
+						'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
933
+					);
934
+				}
935
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
936
+			}
937
+		}
938
+	}
939
+
940
+
941
+	/**
942
+	 * @throws InvalidArgumentException
943
+	 * @throws InvalidDataTypeException
944
+	 * @throws InvalidInterfaceException
945
+	 */
946
+	private function loadEspressoEditorAssetManager()
947
+	{
948
+		EE_Dependency_Map::register_dependencies(
949
+			'EventEspresso\core\domain\services\assets\EspressoEditorAssetManager',
950
+			array(
951
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
952
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
953
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
954
+			)
955
+		);
956
+		$this->loader->getShared(
957
+			'EventEspresso\core\domain\services\assets\EspressoEditorAssetManager'
958
+		);
959
+		add_action('admin_enqueue_scripts', array($this, 'enqueueEspressoEditorAssets'), 100);
960
+	}
961
+
962
+
963
+	/**
964
+	 * enqueue_scripts - Load the scripts and css
965
+	 *
966
+	 * @return void
967
+	 * @throws DomainException
968
+	 */
969
+	public function enqueueEspressoEditorAssets()
970
+	{
971
+		wp_enqueue_style(EspressoEditorAssetManager::CSS_HANDLE_EDITOR);
972
+		// wp_enqueue_style(EspressoEditorAssetManager::CSS_HANDLE_EDITOR_PROTOTYPE);
973
+		wp_enqueue_script(EspressoEditorAssetManager::JS_HANDLE_EDITOR);
974
+		// wp_enqueue_script(EspressoEditorAssetManager::JS_HANDLE_EDITOR_PROTOTYPE);
975
+	}
976
+
977
+	/**
978
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
979
+	 * insert/updates
980
+	 *
981
+	 * @param  int     $post_id ID of post being updated
982
+	 * @param  WP_Post $post    Post object from WP
983
+	 * @param  bool    $update  Whether this is an update or a new save.
984
+	 * @return void
985
+	 * @throws \EE_Error
986
+	 */
987
+	public function insert_update($post_id, $post, $update)
988
+	{
989
+		// make sure that if this is a revision OR trash action that we don't do any updates!
990
+		if (isset($this->_req_data['action'])
991
+			&& (
992
+				$this->_req_data['action'] === 'restore'
993
+				|| $this->_req_data['action'] === 'trash'
994
+			)
995
+		) {
996
+			return;
997
+		}
998
+		$this->_set_model_object($post_id, true, 'insert_update');
999
+		// if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
1000
+		if ($update
1001
+			&& (
1002
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
1003
+				|| $this->_cpt_model_obj->ID() !== $post_id
1004
+			)
1005
+		) {
1006
+			return;
1007
+		}
1008
+		// check for autosave and update our req_data property accordingly.
1009
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
1010 1010
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
1011 1011
 
1012 1012
                 foreach ( (array) $values as $key => $value ) {
@@ -1016,532 +1016,532 @@  discard block
 block discarded – undo
1016 1016
 
1017 1017
         }/**/ // TODO reactivate after autosave is implemented in 4.2
1018 1018
 
1019
-        // take care of updating any selected page_template IF this cpt supports it.
1020
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
1021
-            // wp version aware.
1022
-            if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
1023
-                $page_templates = wp_get_theme()->get_page_templates();
1024
-            } else {
1025
-                $post->page_template = $this->_req_data['page_template'];
1026
-                $page_templates = wp_get_theme()->get_page_templates($post);
1027
-            }
1028
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
1029
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1030
-            } else {
1031
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
1032
-            }
1033
-        }
1034
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
1035
-            return;
1036
-        } //TODO we'll remove this after reimplementing autosave in 4.2
1037
-        $this->_insert_update_cpt_item($post_id, $post);
1038
-    }
1039
-
1040
-
1041
-    /**
1042
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1043
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1044
-     * so we don't have to check for our CPT.
1045
-     *
1046
-     * @param  int $post_id ID of the post
1047
-     * @return void
1048
-     */
1049
-    public function dont_permanently_delete_ee_cpts($post_id)
1050
-    {
1051
-        // only do this if we're actually processing one of our CPTs
1052
-        // if our cpt object isn't existent then get out immediately.
1053
-        if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1054
-            return;
1055
-        }
1056
-        delete_post_meta($post_id, '_wp_trash_meta_status');
1057
-        delete_post_meta($post_id, '_wp_trash_meta_time');
1058
-        // our cpts may have comments so let's take care of that too
1059
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1060
-    }
1061
-
1062
-
1063
-    /**
1064
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1065
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1066
-     * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1067
-     *
1068
-     * @param  int $post_id     ID of cpt item
1069
-     * @param  int $revision_id ID of revision being restored
1070
-     * @return void
1071
-     */
1072
-    public function restore_revision($post_id, $revision_id)
1073
-    {
1074
-        $this->_restore_cpt_item($post_id, $revision_id);
1075
-        // global action
1076
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1077
-        // class specific action so you can limit hooking into a specific page.
1078
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1079
-    }
1080
-
1081
-
1082
-    /**
1083
-     * @see restore_revision() for details
1084
-     * @param  int $post_id     ID of cpt item
1085
-     * @param  int $revision_id ID of revision for item
1086
-     * @return void
1087
-     */
1088
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
1089
-
1090
-
1091
-    /**
1092
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
1093
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1094
-     * To fix we have to reset the current_screen using the page_slug
1095
-     * (which is identical - or should be - to our registered_post_type id.)
1096
-     * Also, since the core WP file loads the admin_header.php for WP
1097
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1098
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1099
-     *
1100
-     * @return void
1101
-     */
1102
-    public function modify_current_screen()
1103
-    {
1104
-        // ONLY do this if the current page_route IS a cpt route
1105
-        if (! $this->_cpt_route) {
1106
-            return;
1107
-        }
1108
-        // routing things REALLY early b/c this is a cpt admin page
1109
-        set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1110
-        $this->_current_screen = get_current_screen();
1111
-        $this->_current_screen->base = 'event-espresso';
1112
-        $this->_add_help_tabs(); // we make sure we add any help tabs back in!
1113
-        /*try {
1019
+		// take care of updating any selected page_template IF this cpt supports it.
1020
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
1021
+			// wp version aware.
1022
+			if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
1023
+				$page_templates = wp_get_theme()->get_page_templates();
1024
+			} else {
1025
+				$post->page_template = $this->_req_data['page_template'];
1026
+				$page_templates = wp_get_theme()->get_page_templates($post);
1027
+			}
1028
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) {
1029
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1030
+			} else {
1031
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
1032
+			}
1033
+		}
1034
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
1035
+			return;
1036
+		} //TODO we'll remove this after reimplementing autosave in 4.2
1037
+		$this->_insert_update_cpt_item($post_id, $post);
1038
+	}
1039
+
1040
+
1041
+	/**
1042
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
1043
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
1044
+	 * so we don't have to check for our CPT.
1045
+	 *
1046
+	 * @param  int $post_id ID of the post
1047
+	 * @return void
1048
+	 */
1049
+	public function dont_permanently_delete_ee_cpts($post_id)
1050
+	{
1051
+		// only do this if we're actually processing one of our CPTs
1052
+		// if our cpt object isn't existent then get out immediately.
1053
+		if (! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1054
+			return;
1055
+		}
1056
+		delete_post_meta($post_id, '_wp_trash_meta_status');
1057
+		delete_post_meta($post_id, '_wp_trash_meta_time');
1058
+		// our cpts may have comments so let's take care of that too
1059
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1060
+	}
1061
+
1062
+
1063
+	/**
1064
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1065
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1066
+	 * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1067
+	 *
1068
+	 * @param  int $post_id     ID of cpt item
1069
+	 * @param  int $revision_id ID of revision being restored
1070
+	 * @return void
1071
+	 */
1072
+	public function restore_revision($post_id, $revision_id)
1073
+	{
1074
+		$this->_restore_cpt_item($post_id, $revision_id);
1075
+		// global action
1076
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1077
+		// class specific action so you can limit hooking into a specific page.
1078
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1079
+	}
1080
+
1081
+
1082
+	/**
1083
+	 * @see restore_revision() for details
1084
+	 * @param  int $post_id     ID of cpt item
1085
+	 * @param  int $revision_id ID of revision for item
1086
+	 * @return void
1087
+	 */
1088
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
1089
+
1090
+
1091
+	/**
1092
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
1093
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1094
+	 * To fix we have to reset the current_screen using the page_slug
1095
+	 * (which is identical - or should be - to our registered_post_type id.)
1096
+	 * Also, since the core WP file loads the admin_header.php for WP
1097
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1098
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1099
+	 *
1100
+	 * @return void
1101
+	 */
1102
+	public function modify_current_screen()
1103
+	{
1104
+		// ONLY do this if the current page_route IS a cpt route
1105
+		if (! $this->_cpt_route) {
1106
+			return;
1107
+		}
1108
+		// routing things REALLY early b/c this is a cpt admin page
1109
+		set_current_screen($this->_cpt_routes[ $this->_req_action ]);
1110
+		$this->_current_screen = get_current_screen();
1111
+		$this->_current_screen->base = 'event-espresso';
1112
+		$this->_add_help_tabs(); // we make sure we add any help tabs back in!
1113
+		/*try {
1114 1114
             $this->_route_admin_request();
1115 1115
         } catch ( EE_Error $e ) {
1116 1116
             $e->get_error();
1117 1117
         }/**/
1118
-    }
1119
-
1120
-
1121
-    /**
1122
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1123
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1124
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1125
-     * default to be.
1126
-     *
1127
-     * @param string $title The new title (or existing if there is no editor_title defined)
1128
-     * @return string
1129
-     */
1130
-    public function add_custom_editor_default_title($title)
1131
-    {
1132
-        return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1133
-            ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1134
-            : $title;
1135
-    }
1136
-
1137
-
1138
-    /**
1139
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1140
-     *
1141
-     * @param string $shortlink   The already generated shortlink
1142
-     * @param int    $id          Post ID for this item
1143
-     * @param string $context     The context for the link
1144
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1145
-     * @return string
1146
-     */
1147
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1148
-    {
1149
-        if (! empty($id) && get_option('permalink_structure') !== '') {
1150
-            $post = get_post($id);
1151
-            if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1152
-                $shortlink = home_url('?p=' . $post->ID);
1153
-            }
1154
-        }
1155
-        return $shortlink;
1156
-    }
1157
-
1158
-
1159
-    /**
1160
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1161
-     * already run in modify_current_screen())
1162
-     *
1163
-     * @return void
1164
-     */
1165
-    public function route_admin_request()
1166
-    {
1167
-        if ($this->_cpt_route) {
1168
-            return;
1169
-        }
1170
-        try {
1171
-            $this->_route_admin_request();
1172
-        } catch (EE_Error $e) {
1173
-            $e->get_error();
1174
-        }
1175
-    }
1176
-
1177
-
1178
-    /**
1179
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1180
-     *
1181
-     * @return void
1182
-     */
1183
-    public function cpt_post_form_hidden_input()
1184
-    {
1185
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1186
-        // we're also going to add the route value and the current page so we can direct autosave parsing correctly
1187
-        echo '<div id="ee-cpt-hidden-inputs">';
1188
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1189
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1190
-        echo '</div>';
1191
-    }
1192
-
1193
-
1194
-    /**
1195
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1196
-     *
1197
-     * @param  string $location Original location url
1198
-     * @param  int    $status   Status for http header
1199
-     * @return string           new (or original) url to redirect to.
1200
-     */
1201
-    public function revision_redirect($location, $status)
1202
-    {
1203
-        // get revision
1204
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1205
-        // can't do anything without revision so let's get out if not present
1206
-        if (empty($rev_id)) {
1207
-            return $location;
1208
-        }
1209
-        // get rev_post_data
1210
-        $rev = get_post($rev_id);
1211
-        $admin_url = $this->_admin_base_url;
1212
-        $query_args = array(
1213
-            'action'   => 'edit',
1214
-            'post'     => $rev->post_parent,
1215
-            'revision' => $rev_id,
1216
-            'message'  => 5,
1217
-        );
1218
-        $this->_process_notices($query_args, true);
1219
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1220
-    }
1221
-
1222
-
1223
-    /**
1224
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1225
-     *
1226
-     * @param  string $link    the original generated link
1227
-     * @param  int    $id      post id
1228
-     * @param  string $context optional, defaults to display.  How to write the '&'
1229
-     * @return string          the link
1230
-     */
1231
-    public function modify_edit_post_link($link, $id, $context)
1232
-    {
1233
-        $post = get_post($id);
1234
-        if (! isset($this->_req_data['action'])
1235
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1236
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1237
-        ) {
1238
-            return $link;
1239
-        }
1240
-        $query_args = array(
1241
-            'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1242
-                ? $this->_cpt_edit_routes[ $post->post_type ]
1243
-                : 'edit',
1244
-            'post'   => $id,
1245
-        );
1246
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1247
-    }
1248
-
1249
-
1250
-    /**
1251
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1252
-     * our routes.
1253
-     *
1254
-     * @param  string $delete_link  original delete link
1255
-     * @param  int    $post_id      id of cpt object
1256
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1257
-     * @return string new delete link
1258
-     * @throws EE_Error
1259
-     */
1260
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1261
-    {
1262
-        $post = get_post($post_id);
1263
-
1264
-        if (empty($this->_req_data['action'])
1265
-            || ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1266
-            || ! $post instanceof WP_Post
1267
-            || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1268
-        ) {
1269
-            return $delete_link;
1270
-        }
1271
-        $this->_set_model_object($post->ID, true);
1272
-
1273
-        // returns something like `trash_event` or `trash_attendee` or `trash_venue`
1274
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1275
-
1276
-        return EE_Admin_Page::add_query_args_and_nonce(
1277
-            array(
1278
-                'page'   => $this->_req_data['page'],
1279
-                'action' => $action,
1280
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1281
-                         => $post->ID,
1282
-            ),
1283
-            admin_url()
1284
-        );
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1290
-     * so that we can hijack the default redirect locations for wp custom post types
1291
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1292
-     *
1293
-     * @param  string $location This is the incoming currently set redirect location
1294
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1295
-     * @return string           the new location to redirect to
1296
-     */
1297
-    public function cpt_post_location_redirect($location, $post_id)
1298
-    {
1299
-        // we DO have a match so let's setup the url
1300
-        // we have to get the post to determine our route
1301
-        $post = get_post($post_id);
1302
-        $edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1303
-        // shared query_args
1304
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1305
-        $admin_url = $this->_admin_base_url;
1306
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1307
-            $status = get_post_status($post_id);
1308
-            if (isset($this->_req_data['publish'])) {
1309
-                switch ($status) {
1310
-                    case 'pending':
1311
-                        $message = 8;
1312
-                        break;
1313
-                    case 'future':
1314
-                        $message = 9;
1315
-                        break;
1316
-                    default:
1317
-                        $message = 6;
1318
-                }
1319
-            } else {
1320
-                $message = 'draft' === $status ? 10 : 1;
1321
-            }
1322
-        } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1323
-            $message = 2;
1324
-        } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1325
-            $message = 3;
1326
-        } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1327
-            $message = 7;
1328
-        } else {
1329
-            $message = 4;
1330
-        }
1331
-        // change the message if the post type is not viewable on the frontend
1332
-        $this->_cpt_object = get_post_type_object($post->post_type);
1333
-        $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1334
-        $query_args = array_merge(array('message' => $message), $query_args);
1335
-        $this->_process_notices($query_args, true);
1336
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1337
-    }
1338
-
1339
-
1340
-    /**
1341
-     * This method is called to inject nav tabs on core WP cpt pages
1342
-     *
1343
-     * @access public
1344
-     * @return void
1345
-     */
1346
-    public function inject_nav_tabs()
1347
-    {
1348
-        // can we hijack and insert the nav_tabs?
1349
-        $nav_tabs = $this->_get_main_nav_tabs();
1350
-        // first close off existing form tag
1351
-        $html = '>';
1352
-        $html .= $nav_tabs;
1353
-        // now let's handle the remaining tag ( missing ">" is CORRECT )
1354
-        $html .= '<span></span';
1355
-        echo $html;
1356
-    }
1357
-
1358
-
1359
-    /**
1360
-     * This just sets up the post update messages when an update form is loaded
1361
-     *
1362
-     * @access public
1363
-     * @param  array $messages the original messages array
1364
-     * @return array           the new messages array
1365
-     */
1366
-    public function post_update_messages($messages)
1367
-    {
1368
-        global $post;
1369
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1370
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1371
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1118
+	}
1119
+
1120
+
1121
+	/**
1122
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1123
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1124
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1125
+	 * default to be.
1126
+	 *
1127
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1128
+	 * @return string
1129
+	 */
1130
+	public function add_custom_editor_default_title($title)
1131
+	{
1132
+		return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ])
1133
+			? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]
1134
+			: $title;
1135
+	}
1136
+
1137
+
1138
+	/**
1139
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1140
+	 *
1141
+	 * @param string $shortlink   The already generated shortlink
1142
+	 * @param int    $id          Post ID for this item
1143
+	 * @param string $context     The context for the link
1144
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1145
+	 * @return string
1146
+	 */
1147
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1148
+	{
1149
+		if (! empty($id) && get_option('permalink_structure') !== '') {
1150
+			$post = get_post($id);
1151
+			if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1152
+				$shortlink = home_url('?p=' . $post->ID);
1153
+			}
1154
+		}
1155
+		return $shortlink;
1156
+	}
1157
+
1158
+
1159
+	/**
1160
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1161
+	 * already run in modify_current_screen())
1162
+	 *
1163
+	 * @return void
1164
+	 */
1165
+	public function route_admin_request()
1166
+	{
1167
+		if ($this->_cpt_route) {
1168
+			return;
1169
+		}
1170
+		try {
1171
+			$this->_route_admin_request();
1172
+		} catch (EE_Error $e) {
1173
+			$e->get_error();
1174
+		}
1175
+	}
1176
+
1177
+
1178
+	/**
1179
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1180
+	 *
1181
+	 * @return void
1182
+	 */
1183
+	public function cpt_post_form_hidden_input()
1184
+	{
1185
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1186
+		// we're also going to add the route value and the current page so we can direct autosave parsing correctly
1187
+		echo '<div id="ee-cpt-hidden-inputs">';
1188
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1189
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1190
+		echo '</div>';
1191
+	}
1192
+
1193
+
1194
+	/**
1195
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1196
+	 *
1197
+	 * @param  string $location Original location url
1198
+	 * @param  int    $status   Status for http header
1199
+	 * @return string           new (or original) url to redirect to.
1200
+	 */
1201
+	public function revision_redirect($location, $status)
1202
+	{
1203
+		// get revision
1204
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1205
+		// can't do anything without revision so let's get out if not present
1206
+		if (empty($rev_id)) {
1207
+			return $location;
1208
+		}
1209
+		// get rev_post_data
1210
+		$rev = get_post($rev_id);
1211
+		$admin_url = $this->_admin_base_url;
1212
+		$query_args = array(
1213
+			'action'   => 'edit',
1214
+			'post'     => $rev->post_parent,
1215
+			'revision' => $rev_id,
1216
+			'message'  => 5,
1217
+		);
1218
+		$this->_process_notices($query_args, true);
1219
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1220
+	}
1221
+
1222
+
1223
+	/**
1224
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1225
+	 *
1226
+	 * @param  string $link    the original generated link
1227
+	 * @param  int    $id      post id
1228
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1229
+	 * @return string          the link
1230
+	 */
1231
+	public function modify_edit_post_link($link, $id, $context)
1232
+	{
1233
+		$post = get_post($id);
1234
+		if (! isset($this->_req_data['action'])
1235
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1236
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1237
+		) {
1238
+			return $link;
1239
+		}
1240
+		$query_args = array(
1241
+			'action' => isset($this->_cpt_edit_routes[ $post->post_type ])
1242
+				? $this->_cpt_edit_routes[ $post->post_type ]
1243
+				: 'edit',
1244
+			'post'   => $id,
1245
+		);
1246
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1247
+	}
1248
+
1249
+
1250
+	/**
1251
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1252
+	 * our routes.
1253
+	 *
1254
+	 * @param  string $delete_link  original delete link
1255
+	 * @param  int    $post_id      id of cpt object
1256
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1257
+	 * @return string new delete link
1258
+	 * @throws EE_Error
1259
+	 */
1260
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1261
+	{
1262
+		$post = get_post($post_id);
1263
+
1264
+		if (empty($this->_req_data['action'])
1265
+			|| ! isset($this->_cpt_routes[ $this->_req_data['action'] ])
1266
+			|| ! $post instanceof WP_Post
1267
+			|| $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ]
1268
+		) {
1269
+			return $delete_link;
1270
+		}
1271
+		$this->_set_model_object($post->ID, true);
1272
+
1273
+		// returns something like `trash_event` or `trash_attendee` or `trash_venue`
1274
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1275
+
1276
+		return EE_Admin_Page::add_query_args_and_nonce(
1277
+			array(
1278
+				'page'   => $this->_req_data['page'],
1279
+				'action' => $action,
1280
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1281
+						 => $post->ID,
1282
+			),
1283
+			admin_url()
1284
+		);
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1290
+	 * so that we can hijack the default redirect locations for wp custom post types
1291
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1292
+	 *
1293
+	 * @param  string $location This is the incoming currently set redirect location
1294
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1295
+	 * @return string           the new location to redirect to
1296
+	 */
1297
+	public function cpt_post_location_redirect($location, $post_id)
1298
+	{
1299
+		// we DO have a match so let's setup the url
1300
+		// we have to get the post to determine our route
1301
+		$post = get_post($post_id);
1302
+		$edit_route = $this->_cpt_edit_routes[ $post->post_type ];
1303
+		// shared query_args
1304
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1305
+		$admin_url = $this->_admin_base_url;
1306
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1307
+			$status = get_post_status($post_id);
1308
+			if (isset($this->_req_data['publish'])) {
1309
+				switch ($status) {
1310
+					case 'pending':
1311
+						$message = 8;
1312
+						break;
1313
+					case 'future':
1314
+						$message = 9;
1315
+						break;
1316
+					default:
1317
+						$message = 6;
1318
+				}
1319
+			} else {
1320
+				$message = 'draft' === $status ? 10 : 1;
1321
+			}
1322
+		} elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1323
+			$message = 2;
1324
+		} elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1325
+			$message = 3;
1326
+		} elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1327
+			$message = 7;
1328
+		} else {
1329
+			$message = 4;
1330
+		}
1331
+		// change the message if the post type is not viewable on the frontend
1332
+		$this->_cpt_object = get_post_type_object($post->post_type);
1333
+		$message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1334
+		$query_args = array_merge(array('message' => $message), $query_args);
1335
+		$this->_process_notices($query_args, true);
1336
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1337
+	}
1338
+
1339
+
1340
+	/**
1341
+	 * This method is called to inject nav tabs on core WP cpt pages
1342
+	 *
1343
+	 * @access public
1344
+	 * @return void
1345
+	 */
1346
+	public function inject_nav_tabs()
1347
+	{
1348
+		// can we hijack and insert the nav_tabs?
1349
+		$nav_tabs = $this->_get_main_nav_tabs();
1350
+		// first close off existing form tag
1351
+		$html = '>';
1352
+		$html .= $nav_tabs;
1353
+		// now let's handle the remaining tag ( missing ">" is CORRECT )
1354
+		$html .= '<span></span';
1355
+		echo $html;
1356
+	}
1357
+
1358
+
1359
+	/**
1360
+	 * This just sets up the post update messages when an update form is loaded
1361
+	 *
1362
+	 * @access public
1363
+	 * @param  array $messages the original messages array
1364
+	 * @return array           the new messages array
1365
+	 */
1366
+	public function post_update_messages($messages)
1367
+	{
1368
+		global $post;
1369
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1370
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1371
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1372 1372
 
1373 1373
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1374
-        $messages[ $post->post_type ] = array(
1375
-            0  => '', // Unused. Messages start at index 1.
1376
-            1  => sprintf(
1377
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1378
-                $this->_cpt_object->labels->singular_name,
1379
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1380
-                '</a>'
1381
-            ),
1382
-            2  => __('Custom field updated', 'event_espresso'),
1383
-            3  => __('Custom field deleted.', 'event_espresso'),
1384
-            4  => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1385
-            5  => isset($_GET['revision']) ? sprintf(
1386
-                __('%s restored to revision from %s', 'event_espresso'),
1387
-                $this->_cpt_object->labels->singular_name,
1388
-                wp_post_revision_title((int) $_GET['revision'], false)
1389
-            )
1390
-                : false,
1391
-            6  => sprintf(
1392
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1393
-                $this->_cpt_object->labels->singular_name,
1394
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1395
-                '</a>'
1396
-            ),
1397
-            7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1398
-            8  => sprintf(
1399
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1400
-                $this->_cpt_object->labels->singular_name,
1401
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1402
-                '</a>'
1403
-            ),
1404
-            9  => sprintf(
1405
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1406
-                $this->_cpt_object->labels->singular_name,
1407
-                '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1408
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1409
-                '</a>'
1410
-            ),
1411
-            10 => sprintf(
1412
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1413
-                $this->_cpt_object->labels->singular_name,
1414
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1415
-                '</a>'
1416
-            ),
1417
-        );
1418
-        return $messages;
1419
-    }
1420
-
1421
-
1422
-    /**
1423
-     * default method for the 'create_new' route for cpt admin pages.
1424
-     * For reference what to include in here, see wp-admin/post-new.php
1425
-     *
1426
-     * @access  protected
1427
-     * @return void
1428
-     */
1429
-    protected function _create_new_cpt_item()
1430
-    {
1431
-        // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1432
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1433
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1434
-        $post_type_object = $this->_cpt_object;
1435
-        $title = $post_type_object->labels->add_new_item;
1436
-        $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1437
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1438
-        // modify the default editor title field with default title.
1439
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1440
-        $this->loadEditorTemplate(true);
1441
-    }
1442
-
1443
-
1444
-    /**
1445
-     * Enqueues auto-save and loads the editor template
1446
-     *
1447
-     * @param bool $creating
1448
-     */
1449
-    private function loadEditorTemplate($creating = true)
1450
-    {
1451
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1452
-        // these vars are used by the template
1453
-        $editing = true;
1454
-        $post_ID = $post->ID;
1455
-        if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1456
-            // only enqueue autosave when creating event (necessary to get permalink/url generated)
1457
-            // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1458
-            if ($creating) {
1459
-                wp_enqueue_script('autosave');
1460
-            } else {
1461
-                if (isset($this->_cpt_routes[ $this->_req_data['action'] ])
1462
-                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1463
-                ) {
1464
-                    $create_new_action = apply_filters(
1465
-                        'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1466
-                        'create_new',
1467
-                        $this
1468
-                    );
1469
-                    $post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1470
-                        array(
1471
-                            'action' => $create_new_action,
1472
-                            'page'   => $this->page_slug,
1473
-                        ),
1474
-                        'admin.php'
1475
-                    );
1476
-                }
1477
-            }
1478
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1479
-        }
1480
-    }
1481
-
1482
-
1483
-    public function add_new_admin_page_global()
1484
-    {
1485
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1486
-        ?>
1374
+		$messages[ $post->post_type ] = array(
1375
+			0  => '', // Unused. Messages start at index 1.
1376
+			1  => sprintf(
1377
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1378
+				$this->_cpt_object->labels->singular_name,
1379
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1380
+				'</a>'
1381
+			),
1382
+			2  => __('Custom field updated', 'event_espresso'),
1383
+			3  => __('Custom field deleted.', 'event_espresso'),
1384
+			4  => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1385
+			5  => isset($_GET['revision']) ? sprintf(
1386
+				__('%s restored to revision from %s', 'event_espresso'),
1387
+				$this->_cpt_object->labels->singular_name,
1388
+				wp_post_revision_title((int) $_GET['revision'], false)
1389
+			)
1390
+				: false,
1391
+			6  => sprintf(
1392
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1393
+				$this->_cpt_object->labels->singular_name,
1394
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1395
+				'</a>'
1396
+			),
1397
+			7  => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1398
+			8  => sprintf(
1399
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1400
+				$this->_cpt_object->labels->singular_name,
1401
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1402
+				'</a>'
1403
+			),
1404
+			9  => sprintf(
1405
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1406
+				$this->_cpt_object->labels->singular_name,
1407
+				'<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>',
1408
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1409
+				'</a>'
1410
+			),
1411
+			10 => sprintf(
1412
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1413
+				$this->_cpt_object->labels->singular_name,
1414
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1415
+				'</a>'
1416
+			),
1417
+		);
1418
+		return $messages;
1419
+	}
1420
+
1421
+
1422
+	/**
1423
+	 * default method for the 'create_new' route for cpt admin pages.
1424
+	 * For reference what to include in here, see wp-admin/post-new.php
1425
+	 *
1426
+	 * @access  protected
1427
+	 * @return void
1428
+	 */
1429
+	protected function _create_new_cpt_item()
1430
+	{
1431
+		// gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1432
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1433
+		$post_type = $this->_cpt_routes[ $this->_req_action ];
1434
+		$post_type_object = $this->_cpt_object;
1435
+		$title = $post_type_object->labels->add_new_item;
1436
+		$post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true);
1437
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1438
+		// modify the default editor title field with default title.
1439
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1440
+		$this->loadEditorTemplate(true);
1441
+	}
1442
+
1443
+
1444
+	/**
1445
+	 * Enqueues auto-save and loads the editor template
1446
+	 *
1447
+	 * @param bool $creating
1448
+	 */
1449
+	private function loadEditorTemplate($creating = true)
1450
+	{
1451
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1452
+		// these vars are used by the template
1453
+		$editing = true;
1454
+		$post_ID = $post->ID;
1455
+		if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1456
+			// only enqueue autosave when creating event (necessary to get permalink/url generated)
1457
+			// otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1458
+			if ($creating) {
1459
+				wp_enqueue_script('autosave');
1460
+			} else {
1461
+				if (isset($this->_cpt_routes[ $this->_req_data['action'] ])
1462
+					&& ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ])
1463
+				) {
1464
+					$create_new_action = apply_filters(
1465
+						'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1466
+						'create_new',
1467
+						$this
1468
+					);
1469
+					$post_new_file = EE_Admin_Page::add_query_args_and_nonce(
1470
+						array(
1471
+							'action' => $create_new_action,
1472
+							'page'   => $this->page_slug,
1473
+						),
1474
+						'admin.php'
1475
+					);
1476
+				}
1477
+			}
1478
+			include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1479
+		}
1480
+	}
1481
+
1482
+
1483
+	public function add_new_admin_page_global()
1484
+	{
1485
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1486
+		?>
1487 1487
         <script type="text/javascript">
1488 1488
             adminpage = '<?php echo $admin_page; ?>';
1489 1489
         </script>
1490 1490
         <?php
1491
-    }
1492
-
1493
-
1494
-    /**
1495
-     * default method for the 'edit' route for cpt admin pages
1496
-     * For reference on what to put in here, refer to wp-admin/post.php
1497
-     *
1498
-     * @access protected
1499
-     * @return string   template for edit cpt form
1500
-     */
1501
-    protected function _edit_cpt_item()
1502
-    {
1503
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1504
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1505
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1506
-        if (empty($post)) {
1507
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1508
-        }
1509
-        if (! empty($_GET['get-post-lock'])) {
1510
-            wp_set_post_lock($post_id);
1511
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1512
-            exit();
1513
-        }
1514
-
1515
-        // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1516
-        $post_type = $this->_cpt_routes[ $this->_req_action ];
1517
-        $post_type_object = $this->_cpt_object;
1518
-
1519
-        if (! wp_check_post_lock($post->ID)) {
1520
-            wp_set_post_lock($post->ID);
1521
-        }
1522
-        add_action('admin_footer', '_admin_notice_post_locked');
1523
-        if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1524
-            wp_enqueue_script('admin-comments');
1525
-            enqueue_comment_hotkeys_js();
1526
-        }
1527
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1528
-        // modify the default editor title field with default title.
1529
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1530
-        $this->loadEditorTemplate(false);
1531
-    }
1532
-
1533
-
1534
-
1535
-    /**
1536
-     * some getters
1537
-     */
1538
-    /**
1539
-     * This returns the protected _cpt_model_obj property
1540
-     *
1541
-     * @return EE_CPT_Base
1542
-     */
1543
-    public function get_cpt_model_obj()
1544
-    {
1545
-        return $this->_cpt_model_obj;
1546
-    }
1491
+	}
1492
+
1493
+
1494
+	/**
1495
+	 * default method for the 'edit' route for cpt admin pages
1496
+	 * For reference on what to put in here, refer to wp-admin/post.php
1497
+	 *
1498
+	 * @access protected
1499
+	 * @return string   template for edit cpt form
1500
+	 */
1501
+	protected function _edit_cpt_item()
1502
+	{
1503
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1504
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1505
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1506
+		if (empty($post)) {
1507
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?', 'event_espresso'));
1508
+		}
1509
+		if (! empty($_GET['get-post-lock'])) {
1510
+			wp_set_post_lock($post_id);
1511
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1512
+			exit();
1513
+		}
1514
+
1515
+		// template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1516
+		$post_type = $this->_cpt_routes[ $this->_req_action ];
1517
+		$post_type_object = $this->_cpt_object;
1518
+
1519
+		if (! wp_check_post_lock($post->ID)) {
1520
+			wp_set_post_lock($post->ID);
1521
+		}
1522
+		add_action('admin_footer', '_admin_notice_post_locked');
1523
+		if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) {
1524
+			wp_enqueue_script('admin-comments');
1525
+			enqueue_comment_hotkeys_js();
1526
+		}
1527
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1528
+		// modify the default editor title field with default title.
1529
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1530
+		$this->loadEditorTemplate(false);
1531
+	}
1532
+
1533
+
1534
+
1535
+	/**
1536
+	 * some getters
1537
+	 */
1538
+	/**
1539
+	 * This returns the protected _cpt_model_obj property
1540
+	 *
1541
+	 * @return EE_CPT_Base
1542
+	 */
1543
+	public function get_cpt_model_obj()
1544
+	{
1545
+		return $this->_cpt_model_obj;
1546
+	}
1547 1547
 }
Please login to merge, or discard this patch.
core/domain/services/admin/events/editor/AdvancedEditorData.php 2 patches
Indentation   +478 added lines, -478 removed lines patch added patch discarded remove patch
@@ -35,96 +35,96 @@  discard block
 block discarded – undo
35 35
 class AdvancedEditorData
36 36
 {
37 37
 
38
-    /**
39
-     * @var string $namespace The graphql namespace/prefix.
40
-     */
41
-    protected $namespace = 'Espresso';
42
-
43
-    /**
44
-     * @var EE_Event
45
-     */
46
-    protected $event;
47
-
48
-    /**
49
-     * @var EE_Admin_Config
50
-     */
51
-    protected $admin_config;
52
-    /**
53
-     * @var EEM_Datetime $datetime_model
54
-     */
55
-    protected $datetime_model;
56
-    /**
57
-     * @var EEM_Price $price_model
58
-     */
59
-    protected $price_model;
60
-    /**
61
-     * @var EEM_Ticket $ticket_model
62
-     */
63
-    protected $ticket_model;
64
-
65
-
66
-    /**
67
-     * AdvancedEditorAdminForm constructor.
68
-     *
69
-     * @param EE_Event        $event
70
-     * @param EE_Admin_Config $admin_config
71
-     * @param EEM_Datetime    $datetime_model
72
-     * @param EEM_Price       $price_model
73
-     * @param EEM_Ticket      $ticket_model
74
-     */
75
-    public function __construct(
76
-        EE_Event $event,
77
-        EE_Admin_Config $admin_config,
78
-        EEM_Datetime $datetime_model,
79
-        EEM_Price $price_model,
80
-        EEM_Ticket $ticket_model
81
-    ) {
82
-        $this->event = $event;
83
-        $this->admin_config = $admin_config;
84
-        $this->datetime_model = $datetime_model;
85
-        $this->price_model = $price_model;
86
-        $this->ticket_model = $ticket_model;
87
-        add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']);
88
-    }
89
-
90
-
91
-    /**
92
-     * @throws EE_Error
93
-     * @throws InvalidArgumentException
94
-     * @throws InvalidDataTypeException
95
-     * @throws InvalidInterfaceException
96
-     * @throws ModelConfigurationException
97
-     * @throws ReflectionException
98
-     * @throws UnexpectedEntityException
99
-     * @throws DomainException
100
-     * @since $VID:$
101
-     */
102
-    public function loadScriptsStyles()
103
-    {
104
-        if ($this->admin_config->useAdvancedEditor()) {
105
-            $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0;
106
-            if (! $eventId) {
107
-                global $post;
108
-                $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
109
-                $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events'
110
-                    ? $post->ID
111
-                    : $eventId;
112
-            }
113
-            if ($eventId) {
114
-                $data = $this->getEditorData($eventId);
115
-                $data = wp_json_encode($data);
116
-                add_action(
117
-                    'admin_footer',
118
-                    static function () use ($data) {
119
-                        wp_add_inline_script(
120
-                            EspressoEditorAssetManager::JS_HANDLE_EDITOR,
121
-                            "
38
+	/**
39
+	 * @var string $namespace The graphql namespace/prefix.
40
+	 */
41
+	protected $namespace = 'Espresso';
42
+
43
+	/**
44
+	 * @var EE_Event
45
+	 */
46
+	protected $event;
47
+
48
+	/**
49
+	 * @var EE_Admin_Config
50
+	 */
51
+	protected $admin_config;
52
+	/**
53
+	 * @var EEM_Datetime $datetime_model
54
+	 */
55
+	protected $datetime_model;
56
+	/**
57
+	 * @var EEM_Price $price_model
58
+	 */
59
+	protected $price_model;
60
+	/**
61
+	 * @var EEM_Ticket $ticket_model
62
+	 */
63
+	protected $ticket_model;
64
+
65
+
66
+	/**
67
+	 * AdvancedEditorAdminForm constructor.
68
+	 *
69
+	 * @param EE_Event        $event
70
+	 * @param EE_Admin_Config $admin_config
71
+	 * @param EEM_Datetime    $datetime_model
72
+	 * @param EEM_Price       $price_model
73
+	 * @param EEM_Ticket      $ticket_model
74
+	 */
75
+	public function __construct(
76
+		EE_Event $event,
77
+		EE_Admin_Config $admin_config,
78
+		EEM_Datetime $datetime_model,
79
+		EEM_Price $price_model,
80
+		EEM_Ticket $ticket_model
81
+	) {
82
+		$this->event = $event;
83
+		$this->admin_config = $admin_config;
84
+		$this->datetime_model = $datetime_model;
85
+		$this->price_model = $price_model;
86
+		$this->ticket_model = $ticket_model;
87
+		add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']);
88
+	}
89
+
90
+
91
+	/**
92
+	 * @throws EE_Error
93
+	 * @throws InvalidArgumentException
94
+	 * @throws InvalidDataTypeException
95
+	 * @throws InvalidInterfaceException
96
+	 * @throws ModelConfigurationException
97
+	 * @throws ReflectionException
98
+	 * @throws UnexpectedEntityException
99
+	 * @throws DomainException
100
+	 * @since $VID:$
101
+	 */
102
+	public function loadScriptsStyles()
103
+	{
104
+		if ($this->admin_config->useAdvancedEditor()) {
105
+			$eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0;
106
+			if (! $eventId) {
107
+				global $post;
108
+				$eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
109
+				$eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events'
110
+					? $post->ID
111
+					: $eventId;
112
+			}
113
+			if ($eventId) {
114
+				$data = $this->getEditorData($eventId);
115
+				$data = wp_json_encode($data);
116
+				add_action(
117
+					'admin_footer',
118
+					static function () use ($data) {
119
+						wp_add_inline_script(
120
+							EspressoEditorAssetManager::JS_HANDLE_EDITOR,
121
+							"
122 122
 var eeEditorData={$data};
123 123
 ",
124
-                            'before'
125
-                        );
126
-                    }
127
-                );
124
+							'before'
125
+						);
126
+					}
127
+				);
128 128
 //                 add_action(
129 129
 //                     'admin_footer',
130 130
 //                     static function () use ($data) {
@@ -137,121 +137,121 @@  discard block
 block discarded – undo
137 137
 //                         );
138 138
 //                     }
139 139
 //                 );
140
-            }
141
-        }
142
-    }
143
-
144
-
145
-    /**
146
-     * @param int $eventId
147
-     * @return array
148
-     * @throws EE_Error
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidInterfaceException
151
-     * @throws ModelConfigurationException
152
-     * @throws UnexpectedEntityException
153
-     * @throws InvalidArgumentException
154
-     * @throws ReflectionException
155
-     * @throws DomainException
156
-     * @since $VID:$
157
-     */
158
-    protected function getEditorData($eventId)
159
-    {
160
-        $event = $this->getEventGraphQLData($eventId);
161
-        $event['dbId'] = $eventId;
162
-
163
-        $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : '';
164
-        $graphqlEndpoint = esc_url($graphqlEndpoint);
165
-
166
-        $currentUser = $this->getGraphQLCurrentUser();
167
-
168
-        $generalSettings = $this->getGraphQLGeneralSettings();
169
-
170
-        $i18n = self::getJedLocaleData('event_espresso');
171
-
172
-        return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n');
173
-    }
174
-
175
-
176
-    /**
177
-     * @param int $eventId
178
-     * @return array
179
-     * @since $VID:$
180
-     */
181
-    protected function getEventGraphQLData($eventId)
182
-    {
183
-        $datetimes = $this->getGraphQLDatetimes($eventId);
184
-
185
-        if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
186
-            $this->addDefaultEntities($eventId);
187
-            $datetimes = $this->getGraphQLDatetimes($eventId);
188
-        }
189
-
190
-        if (! empty($datetimes['nodes'])) {
191
-            $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
192
-
193
-            if (! empty($datetimeIn)) {
194
-                $tickets = $this->getGraphQLTickets($datetimeIn);
195
-            }
196
-        }
197
-
198
-        if (! empty($tickets['nodes'])) {
199
-            $ticketIn = wp_list_pluck($tickets['nodes'], 'id');
200
-
201
-            if (! empty($ticketIn)) {
202
-                $prices = $this->getGraphQLPrices($ticketIn);
203
-            }
204
-        }
205
-
206
-        $priceTypes = $this->getGraphQLPriceTypes();
207
-
208
-        $relations = $this->getRelationalData($eventId);
209
-
210
-        return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations');
211
-    }
212
-
213
-    /**
214
-     * @param int $eventId
215
-     * @throws DomainException
216
-     * @throws EE_Error
217
-     * @throws InvalidArgumentException
218
-     * @throws InvalidDataTypeException
219
-     * @throws InvalidInterfaceException
220
-     * @throws ModelConfigurationException
221
-     * @throws ReflectionException
222
-     * @throws UnexpectedEntityException
223
-     * @since $VID:$
224
-     */
225
-    protected function addDefaultEntities($eventId)
226
-    {
227
-        $default_dates = $this->datetime_model->create_new_blank_datetime();
228
-        if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) {
229
-            $default_date = $default_dates[0];
230
-            $default_date->save();
231
-            $default_date->_add_relation_to($eventId, 'Event');
232
-            $default_tickets = $this->ticket_model->get_all_default_tickets();
233
-            $default_prices = $this->price_model->get_all_default_prices();
234
-            foreach ($default_tickets as $default_ticket) {
235
-                $default_ticket->save();
236
-                $default_ticket->_add_relation_to($default_date, 'Datetime');
237
-                foreach ($default_prices as $default_price) {
238
-                    $default_price->save();
239
-                    $default_price->_add_relation_to($default_ticket, 'Ticket');
240
-                }
241
-            }
242
-        }
243
-    }
244
-
245
-
246
-    /**
247
-     * @param int $eventId
248
-     * @return array|null
249
-     * @since $VID:$
250
-     */
251
-    protected function getGraphQLDatetimes($eventId)
252
-    {
253
-        $field_key = lcfirst($this->namespace) . 'Datetimes';
254
-        $query = <<<QUERY
140
+			}
141
+		}
142
+	}
143
+
144
+
145
+	/**
146
+	 * @param int $eventId
147
+	 * @return array
148
+	 * @throws EE_Error
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidInterfaceException
151
+	 * @throws ModelConfigurationException
152
+	 * @throws UnexpectedEntityException
153
+	 * @throws InvalidArgumentException
154
+	 * @throws ReflectionException
155
+	 * @throws DomainException
156
+	 * @since $VID:$
157
+	 */
158
+	protected function getEditorData($eventId)
159
+	{
160
+		$event = $this->getEventGraphQLData($eventId);
161
+		$event['dbId'] = $eventId;
162
+
163
+		$graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : '';
164
+		$graphqlEndpoint = esc_url($graphqlEndpoint);
165
+
166
+		$currentUser = $this->getGraphQLCurrentUser();
167
+
168
+		$generalSettings = $this->getGraphQLGeneralSettings();
169
+
170
+		$i18n = self::getJedLocaleData('event_espresso');
171
+
172
+		return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n');
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param int $eventId
178
+	 * @return array
179
+	 * @since $VID:$
180
+	 */
181
+	protected function getEventGraphQLData($eventId)
182
+	{
183
+		$datetimes = $this->getGraphQLDatetimes($eventId);
184
+
185
+		if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
186
+			$this->addDefaultEntities($eventId);
187
+			$datetimes = $this->getGraphQLDatetimes($eventId);
188
+		}
189
+
190
+		if (! empty($datetimes['nodes'])) {
191
+			$datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
192
+
193
+			if (! empty($datetimeIn)) {
194
+				$tickets = $this->getGraphQLTickets($datetimeIn);
195
+			}
196
+		}
197
+
198
+		if (! empty($tickets['nodes'])) {
199
+			$ticketIn = wp_list_pluck($tickets['nodes'], 'id');
200
+
201
+			if (! empty($ticketIn)) {
202
+				$prices = $this->getGraphQLPrices($ticketIn);
203
+			}
204
+		}
205
+
206
+		$priceTypes = $this->getGraphQLPriceTypes();
207
+
208
+		$relations = $this->getRelationalData($eventId);
209
+
210
+		return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations');
211
+	}
212
+
213
+	/**
214
+	 * @param int $eventId
215
+	 * @throws DomainException
216
+	 * @throws EE_Error
217
+	 * @throws InvalidArgumentException
218
+	 * @throws InvalidDataTypeException
219
+	 * @throws InvalidInterfaceException
220
+	 * @throws ModelConfigurationException
221
+	 * @throws ReflectionException
222
+	 * @throws UnexpectedEntityException
223
+	 * @since $VID:$
224
+	 */
225
+	protected function addDefaultEntities($eventId)
226
+	{
227
+		$default_dates = $this->datetime_model->create_new_blank_datetime();
228
+		if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) {
229
+			$default_date = $default_dates[0];
230
+			$default_date->save();
231
+			$default_date->_add_relation_to($eventId, 'Event');
232
+			$default_tickets = $this->ticket_model->get_all_default_tickets();
233
+			$default_prices = $this->price_model->get_all_default_prices();
234
+			foreach ($default_tickets as $default_ticket) {
235
+				$default_ticket->save();
236
+				$default_ticket->_add_relation_to($default_date, 'Datetime');
237
+				foreach ($default_prices as $default_price) {
238
+					$default_price->save();
239
+					$default_price->_add_relation_to($default_ticket, 'Ticket');
240
+				}
241
+			}
242
+		}
243
+	}
244
+
245
+
246
+	/**
247
+	 * @param int $eventId
248
+	 * @return array|null
249
+	 * @since $VID:$
250
+	 */
251
+	protected function getGraphQLDatetimes($eventId)
252
+	{
253
+		$field_key = lcfirst($this->namespace) . 'Datetimes';
254
+		$query = <<<QUERY
255 255
         query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) {
256 256
             {$field_key}(where: \$where, first: \$first, last: \$last) {
257 257
                 nodes {
@@ -279,31 +279,31 @@  discard block
 block discarded – undo
279 279
             }
280 280
         }
281 281
 QUERY;
282
-        $data = [
283
-            'operation_name' => 'GET_DATETIMES',
284
-            'variables' => [
285
-                'first' => 100,
286
-                'where' => [
287
-                    'eventId' => $eventId,
288
-                ],
289
-            ],
290
-            'query' => $query,
291
-        ];
292
-
293
-        $responseData = $this->makeGraphQLRequest($data);
294
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
295
-    }
296
-
297
-
298
-    /**
299
-     * @param array $datetimeIn
300
-     * @return array|null
301
-     * @since $VID:$
302
-     */
303
-    protected function getGraphQLTickets(array $datetimeIn)
304
-    {
305
-        $field_key = lcfirst($this->namespace) . 'Tickets';
306
-        $query = <<<QUERY
282
+		$data = [
283
+			'operation_name' => 'GET_DATETIMES',
284
+			'variables' => [
285
+				'first' => 100,
286
+				'where' => [
287
+					'eventId' => $eventId,
288
+				],
289
+			],
290
+			'query' => $query,
291
+		];
292
+
293
+		$responseData = $this->makeGraphQLRequest($data);
294
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
295
+	}
296
+
297
+
298
+	/**
299
+	 * @param array $datetimeIn
300
+	 * @return array|null
301
+	 * @since $VID:$
302
+	 */
303
+	protected function getGraphQLTickets(array $datetimeIn)
304
+	{
305
+		$field_key = lcfirst($this->namespace) . 'Tickets';
306
+		$query = <<<QUERY
307 307
         query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) {
308 308
             {$field_key}(where: \$where, first: \$first, last: \$last) {
309 309
                 nodes {
@@ -337,31 +337,31 @@  discard block
 block discarded – undo
337 337
             }
338 338
         }
339 339
 QUERY;
340
-        $data = [
341
-            'operation_name' => 'GET_TICKETS',
342
-            'variables' => [
343
-                'first' => 100,
344
-                'where' => [
345
-                    'datetimeIn' => $datetimeIn,
346
-                ],
347
-            ],
348
-            'query' => $query,
349
-        ];
350
-
351
-        $responseData = $this->makeGraphQLRequest($data);
352
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
353
-    }
354
-
355
-
356
-    /**
357
-     * @param array $ticketIn
358
-     * @return array|null
359
-     * @since $VID:$
360
-     */
361
-    protected function getGraphQLPrices(array $ticketIn)
362
-    {
363
-        $field_key = lcfirst($this->namespace) . 'Prices';
364
-        $query = <<<QUERY
340
+		$data = [
341
+			'operation_name' => 'GET_TICKETS',
342
+			'variables' => [
343
+				'first' => 100,
344
+				'where' => [
345
+					'datetimeIn' => $datetimeIn,
346
+				],
347
+			],
348
+			'query' => $query,
349
+		];
350
+
351
+		$responseData = $this->makeGraphQLRequest($data);
352
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
353
+	}
354
+
355
+
356
+	/**
357
+	 * @param array $ticketIn
358
+	 * @return array|null
359
+	 * @since $VID:$
360
+	 */
361
+	protected function getGraphQLPrices(array $ticketIn)
362
+	{
363
+		$field_key = lcfirst($this->namespace) . 'Prices';
364
+		$query = <<<QUERY
365 365
         query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) {
366 366
             {$field_key}(where: \$where, first: \$first, last: \$last) {
367 367
                 nodes {
@@ -384,30 +384,30 @@  discard block
 block discarded – undo
384 384
             }
385 385
         }
386 386
 QUERY;
387
-        $data = [
388
-            'operation_name' => 'GET_PRICES',
389
-            'variables' => [
390
-                'first' => 100,
391
-                'where' => [
392
-                    'ticketIn' => $ticketIn,
393
-                ],
394
-            ],
395
-            'query' => $query,
396
-        ];
397
-
398
-        $responseData = $this->makeGraphQLRequest($data);
399
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
400
-    }
401
-
402
-
403
-    /**
404
-     * @return array|null
405
-     * @since $VID:$
406
-     */
407
-    protected function getGraphQLPriceTypes()
408
-    {
409
-        $field_key = lcfirst($this->namespace) . 'PriceTypes';
410
-        $query = <<<QUERY
387
+		$data = [
388
+			'operation_name' => 'GET_PRICES',
389
+			'variables' => [
390
+				'first' => 100,
391
+				'where' => [
392
+					'ticketIn' => $ticketIn,
393
+				],
394
+			],
395
+			'query' => $query,
396
+		];
397
+
398
+		$responseData = $this->makeGraphQLRequest($data);
399
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
400
+	}
401
+
402
+
403
+	/**
404
+	 * @return array|null
405
+	 * @since $VID:$
406
+	 */
407
+	protected function getGraphQLPriceTypes()
408
+	{
409
+		$field_key = lcfirst($this->namespace) . 'PriceTypes';
410
+		$query = <<<QUERY
411 411
         query GET_PRICE_TYPES(\$first: Int, \$last: Int ) {
412 412
             {$field_key}(first: \$first, last: \$last) {
413 413
                 nodes {
@@ -427,27 +427,27 @@  discard block
 block discarded – undo
427 427
             }
428 428
         }
429 429
 QUERY;
430
-        $data = [
431
-            'operation_name' => 'GET_PRICE_TYPES',
432
-            'variables' => [
433
-                'first' => 100,
434
-            ],
435
-            'query' => $query,
436
-        ];
437
-
438
-        $responseData = $this->makeGraphQLRequest($data);
439
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
440
-    }
441
-
442
-
443
-    /**
444
-     * @return array|null
445
-     * @since $VID:$
446
-     */
447
-    protected function getGraphQLCurrentUser()
448
-    {
449
-        $field_key = 'viewer';
450
-        $query = <<<QUERY
430
+		$data = [
431
+			'operation_name' => 'GET_PRICE_TYPES',
432
+			'variables' => [
433
+				'first' => 100,
434
+			],
435
+			'query' => $query,
436
+		];
437
+
438
+		$responseData = $this->makeGraphQLRequest($data);
439
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
440
+	}
441
+
442
+
443
+	/**
444
+	 * @return array|null
445
+	 * @since $VID:$
446
+	 */
447
+	protected function getGraphQLCurrentUser()
448
+	{
449
+		$field_key = 'viewer';
450
+		$query = <<<QUERY
451 451
         query GET_CURRENT_USER {
452 452
             {$field_key} {
453 453
                 description
@@ -465,24 +465,24 @@  discard block
 block discarded – undo
465 465
             }
466 466
         }
467 467
 QUERY;
468
-        $data = [
469
-            'operation_name' => 'GET_CURRENT_USER',
470
-            'query' => $query,
471
-        ];
472
-
473
-        $responseData = $this->makeGraphQLRequest($data);
474
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
475
-    }
476
-
477
-
478
-    /**
479
-     * @return array|null
480
-     * @since $VID:$
481
-     */
482
-    protected function getGraphQLGeneralSettings()
483
-    {
484
-        $field_key = 'generalSettings';
485
-        $query = <<<QUERY
468
+		$data = [
469
+			'operation_name' => 'GET_CURRENT_USER',
470
+			'query' => $query,
471
+		];
472
+
473
+		$responseData = $this->makeGraphQLRequest($data);
474
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
475
+	}
476
+
477
+
478
+	/**
479
+	 * @return array|null
480
+	 * @since $VID:$
481
+	 */
482
+	protected function getGraphQLGeneralSettings()
483
+	{
484
+		$field_key = 'generalSettings';
485
+		$query = <<<QUERY
486 486
         query GET_GENERAL_SETTINGS {
487 487
             {$field_key} {
488 488
                 dateFormat
@@ -492,166 +492,166 @@  discard block
 block discarded – undo
492 492
             }
493 493
         }
494 494
 QUERY;
495
-        $data = [
496
-            'operation_name' => 'GET_CURRENT_USER',
497
-            'query' => $query,
498
-        ];
499
-
500
-        $responseData = $this->makeGraphQLRequest($data);
501
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
502
-    }
503
-
504
-
505
-    /**
506
-     * @param array $data
507
-     * @return array
508
-     * @since $VID:$
509
-     */
510
-    protected function makeGraphQLRequest($data)
511
-    {
512
-        try {
513
-            $response = graphql($data);
514
-            if (!empty($response['data'])) {
515
-                return $response['data'];
516
-            }
517
-            return null;
518
-        } catch (\Exception $e) {
519
-            // do something with the errors thrown
520
-            return null;
521
-        }
522
-    }
523
-
524
-
525
-    /**
526
-     * @param mixed       $source  The source that's passed down the GraphQL queries
527
-     * @param array       $args    The inputArgs on the field
528
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
529
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
530
-     * @return string
531
-     * @throws EE_Error
532
-     * @throws Exception
533
-     * @throws InvalidArgumentException
534
-     * @throws InvalidDataTypeException
535
-     * @throws InvalidInterfaceException
536
-     * @throws ReflectionException
537
-     * @throws UserError
538
-     * @throws UnexpectedEntityException
539
-     * @since $VID:$
540
-     */
541
-    public static function getRelationalData($eventId)
542
-    {
543
-        $data = [
544
-            'datetimes'  => [],
545
-            'tickets'    => [],
546
-            'prices'     => [],
547
-        ];
548
-
549
-        $eem_datetime   = EEM_Datetime::instance();
550
-        $eem_ticket     = EEM_Ticket::instance();
551
-        $eem_price      = EEM_Price::instance();
552
-        $eem_price_type = EEM_Price_Type::instance();
553
-
554
-        // PROCESS DATETIMES
555
-        $related_models = [
556
-            'tickets' => $eem_ticket,
557
-        ];
558
-        // Get the IDs of event datetimes.
559
-        $datetimeIds = $eem_datetime->get_col([[
560
-            'EVT_ID' => $eventId,
561
-            'DTT_deleted' => ['IN', [true, false]],
562
-        ]]);
563
-        foreach ($datetimeIds as $datetimeId) {
564
-            $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId);
565
-            foreach ($related_models as $key => $model) {
566
-                // Get the IDs of related entities for the datetime ID.
567
-                $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]);
568
-                $data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
569
-            }
570
-        }
571
-
572
-        // PROCESS TICKETS
573
-        $related_models = [
574
-            'datetimes' => $eem_datetime,
575
-            'prices'    => $eem_price,
576
-        ];
577
-        // Get the IDs of all datetime tickets.
578
-        $ticketIds = $eem_ticket->get_col([[
579
-            'Datetime.DTT_ID' => ['in', $datetimeIds],
580
-            'TKT_deleted' => ['IN', [true, false]],
581
-        ]]);
582
-        foreach ($ticketIds as $ticketId) {
583
-            $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId);
584
-
585
-            foreach ($related_models as $key => $model) {
586
-                // Get the IDs of related entities for the ticket ID.
587
-                $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]);
588
-                $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
589
-            }
590
-        }
591
-
592
-        // PROCESS PRICES
593
-        $related_models = [
594
-            'tickets'    => $eem_ticket,
595
-            'priceTypes' => $eem_price_type,
596
-        ];
597
-        // Get the IDs of all ticket prices.
598
-        $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]);
599
-        foreach ($priceIds as $priceId) {
600
-            $GID = self::convertToGlobalId($eem_price->item_name(), $priceId);
601
-
602
-            foreach ($related_models as $key => $model) {
603
-                // Get the IDs of related entities for the price ID.
604
-                $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]);
605
-                $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
606
-            }
607
-        }
608
-
609
-        return $data;
610
-    }
611
-
612
-    /**
613
-     * Convert the DB ID into GID
614
-     *
615
-     * @param string    $type
616
-     * @param int|int[] $ID
617
-     * @return mixed
618
-     */
619
-    public static function convertToGlobalId($type, $ID)
620
-    {
621
-        if (is_array($ID)) {
622
-            return array_map(function ($id) use ($type) {
623
-                return self::convertToGlobalId($type, $id);
624
-            }, $ID);
625
-        }
626
-        return Relay::toGlobalId($type, $ID);
627
-    }
628
-
629
-
630
-    /**
631
-     * Returns Jed-formatted localization data.
632
-     *
633
-     * @param  string $domain Translation domain.
634
-     * @return array
635
-     */
636
-    public static function getJedLocaleData($domain)
637
-    {
638
-        $translations = get_translations_for_domain($domain);
639
-
640
-        $locale = array(
641
-            '' => array(
642
-                'domain' => $domain,
643
-                'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
644
-            ),
645
-        );
646
-
647
-        if (! empty($translations->headers['Plural-Forms'])) {
648
-            $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
649
-        }
650
-
651
-        foreach ($translations->entries as $msgid => $entry) {
652
-            $locale[ $msgid ] = $entry->translations;
653
-        }
654
-
655
-        return $locale;
656
-    }
495
+		$data = [
496
+			'operation_name' => 'GET_CURRENT_USER',
497
+			'query' => $query,
498
+		];
499
+
500
+		$responseData = $this->makeGraphQLRequest($data);
501
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
502
+	}
503
+
504
+
505
+	/**
506
+	 * @param array $data
507
+	 * @return array
508
+	 * @since $VID:$
509
+	 */
510
+	protected function makeGraphQLRequest($data)
511
+	{
512
+		try {
513
+			$response = graphql($data);
514
+			if (!empty($response['data'])) {
515
+				return $response['data'];
516
+			}
517
+			return null;
518
+		} catch (\Exception $e) {
519
+			// do something with the errors thrown
520
+			return null;
521
+		}
522
+	}
523
+
524
+
525
+	/**
526
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
527
+	 * @param array       $args    The inputArgs on the field
528
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
529
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
530
+	 * @return string
531
+	 * @throws EE_Error
532
+	 * @throws Exception
533
+	 * @throws InvalidArgumentException
534
+	 * @throws InvalidDataTypeException
535
+	 * @throws InvalidInterfaceException
536
+	 * @throws ReflectionException
537
+	 * @throws UserError
538
+	 * @throws UnexpectedEntityException
539
+	 * @since $VID:$
540
+	 */
541
+	public static function getRelationalData($eventId)
542
+	{
543
+		$data = [
544
+			'datetimes'  => [],
545
+			'tickets'    => [],
546
+			'prices'     => [],
547
+		];
548
+
549
+		$eem_datetime   = EEM_Datetime::instance();
550
+		$eem_ticket     = EEM_Ticket::instance();
551
+		$eem_price      = EEM_Price::instance();
552
+		$eem_price_type = EEM_Price_Type::instance();
553
+
554
+		// PROCESS DATETIMES
555
+		$related_models = [
556
+			'tickets' => $eem_ticket,
557
+		];
558
+		// Get the IDs of event datetimes.
559
+		$datetimeIds = $eem_datetime->get_col([[
560
+			'EVT_ID' => $eventId,
561
+			'DTT_deleted' => ['IN', [true, false]],
562
+		]]);
563
+		foreach ($datetimeIds as $datetimeId) {
564
+			$GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId);
565
+			foreach ($related_models as $key => $model) {
566
+				// Get the IDs of related entities for the datetime ID.
567
+				$Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]);
568
+				$data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
569
+			}
570
+		}
571
+
572
+		// PROCESS TICKETS
573
+		$related_models = [
574
+			'datetimes' => $eem_datetime,
575
+			'prices'    => $eem_price,
576
+		];
577
+		// Get the IDs of all datetime tickets.
578
+		$ticketIds = $eem_ticket->get_col([[
579
+			'Datetime.DTT_ID' => ['in', $datetimeIds],
580
+			'TKT_deleted' => ['IN', [true, false]],
581
+		]]);
582
+		foreach ($ticketIds as $ticketId) {
583
+			$GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId);
584
+
585
+			foreach ($related_models as $key => $model) {
586
+				// Get the IDs of related entities for the ticket ID.
587
+				$Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]);
588
+				$data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
589
+			}
590
+		}
591
+
592
+		// PROCESS PRICES
593
+		$related_models = [
594
+			'tickets'    => $eem_ticket,
595
+			'priceTypes' => $eem_price_type,
596
+		];
597
+		// Get the IDs of all ticket prices.
598
+		$priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['in', $ticketIds]]]);
599
+		foreach ($priceIds as $priceId) {
600
+			$GID = self::convertToGlobalId($eem_price->item_name(), $priceId);
601
+
602
+			foreach ($related_models as $key => $model) {
603
+				// Get the IDs of related entities for the price ID.
604
+				$Ids = $model->get_col([['Price.PRC_ID' => $priceId]]);
605
+				$data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
606
+			}
607
+		}
608
+
609
+		return $data;
610
+	}
611
+
612
+	/**
613
+	 * Convert the DB ID into GID
614
+	 *
615
+	 * @param string    $type
616
+	 * @param int|int[] $ID
617
+	 * @return mixed
618
+	 */
619
+	public static function convertToGlobalId($type, $ID)
620
+	{
621
+		if (is_array($ID)) {
622
+			return array_map(function ($id) use ($type) {
623
+				return self::convertToGlobalId($type, $id);
624
+			}, $ID);
625
+		}
626
+		return Relay::toGlobalId($type, $ID);
627
+	}
628
+
629
+
630
+	/**
631
+	 * Returns Jed-formatted localization data.
632
+	 *
633
+	 * @param  string $domain Translation domain.
634
+	 * @return array
635
+	 */
636
+	public static function getJedLocaleData($domain)
637
+	{
638
+		$translations = get_translations_for_domain($domain);
639
+
640
+		$locale = array(
641
+			'' => array(
642
+				'domain' => $domain,
643
+				'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
644
+			),
645
+		);
646
+
647
+		if (! empty($translations->headers['Plural-Forms'])) {
648
+			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
649
+		}
650
+
651
+		foreach ($translations->entries as $msgid => $entry) {
652
+			$locale[ $msgid ] = $entry->translations;
653
+		}
654
+
655
+		return $locale;
656
+	}
657 657
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
     {
104 104
         if ($this->admin_config->useAdvancedEditor()) {
105 105
             $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0;
106
-            if (! $eventId) {
106
+            if ( ! $eventId) {
107 107
                 global $post;
108 108
                 $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
109 109
                 $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events'
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 $data = wp_json_encode($data);
116 116
                 add_action(
117 117
                     'admin_footer',
118
-                    static function () use ($data) {
118
+                    static function() use ($data) {
119 119
                         wp_add_inline_script(
120 120
                             EspressoEditorAssetManager::JS_HANDLE_EDITOR,
121 121
                             "
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         $event = $this->getEventGraphQLData($eventId);
161 161
         $event['dbId'] = $eventId;
162 162
 
163
-        $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : '';
163
+        $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()).Router::$route : '';
164 164
         $graphqlEndpoint = esc_url($graphqlEndpoint);
165 165
 
166 166
         $currentUser = $this->getGraphQLCurrentUser();
@@ -187,18 +187,18 @@  discard block
 block discarded – undo
187 187
             $datetimes = $this->getGraphQLDatetimes($eventId);
188 188
         }
189 189
 
190
-        if (! empty($datetimes['nodes'])) {
190
+        if ( ! empty($datetimes['nodes'])) {
191 191
             $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
192 192
 
193
-            if (! empty($datetimeIn)) {
193
+            if ( ! empty($datetimeIn)) {
194 194
                 $tickets = $this->getGraphQLTickets($datetimeIn);
195 195
             }
196 196
         }
197 197
 
198
-        if (! empty($tickets['nodes'])) {
198
+        if ( ! empty($tickets['nodes'])) {
199 199
             $ticketIn = wp_list_pluck($tickets['nodes'], 'id');
200 200
 
201
-            if (! empty($ticketIn)) {
201
+            if ( ! empty($ticketIn)) {
202 202
                 $prices = $this->getGraphQLPrices($ticketIn);
203 203
             }
204 204
         }
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
      */
251 251
     protected function getGraphQLDatetimes($eventId)
252 252
     {
253
-        $field_key = lcfirst($this->namespace) . 'Datetimes';
253
+        $field_key = lcfirst($this->namespace).'Datetimes';
254 254
         $query = <<<QUERY
255 255
         query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) {
256 256
             {$field_key}(where: \$where, first: \$first, last: \$last) {
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
         ];
292 292
 
293 293
         $responseData = $this->makeGraphQLRequest($data);
294
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
294
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
295 295
     }
296 296
 
297 297
 
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      */
303 303
     protected function getGraphQLTickets(array $datetimeIn)
304 304
     {
305
-        $field_key = lcfirst($this->namespace) . 'Tickets';
305
+        $field_key = lcfirst($this->namespace).'Tickets';
306 306
         $query = <<<QUERY
307 307
         query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) {
308 308
             {$field_key}(where: \$where, first: \$first, last: \$last) {
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
         ];
350 350
 
351 351
         $responseData = $this->makeGraphQLRequest($data);
352
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
352
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
353 353
     }
354 354
 
355 355
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
      */
361 361
     protected function getGraphQLPrices(array $ticketIn)
362 362
     {
363
-        $field_key = lcfirst($this->namespace) . 'Prices';
363
+        $field_key = lcfirst($this->namespace).'Prices';
364 364
         $query = <<<QUERY
365 365
         query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) {
366 366
             {$field_key}(where: \$where, first: \$first, last: \$last) {
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
         ];
397 397
 
398 398
         $responseData = $this->makeGraphQLRequest($data);
399
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
399
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
400 400
     }
401 401
 
402 402
 
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
      */
407 407
     protected function getGraphQLPriceTypes()
408 408
     {
409
-        $field_key = lcfirst($this->namespace) . 'PriceTypes';
409
+        $field_key = lcfirst($this->namespace).'PriceTypes';
410 410
         $query = <<<QUERY
411 411
         query GET_PRICE_TYPES(\$first: Int, \$last: Int ) {
412 412
             {$field_key}(first: \$first, last: \$last) {
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
         ];
437 437
 
438 438
         $responseData = $this->makeGraphQLRequest($data);
439
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
439
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
440 440
     }
441 441
 
442 442
 
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
         ];
472 472
 
473 473
         $responseData = $this->makeGraphQLRequest($data);
474
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
474
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
475 475
     }
476 476
 
477 477
 
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
         ];
499 499
 
500 500
         $responseData = $this->makeGraphQLRequest($data);
501
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
501
+        return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null;
502 502
     }
503 503
 
504 504
 
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
     {
512 512
         try {
513 513
             $response = graphql($data);
514
-            if (!empty($response['data'])) {
514
+            if ( ! empty($response['data'])) {
515 515
                 return $response['data'];
516 516
             }
517 517
             return null;
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
             foreach ($related_models as $key => $model) {
566 566
                 // Get the IDs of related entities for the datetime ID.
567 567
                 $Ids = $model->get_col([['Datetime.DTT_ID' => $datetimeId]]);
568
-                $data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
568
+                $data['datetimes'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
569 569
             }
570 570
         }
571 571
 
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
             foreach ($related_models as $key => $model) {
586 586
                 // Get the IDs of related entities for the ticket ID.
587 587
                 $Ids = $model->get_col([['Ticket.TKT_ID' => $ticketId]]);
588
-                $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
588
+                $data['tickets'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
589 589
             }
590 590
         }
591 591
 
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
             foreach ($related_models as $key => $model) {
603 603
                 // Get the IDs of related entities for the price ID.
604 604
                 $Ids = $model->get_col([['Price.PRC_ID' => $priceId]]);
605
-                $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
605
+                $data['prices'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
606 606
             }
607 607
         }
608 608
 
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
     public static function convertToGlobalId($type, $ID)
620 620
     {
621 621
         if (is_array($ID)) {
622
-            return array_map(function ($id) use ($type) {
622
+            return array_map(function($id) use ($type) {
623 623
                 return self::convertToGlobalId($type, $id);
624 624
             }, $ID);
625 625
         }
@@ -644,12 +644,12 @@  discard block
 block discarded – undo
644 644
             ),
645 645
         );
646 646
 
647
-        if (! empty($translations->headers['Plural-Forms'])) {
647
+        if ( ! empty($translations->headers['Plural-Forms'])) {
648 648
             $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
649 649
         }
650 650
 
651 651
         foreach ($translations->entries as $msgid => $entry) {
652
-            $locale[ $msgid ] = $entry->translations;
652
+            $locale[$msgid] = $entry->translations;
653 653
         }
654 654
 
655 655
         return $locale;
Please login to merge, or discard this patch.
core/domain/services/assets/EspressoEditorAssetManager.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -19,52 +19,52 @@
 block discarded – undo
19 19
  */
20 20
 class EspressoEditorAssetManager extends AssetManager
21 21
 {
22
-    const JS_HANDLE_EDITOR = 'eventespresso-editor';
23
-    // const JS_HANDLE_EDITOR_PROTOTYPE = 'eventespresso-editor-prototype';
24
-    const CSS_HANDLE_EDITOR = 'eventespresso-editor';
25
-    // const CSS_HANDLE_EDITOR_PROTOTYPE = 'eventespresso-editor-prototype';
22
+	const JS_HANDLE_EDITOR = 'eventespresso-editor';
23
+	// const JS_HANDLE_EDITOR_PROTOTYPE = 'eventespresso-editor-prototype';
24
+	const CSS_HANDLE_EDITOR = 'eventespresso-editor';
25
+	// const CSS_HANDLE_EDITOR_PROTOTYPE = 'eventespresso-editor-prototype';
26 26
 
27 27
 
28
-    /**
29
-     * @throws InvalidDataTypeException
30
-     * @throws InvalidEntityException
31
-     * @throws DuplicateCollectionIdentifierException
32
-     * @throws DomainException
33
-     */
34
-    public function addAssets()
35
-    {
36
-        $this->registerJavascript();
37
-        $this->registerStyleSheets();
38
-    }
28
+	/**
29
+	 * @throws InvalidDataTypeException
30
+	 * @throws InvalidEntityException
31
+	 * @throws DuplicateCollectionIdentifierException
32
+	 * @throws DomainException
33
+	 */
34
+	public function addAssets()
35
+	{
36
+		$this->registerJavascript();
37
+		$this->registerStyleSheets();
38
+	}
39 39
 
40 40
 
41
-    /**
42
-     * Register javascript assets
43
-     *
44
-     * @throws InvalidDataTypeException
45
-     * @throws InvalidEntityException
46
-     * @throws DuplicateCollectionIdentifierException
47
-     * @throws DomainException
48
-     */
49
-    private function registerJavascript()
50
-    {
51
-        $this->addJs(self::JS_HANDLE_EDITOR, [CoreAssetManager::JS_HANDLE_JS_CORE])->setRequiresTranslation();
52
-        // $this->addJs(self::JS_HANDLE_EDITOR, [CoreAssetManager::JS_HANDLE_JS_CORE])->setRequiresTranslation();
53
-        // $this->addJs(self::JS_HANDLE_EDITOR_PROTOTYPE, [self::JS_HANDLE_EDITOR])->setRequiresTranslation();
54
-    }
41
+	/**
42
+	 * Register javascript assets
43
+	 *
44
+	 * @throws InvalidDataTypeException
45
+	 * @throws InvalidEntityException
46
+	 * @throws DuplicateCollectionIdentifierException
47
+	 * @throws DomainException
48
+	 */
49
+	private function registerJavascript()
50
+	{
51
+		$this->addJs(self::JS_HANDLE_EDITOR, [CoreAssetManager::JS_HANDLE_JS_CORE])->setRequiresTranslation();
52
+		// $this->addJs(self::JS_HANDLE_EDITOR, [CoreAssetManager::JS_HANDLE_JS_CORE])->setRequiresTranslation();
53
+		// $this->addJs(self::JS_HANDLE_EDITOR_PROTOTYPE, [self::JS_HANDLE_EDITOR])->setRequiresTranslation();
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     * Register CSS assets.
59
-     *
60
-     * @throws DuplicateCollectionIdentifierException
61
-     * @throws InvalidDataTypeException
62
-     * @throws InvalidEntityException
63
-     * @throws DomainException
64
-     */
65
-    private function registerStyleSheets()
66
-    {
67
-        $this->addCss(self::CSS_HANDLE_EDITOR);
68
-        // $this->addCss(self::CSS_HANDLE_EDITOR_PROTOTYPE, [self::CSS_HANDLE_EDITOR]);
69
-    }
57
+	/**
58
+	 * Register CSS assets.
59
+	 *
60
+	 * @throws DuplicateCollectionIdentifierException
61
+	 * @throws InvalidDataTypeException
62
+	 * @throws InvalidEntityException
63
+	 * @throws DomainException
64
+	 */
65
+	private function registerStyleSheets()
66
+	{
67
+		$this->addCss(self::CSS_HANDLE_EDITOR);
68
+		// $this->addCss(self::CSS_HANDLE_EDITOR_PROTOTYPE, [self::CSS_HANDLE_EDITOR]);
69
+	}
70 70
 }
Please login to merge, or discard this patch.
core/domain/services/assets/CoreAssetManager.php 2 patches
Indentation   +442 added lines, -442 removed lines patch added patch discarded remove patch
@@ -32,469 +32,469 @@
 block discarded – undo
32 32
 class CoreAssetManager extends AssetManager
33 33
 {
34 34
 
35
-    // WordPress core / Third party JS asset handles
36
-    const JS_HANDLE_JQUERY = 'jquery';
35
+	// WordPress core / Third party JS asset handles
36
+	const JS_HANDLE_JQUERY = 'jquery';
37 37
 
38
-    const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
38
+	const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
39 39
 
40
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
40
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
41 41
 
42
-    const JS_HANDLE_UNDERSCORE = 'underscore';
42
+	const JS_HANDLE_UNDERSCORE = 'underscore';
43 43
 
44
-    const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
44
+	const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
45 45
 
46
-    /**
47
-     * @since 4.9.71.p
48
-     */
49
-    const JS_HANDLE_REACT = 'react';
46
+	/**
47
+	 * @since 4.9.71.p
48
+	 */
49
+	const JS_HANDLE_REACT = 'react';
50 50
 
51
-    /**
52
-     * @since 4.9.71.p
53
-     */
54
-    const JS_HANDLE_REACT_DOM = 'react-dom';
51
+	/**
52
+	 * @since 4.9.71.p
53
+	 */
54
+	const JS_HANDLE_REACT_DOM = 'react-dom';
55 55
 
56
-    /**
57
-     * @since 4.9.71.p
58
-     */
59
-    const JS_HANDLE_LODASH = 'lodash';
56
+	/**
57
+	 * @since 4.9.71.p
58
+	 */
59
+	const JS_HANDLE_LODASH = 'lodash';
60 60
 
61
-    const JS_HANDLE_JS_CORE = 'eejs-core';
61
+	const JS_HANDLE_JS_CORE = 'eejs-core';
62 62
 
63
-    const JS_HANDLE_VENDOR = 'eventespresso-vendor';
63
+	const JS_HANDLE_VENDOR = 'eventespresso-vendor';
64 64
 
65
-    const JS_HANDLE_UTILS = 'eventespresso-utils';
65
+	const JS_HANDLE_UTILS = 'eventespresso-utils';
66 66
 
67
-    const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
67
+	const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
68 68
 
69
-    const JS_HANDLE_HELPERS = 'eventespresso-helpers';
69
+	const JS_HANDLE_HELPERS = 'eventespresso-helpers';
70 70
 
71
-    const JS_HANDLE_MODEL = 'eventespresso-model';
72
-    const JS_HANDLE_MODEL_SCHEMA = 'eventespresso-model-schema';
71
+	const JS_HANDLE_MODEL = 'eventespresso-model';
72
+	const JS_HANDLE_MODEL_SCHEMA = 'eventespresso-model-schema';
73 73
 
74
-    const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
74
+	const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
75 75
 
76
-    const JS_HANDLE_HOCS = 'eventespresso-hocs';
76
+	const JS_HANDLE_HOCS = 'eventespresso-hocs';
77 77
 
78
-    const JS_HANDLE_COMPONENTS = 'eventespresso-components';
78
+	const JS_HANDLE_COMPONENTS = 'eventespresso-components';
79 79
 
80
-    const JS_HANDLE_HOOKS = 'eventespresso-hooks';
80
+	const JS_HANDLE_HOOKS = 'eventespresso-hooks';
81 81
 
82
-    const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
82
+	const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
83 83
 
84
-    const JS_HANDLE_CORE = 'espresso_core';
84
+	const JS_HANDLE_CORE = 'espresso_core';
85 85
 
86
-    const JS_HANDLE_I18N = 'eei18n';
86
+	const JS_HANDLE_I18N = 'eei18n';
87 87
 
88
-    const JS_HANDLE_ACCOUNTING = 'ee-accounting';
88
+	const JS_HANDLE_ACCOUNTING = 'ee-accounting';
89 89
 
90
-    const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
90
+	const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
91 91
 
92
-    // EE CSS assets handles
93
-    const CSS_HANDLE_DEFAULT = 'espresso_default';
94
-
95
-    const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
96
-
97
-    const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
98
-
99
-    const CSS_HANDLE_HOCS = 'eventespresso-hocs';
100
-
101
-    const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default';
102
-
103
-    /**
104
-     * @var EE_Currency_Config $currency_config
105
-     */
106
-    protected $currency_config;
107
-
108
-    /**
109
-     * @var EE_Template_Config $template_config
110
-     */
111
-    protected $template_config;
112
-
113
-
114
-    /**
115
-     * CoreAssetRegister constructor.
116
-     *
117
-     * @param AssetCollection    $assets
118
-     * @param EE_Currency_Config $currency_config
119
-     * @param EE_Template_Config $template_config
120
-     * @param DomainInterface    $domain
121
-     * @param Registry           $registry
122
-     */
123
-    public function __construct(
124
-        AssetCollection $assets,
125
-        EE_Currency_Config $currency_config,
126
-        EE_Template_Config $template_config,
127
-        DomainInterface $domain,
128
-        Registry $registry
129
-    ) {
130
-        $this->currency_config = $currency_config;
131
-        $this->template_config = $template_config;
132
-        parent::__construct($domain, $assets, $registry);
133
-    }
134
-
135
-
136
-    /**
137
-     * @since 4.9.62.p
138
-     * @throws DomainException
139
-     * @throws DuplicateCollectionIdentifierException
140
-     * @throws InvalidArgumentException
141
-     * @throws InvalidDataTypeException
142
-     * @throws InvalidEntityException
143
-     * @throws InvalidInterfaceException
144
-     */
145
-    public function addAssets()
146
-    {
147
-        $this->addJavascriptFiles();
148
-        $this->addStylesheetFiles();
149
-    }
150
-
151
-
152
-    /**
153
-     * @since 4.9.62.p
154
-     * @throws DomainException
155
-     * @throws DuplicateCollectionIdentifierException
156
-     * @throws InvalidArgumentException
157
-     * @throws InvalidDataTypeException
158
-     * @throws InvalidEntityException
159
-     * @throws InvalidInterfaceException
160
-     */
161
-    public function addJavascriptFiles()
162
-    {
163
-        $this->loadCoreJs();
164
-        $this->loadJqueryValidate();
165
-        $this->loadAccountingJs();
166
-        add_action(
167
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
168
-            array($this, 'loadQtipJs')
169
-        );
170
-        $this->registerAdminAssets();
171
-    }
172
-
173
-
174
-    /**
175
-     * @throws DuplicateCollectionIdentifierException
176
-     * @throws InvalidDataTypeException
177
-     * @throws InvalidEntityException
178
-     * @throws DomainException
179
-     * @since 4.9.62.p
180
-     */
181
-    public function addStylesheetFiles()
182
-    {
183
-        $this->loadCoreCss();
184
-    }
185
-
186
-
187
-    /**
188
-     * core default javascript
189
-     *
190
-     * @since 4.9.62.p
191
-     * @throws DomainException
192
-     * @throws DuplicateCollectionIdentifierException
193
-     * @throws InvalidArgumentException
194
-     * @throws InvalidDataTypeException
195
-     * @throws InvalidEntityException
196
-     * @throws InvalidInterfaceException
197
-     */
198
-    private function loadCoreJs()
199
-    {
200
-        // conditionally load third-party libraries that WP core MIGHT have.
201
-        $this->registerWpAssets();
202
-
203
-        $this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData();
204
-        // $this->addJs(self::JS_HANDLE_VENDOR);
205
-        // $this->addJs(self::JS_HANDLE_UTILS)->setRequiresTranslation();
206
-        // $this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation();
207
-        // $this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation();
208
-        // $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
209
-        // $this->addJs(self::JS_HANDLE_MODEL_SCHEMA)->setRequiresTranslation();
210
-        // $this->addJs(self::JS_HANDLE_HOOKS);
211
-        // $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
212
-        // $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
213
-        //     static function () {
214
-        //         wp_add_inline_script(
215
-        //             CoreAssetManager::JS_HANDLE_DATA_STORES,
216
-        //             is_admin()
217
-        //                 ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
218
-        //                 : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
219
-        //         );
220
-        //     }
221
-        // );
222
-        // $this->addJs(self::JS_HANDLE_HOCS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
223
-        // $this->addJs(self::JS_HANDLE_COMPONENTS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
224
-
225
-        $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
226
-        $this->registry->addData(
227
-            'paths',
228
-            array(
229
-                'base_rest_route' => rest_url(),
230
-                'rest_route' => rest_url('ee/v4.8.36/'),
231
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
232
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
233
-                'site_url' => site_url('/'),
234
-                'admin_url' => admin_url('/'),
235
-            )
236
-        );
237
-        // Event Espresso brand name
238
-        $this->registry->addData('brandName', Domain::brandName());
239
-        /** site formatting values **/
240
-        $this->registry->addData(
241
-            'site_formats',
242
-            array(
243
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
244
-            )
245
-        );
246
-        /** currency data **/
247
-        $this->registry->addData(
248
-            'currency_config',
249
-            $this->getCurrencySettings()
250
-        );
251
-        /** site timezone */
252
-        $this->registry->addData(
253
-            'default_timezone',
254
-            array(
255
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
256
-                'string' => get_option('timezone_string'),
257
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
258
-            )
259
-        );
260
-        /** site locale (user locale if user logged in) */
261
-        $this->registry->addData(
262
-            'locale',
263
-            array(
264
-                'user' => get_user_locale(),
265
-                'site' => get_locale()
266
-            )
267
-        );
268
-
269
-        $this->addJavascript(
270
-            CoreAssetManager::JS_HANDLE_CORE,
271
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
272
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
273
-        )
274
-        ->setInlineDataCallback(
275
-            static function () {
276
-                wp_localize_script(
277
-                    CoreAssetManager::JS_HANDLE_CORE,
278
-                    CoreAssetManager::JS_HANDLE_I18N,
279
-                    EE_Registry::$i18n_js_strings
280
-                );
281
-            }
282
-        );
283
-    }
284
-
285
-
286
-    /**
287
-     * Registers vendor files that are bundled with a later version WP but might not be for the current version of
288
-     * WordPress in the running environment.
289
-     *
290
-     * @throws DuplicateCollectionIdentifierException
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidEntityException
293
-     * @throws DomainException
294
-     * @since 4.9.71.p
295
-     */
296
-    private function registerWpAssets()
297
-    {
298
-        global $wp_version;
299
-        if (version_compare($wp_version, '5.0.beta', '>=')) {
300
-            return;
301
-        }
302
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT, [], true, '16.6.0');
303
-        $this->addVendorJavascript(
304
-            CoreAssetManager::JS_HANDLE_REACT_DOM,
305
-            array(CoreAssetManager::JS_HANDLE_REACT),
306
-            true,
307
-            '16.6.0'
308
-        );
309
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH, [], true, '4.17.11')
310
-            ->setInlineDataCallback(
311
-                static function() {
312
-                    wp_add_inline_script(
313
-                        CoreAssetManager::JS_HANDLE_LODASH,
314
-                        'window.lodash = _.noConflict();'
315
-                    );
316
-                }
317
-            );
318
-    }
319
-
320
-
321
-    /**
322
-     * Returns configuration data for the accounting-js library.
323
-     * @since 4.9.71.p
324
-     * @return array
325
-     */
326
-    private function getAccountingSettings() {
327
-        return array(
328
-            'currency' => array(
329
-                'symbol'    => $this->currency_config->sign,
330
-                'format'    => array(
331
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
332
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
333
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
334
-                ),
335
-                'decimal'   => $this->currency_config->dec_mrk,
336
-                'thousand'  => $this->currency_config->thsnds,
337
-                'precision' => $this->currency_config->dec_plc,
338
-            ),
339
-            'number'   => array(
340
-                'precision' => $this->currency_config->dec_plc,
341
-                'thousand'  => $this->currency_config->thsnds,
342
-                'decimal'   => $this->currency_config->dec_mrk,
343
-            ),
344
-        );
345
-    }
346
-
347
-
348
-    /**
349
-     * Returns configuration data for the js Currency VO.
350
-     * @since 4.9.71.p
351
-     * @return array
352
-     */
353
-    private function getCurrencySettings()
354
-    {
355
-        return array(
356
-            'code' => $this->currency_config->code,
357
-            'singularLabel' => $this->currency_config->name,
358
-            'pluralLabel' => $this->currency_config->plural,
359
-            'sign' => $this->currency_config->sign,
360
-            'signB4' => $this->currency_config->sign_b4,
361
-            'decimalPlaces' => $this->currency_config->dec_plc,
362
-            'decimalMark' => $this->currency_config->dec_mrk,
363
-            'thousandsSeparator' => $this->currency_config->thsnds,
364
-        );
365
-    }
366
-
367
-
368
-    /**
369
-     * @throws DuplicateCollectionIdentifierException
370
-     * @throws InvalidDataTypeException
371
-     * @throws InvalidEntityException
372
-     * @throws DomainException
373
-     * @since 4.9.62.p
374
-     */
375
-    private function loadCoreCss()
376
-    {
377
-        if ($this->template_config->enable_default_style && ! is_admin()) {
378
-            $this->addStylesheet(
379
-                CoreAssetManager::CSS_HANDLE_DEFAULT,
380
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
381
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
382
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
383
-                array('dashicons')
384
-            );
385
-            //Load custom style sheet if available
386
-            if ($this->template_config->custom_style_sheet !== null) {
387
-                $this->addStylesheet(
388
-                    CoreAssetManager::CSS_HANDLE_CUSTOM,
389
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
390
-                    array(CoreAssetManager::CSS_HANDLE_DEFAULT)
391
-                );
392
-            }
393
-        }
394
-    //     $this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, ['dashicons']);
395
-    //     $this->addCss(self::CSS_HANDLE_COMPONENTS, [self::CSS_HANDLE_CORE_CSS_DEFAULT]);
396
-    //     $this->addCss(self::CSS_HANDLE_HOCS);
397
-    }
398
-
399
-
400
-    /**
401
-     * jQuery Validate for form validation
402
-     *
403
-     * @since 4.9.62.p
404
-     * @throws DomainException
405
-     * @throws DuplicateCollectionIdentifierException
406
-     * @throws InvalidDataTypeException
407
-     * @throws InvalidEntityException
408
-     */
409
-    private function loadJqueryValidate()
410
-    {
411
-        $this->addJavascript(
412
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
413
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
414
-            array(CoreAssetManager::JS_HANDLE_JQUERY),
415
-            true,
416
-            '1.15.0'
417
-        );
418
-
419
-        $this->addJavascript(
420
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
421
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
422
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
423
-            true,
424
-            '1.15.0'
425
-        );
426
-    }
427
-
428
-
429
-    /**
430
-     * accounting.js for performing client-side calculations
431
-     *
432
-     * @since 4.9.62.p
433
-     * @throws DomainException
434
-     * @throws DuplicateCollectionIdentifierException
435
-     * @throws InvalidDataTypeException
436
-     * @throws InvalidEntityException
437
-     */
438
-    private function loadAccountingJs()
439
-    {
440
-        //accounting.js library
441
-        // @link http://josscrowcroft.github.io/accounting.js/
442
-        $this->addJavascript(
443
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
444
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
445
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE),
446
-            true,
447
-            '0.3.2'
448
-        );
449
-
450
-        $this->addJavascript(
451
-            CoreAssetManager::JS_HANDLE_ACCOUNTING,
452
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
453
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
454
-        )
455
-        ->setInlineDataCallback(
456
-            function () {
457
-                 wp_localize_script(
458
-                     CoreAssetManager::JS_HANDLE_ACCOUNTING,
459
-                     'EE_ACCOUNTING_CFG',
460
-                     $this->getAccountingSettings()
461
-                 );
462
-            }
463
-        );
464
-    }
465
-
466
-
467
-    /**
468
-     * registers assets for cleaning your ears
469
-     *
470
-     * @param JavascriptAsset $script
471
-     */
472
-    public function loadQtipJs(JavascriptAsset $script)
473
-    {
474
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
475
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
476
-        if (
477
-            $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
478
-            && apply_filters('FHEE_load_qtip', false)
479
-        ) {
480
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
481
-        }
482
-    }
483
-
484
-
485
-    /**
486
-     * assets that are used in the WordPress admin
487
-     *
488
-     * @throws DuplicateCollectionIdentifierException
489
-     * @throws InvalidDataTypeException
490
-     * @throws InvalidEntityException
491
-     * @throws DomainException
492
-     * @since 4.9.62.p
493
-     */
494
-    private function registerAdminAssets()
495
-    {
496
-        $this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation();
497
-        // note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle.
498
-        $this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE);
499
-    }
92
+	// EE CSS assets handles
93
+	const CSS_HANDLE_DEFAULT = 'espresso_default';
94
+
95
+	const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
96
+
97
+	const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
98
+
99
+	const CSS_HANDLE_HOCS = 'eventespresso-hocs';
100
+
101
+	const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default';
102
+
103
+	/**
104
+	 * @var EE_Currency_Config $currency_config
105
+	 */
106
+	protected $currency_config;
107
+
108
+	/**
109
+	 * @var EE_Template_Config $template_config
110
+	 */
111
+	protected $template_config;
112
+
113
+
114
+	/**
115
+	 * CoreAssetRegister constructor.
116
+	 *
117
+	 * @param AssetCollection    $assets
118
+	 * @param EE_Currency_Config $currency_config
119
+	 * @param EE_Template_Config $template_config
120
+	 * @param DomainInterface    $domain
121
+	 * @param Registry           $registry
122
+	 */
123
+	public function __construct(
124
+		AssetCollection $assets,
125
+		EE_Currency_Config $currency_config,
126
+		EE_Template_Config $template_config,
127
+		DomainInterface $domain,
128
+		Registry $registry
129
+	) {
130
+		$this->currency_config = $currency_config;
131
+		$this->template_config = $template_config;
132
+		parent::__construct($domain, $assets, $registry);
133
+	}
134
+
135
+
136
+	/**
137
+	 * @since 4.9.62.p
138
+	 * @throws DomainException
139
+	 * @throws DuplicateCollectionIdentifierException
140
+	 * @throws InvalidArgumentException
141
+	 * @throws InvalidDataTypeException
142
+	 * @throws InvalidEntityException
143
+	 * @throws InvalidInterfaceException
144
+	 */
145
+	public function addAssets()
146
+	{
147
+		$this->addJavascriptFiles();
148
+		$this->addStylesheetFiles();
149
+	}
150
+
151
+
152
+	/**
153
+	 * @since 4.9.62.p
154
+	 * @throws DomainException
155
+	 * @throws DuplicateCollectionIdentifierException
156
+	 * @throws InvalidArgumentException
157
+	 * @throws InvalidDataTypeException
158
+	 * @throws InvalidEntityException
159
+	 * @throws InvalidInterfaceException
160
+	 */
161
+	public function addJavascriptFiles()
162
+	{
163
+		$this->loadCoreJs();
164
+		$this->loadJqueryValidate();
165
+		$this->loadAccountingJs();
166
+		add_action(
167
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
168
+			array($this, 'loadQtipJs')
169
+		);
170
+		$this->registerAdminAssets();
171
+	}
172
+
173
+
174
+	/**
175
+	 * @throws DuplicateCollectionIdentifierException
176
+	 * @throws InvalidDataTypeException
177
+	 * @throws InvalidEntityException
178
+	 * @throws DomainException
179
+	 * @since 4.9.62.p
180
+	 */
181
+	public function addStylesheetFiles()
182
+	{
183
+		$this->loadCoreCss();
184
+	}
185
+
186
+
187
+	/**
188
+	 * core default javascript
189
+	 *
190
+	 * @since 4.9.62.p
191
+	 * @throws DomainException
192
+	 * @throws DuplicateCollectionIdentifierException
193
+	 * @throws InvalidArgumentException
194
+	 * @throws InvalidDataTypeException
195
+	 * @throws InvalidEntityException
196
+	 * @throws InvalidInterfaceException
197
+	 */
198
+	private function loadCoreJs()
199
+	{
200
+		// conditionally load third-party libraries that WP core MIGHT have.
201
+		$this->registerWpAssets();
202
+
203
+		$this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData();
204
+		// $this->addJs(self::JS_HANDLE_VENDOR);
205
+		// $this->addJs(self::JS_HANDLE_UTILS)->setRequiresTranslation();
206
+		// $this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation();
207
+		// $this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation();
208
+		// $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
209
+		// $this->addJs(self::JS_HANDLE_MODEL_SCHEMA)->setRequiresTranslation();
210
+		// $this->addJs(self::JS_HANDLE_HOOKS);
211
+		// $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
212
+		// $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
213
+		//     static function () {
214
+		//         wp_add_inline_script(
215
+		//             CoreAssetManager::JS_HANDLE_DATA_STORES,
216
+		//             is_admin()
217
+		//                 ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
218
+		//                 : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
219
+		//         );
220
+		//     }
221
+		// );
222
+		// $this->addJs(self::JS_HANDLE_HOCS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
223
+		// $this->addJs(self::JS_HANDLE_COMPONENTS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
224
+
225
+		$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
226
+		$this->registry->addData(
227
+			'paths',
228
+			array(
229
+				'base_rest_route' => rest_url(),
230
+				'rest_route' => rest_url('ee/v4.8.36/'),
231
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
232
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
233
+				'site_url' => site_url('/'),
234
+				'admin_url' => admin_url('/'),
235
+			)
236
+		);
237
+		// Event Espresso brand name
238
+		$this->registry->addData('brandName', Domain::brandName());
239
+		/** site formatting values **/
240
+		$this->registry->addData(
241
+			'site_formats',
242
+			array(
243
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
244
+			)
245
+		);
246
+		/** currency data **/
247
+		$this->registry->addData(
248
+			'currency_config',
249
+			$this->getCurrencySettings()
250
+		);
251
+		/** site timezone */
252
+		$this->registry->addData(
253
+			'default_timezone',
254
+			array(
255
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
256
+				'string' => get_option('timezone_string'),
257
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
258
+			)
259
+		);
260
+		/** site locale (user locale if user logged in) */
261
+		$this->registry->addData(
262
+			'locale',
263
+			array(
264
+				'user' => get_user_locale(),
265
+				'site' => get_locale()
266
+			)
267
+		);
268
+
269
+		$this->addJavascript(
270
+			CoreAssetManager::JS_HANDLE_CORE,
271
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
272
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
273
+		)
274
+		->setInlineDataCallback(
275
+			static function () {
276
+				wp_localize_script(
277
+					CoreAssetManager::JS_HANDLE_CORE,
278
+					CoreAssetManager::JS_HANDLE_I18N,
279
+					EE_Registry::$i18n_js_strings
280
+				);
281
+			}
282
+		);
283
+	}
284
+
285
+
286
+	/**
287
+	 * Registers vendor files that are bundled with a later version WP but might not be for the current version of
288
+	 * WordPress in the running environment.
289
+	 *
290
+	 * @throws DuplicateCollectionIdentifierException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidEntityException
293
+	 * @throws DomainException
294
+	 * @since 4.9.71.p
295
+	 */
296
+	private function registerWpAssets()
297
+	{
298
+		global $wp_version;
299
+		if (version_compare($wp_version, '5.0.beta', '>=')) {
300
+			return;
301
+		}
302
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT, [], true, '16.6.0');
303
+		$this->addVendorJavascript(
304
+			CoreAssetManager::JS_HANDLE_REACT_DOM,
305
+			array(CoreAssetManager::JS_HANDLE_REACT),
306
+			true,
307
+			'16.6.0'
308
+		);
309
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH, [], true, '4.17.11')
310
+			->setInlineDataCallback(
311
+				static function() {
312
+					wp_add_inline_script(
313
+						CoreAssetManager::JS_HANDLE_LODASH,
314
+						'window.lodash = _.noConflict();'
315
+					);
316
+				}
317
+			);
318
+	}
319
+
320
+
321
+	/**
322
+	 * Returns configuration data for the accounting-js library.
323
+	 * @since 4.9.71.p
324
+	 * @return array
325
+	 */
326
+	private function getAccountingSettings() {
327
+		return array(
328
+			'currency' => array(
329
+				'symbol'    => $this->currency_config->sign,
330
+				'format'    => array(
331
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
332
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
333
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
334
+				),
335
+				'decimal'   => $this->currency_config->dec_mrk,
336
+				'thousand'  => $this->currency_config->thsnds,
337
+				'precision' => $this->currency_config->dec_plc,
338
+			),
339
+			'number'   => array(
340
+				'precision' => $this->currency_config->dec_plc,
341
+				'thousand'  => $this->currency_config->thsnds,
342
+				'decimal'   => $this->currency_config->dec_mrk,
343
+			),
344
+		);
345
+	}
346
+
347
+
348
+	/**
349
+	 * Returns configuration data for the js Currency VO.
350
+	 * @since 4.9.71.p
351
+	 * @return array
352
+	 */
353
+	private function getCurrencySettings()
354
+	{
355
+		return array(
356
+			'code' => $this->currency_config->code,
357
+			'singularLabel' => $this->currency_config->name,
358
+			'pluralLabel' => $this->currency_config->plural,
359
+			'sign' => $this->currency_config->sign,
360
+			'signB4' => $this->currency_config->sign_b4,
361
+			'decimalPlaces' => $this->currency_config->dec_plc,
362
+			'decimalMark' => $this->currency_config->dec_mrk,
363
+			'thousandsSeparator' => $this->currency_config->thsnds,
364
+		);
365
+	}
366
+
367
+
368
+	/**
369
+	 * @throws DuplicateCollectionIdentifierException
370
+	 * @throws InvalidDataTypeException
371
+	 * @throws InvalidEntityException
372
+	 * @throws DomainException
373
+	 * @since 4.9.62.p
374
+	 */
375
+	private function loadCoreCss()
376
+	{
377
+		if ($this->template_config->enable_default_style && ! is_admin()) {
378
+			$this->addStylesheet(
379
+				CoreAssetManager::CSS_HANDLE_DEFAULT,
380
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
381
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
382
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
383
+				array('dashicons')
384
+			);
385
+			//Load custom style sheet if available
386
+			if ($this->template_config->custom_style_sheet !== null) {
387
+				$this->addStylesheet(
388
+					CoreAssetManager::CSS_HANDLE_CUSTOM,
389
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
390
+					array(CoreAssetManager::CSS_HANDLE_DEFAULT)
391
+				);
392
+			}
393
+		}
394
+	//     $this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, ['dashicons']);
395
+	//     $this->addCss(self::CSS_HANDLE_COMPONENTS, [self::CSS_HANDLE_CORE_CSS_DEFAULT]);
396
+	//     $this->addCss(self::CSS_HANDLE_HOCS);
397
+	}
398
+
399
+
400
+	/**
401
+	 * jQuery Validate for form validation
402
+	 *
403
+	 * @since 4.9.62.p
404
+	 * @throws DomainException
405
+	 * @throws DuplicateCollectionIdentifierException
406
+	 * @throws InvalidDataTypeException
407
+	 * @throws InvalidEntityException
408
+	 */
409
+	private function loadJqueryValidate()
410
+	{
411
+		$this->addJavascript(
412
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
413
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
414
+			array(CoreAssetManager::JS_HANDLE_JQUERY),
415
+			true,
416
+			'1.15.0'
417
+		);
418
+
419
+		$this->addJavascript(
420
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
421
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
422
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
423
+			true,
424
+			'1.15.0'
425
+		);
426
+	}
427
+
428
+
429
+	/**
430
+	 * accounting.js for performing client-side calculations
431
+	 *
432
+	 * @since 4.9.62.p
433
+	 * @throws DomainException
434
+	 * @throws DuplicateCollectionIdentifierException
435
+	 * @throws InvalidDataTypeException
436
+	 * @throws InvalidEntityException
437
+	 */
438
+	private function loadAccountingJs()
439
+	{
440
+		//accounting.js library
441
+		// @link http://josscrowcroft.github.io/accounting.js/
442
+		$this->addJavascript(
443
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
444
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
445
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE),
446
+			true,
447
+			'0.3.2'
448
+		);
449
+
450
+		$this->addJavascript(
451
+			CoreAssetManager::JS_HANDLE_ACCOUNTING,
452
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
453
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
454
+		)
455
+		->setInlineDataCallback(
456
+			function () {
457
+				 wp_localize_script(
458
+					 CoreAssetManager::JS_HANDLE_ACCOUNTING,
459
+					 'EE_ACCOUNTING_CFG',
460
+					 $this->getAccountingSettings()
461
+				 );
462
+			}
463
+		);
464
+	}
465
+
466
+
467
+	/**
468
+	 * registers assets for cleaning your ears
469
+	 *
470
+	 * @param JavascriptAsset $script
471
+	 */
472
+	public function loadQtipJs(JavascriptAsset $script)
473
+	{
474
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
475
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
476
+		if (
477
+			$script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
478
+			&& apply_filters('FHEE_load_qtip', false)
479
+		) {
480
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
481
+		}
482
+	}
483
+
484
+
485
+	/**
486
+	 * assets that are used in the WordPress admin
487
+	 *
488
+	 * @throws DuplicateCollectionIdentifierException
489
+	 * @throws InvalidDataTypeException
490
+	 * @throws InvalidEntityException
491
+	 * @throws DomainException
492
+	 * @since 4.9.62.p
493
+	 */
494
+	private function registerAdminAssets()
495
+	{
496
+		$this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation();
497
+		// note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle.
498
+		$this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE);
499
+	}
500 500
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -268,11 +268,11 @@  discard block
 block discarded – undo
268 268
 
269 269
         $this->addJavascript(
270 270
             CoreAssetManager::JS_HANDLE_CORE,
271
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
271
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
272 272
             array(CoreAssetManager::JS_HANDLE_JQUERY)
273 273
         )
274 274
         ->setInlineDataCallback(
275
-            static function () {
275
+            static function() {
276 276
                 wp_localize_script(
277 277
                     CoreAssetManager::JS_HANDLE_CORE,
278 278
                     CoreAssetManager::JS_HANDLE_I18N,
@@ -377,16 +377,16 @@  discard block
 block discarded – undo
377 377
         if ($this->template_config->enable_default_style && ! is_admin()) {
378 378
             $this->addStylesheet(
379 379
                 CoreAssetManager::CSS_HANDLE_DEFAULT,
380
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
380
+                is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
381 381
                     ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
382
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
382
+                    : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
383 383
                 array('dashicons')
384 384
             );
385 385
             //Load custom style sheet if available
386 386
             if ($this->template_config->custom_style_sheet !== null) {
387 387
                 $this->addStylesheet(
388 388
                     CoreAssetManager::CSS_HANDLE_CUSTOM,
389
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
389
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
390 390
                     array(CoreAssetManager::CSS_HANDLE_DEFAULT)
391 391
                 );
392 392
             }
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
     {
411 411
         $this->addJavascript(
412 412
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
413
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
413
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
414 414
             array(CoreAssetManager::JS_HANDLE_JQUERY),
415 415
             true,
416 416
             '1.15.0'
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 
419 419
         $this->addJavascript(
420 420
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
421
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
421
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
422 422
             array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
423 423
             true,
424 424
             '1.15.0'
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
         // @link http://josscrowcroft.github.io/accounting.js/
442 442
         $this->addJavascript(
443 443
             CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
444
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
444
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
445 445
             array(CoreAssetManager::JS_HANDLE_UNDERSCORE),
446 446
             true,
447 447
             '0.3.2'
@@ -449,11 +449,11 @@  discard block
 block discarded – undo
449 449
 
450 450
         $this->addJavascript(
451 451
             CoreAssetManager::JS_HANDLE_ACCOUNTING,
452
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
452
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
453 453
             array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
454 454
         )
455 455
         ->setInlineDataCallback(
456
-            function () {
456
+            function() {
457 457
                  wp_localize_script(
458 458
                      CoreAssetManager::JS_HANDLE_ACCOUNTING,
459 459
                      'EE_ACCOUNTING_CFG',
Please login to merge, or discard this patch.