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