@@ -20,125 +20,125 @@ |
||
20 | 20 | */ |
21 | 21 | class PueRequests extends Route |
22 | 22 | { |
23 | - /** |
|
24 | - * @var bool |
|
25 | - * @since 5.0.0.p |
|
26 | - */ |
|
27 | - private $load_pue = true; |
|
23 | + /** |
|
24 | + * @var bool |
|
25 | + * @since 5.0.0.p |
|
26 | + */ |
|
27 | + private $load_pue = true; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * returns true if the current request matches this route |
|
32 | - * |
|
33 | - * @return bool |
|
34 | - * @since 5.0.0.p |
|
35 | - */ |
|
36 | - public function matchesCurrentRequest(): bool |
|
37 | - { |
|
38 | - // route may match, but PUE loading is still conditional based on this filter |
|
39 | - $this->load_pue = apply_filters('FHEE__EE_System__brew_espresso__load_pue', true); |
|
40 | - return $this->request->isAdmin() || $this->request->isAjax() || $this->request->isActivation(); |
|
41 | - } |
|
30 | + /** |
|
31 | + * returns true if the current request matches this route |
|
32 | + * |
|
33 | + * @return bool |
|
34 | + * @since 5.0.0.p |
|
35 | + */ |
|
36 | + public function matchesCurrentRequest(): bool |
|
37 | + { |
|
38 | + // route may match, but PUE loading is still conditional based on this filter |
|
39 | + $this->load_pue = apply_filters('FHEE__EE_System__brew_espresso__load_pue', true); |
|
40 | + return $this->request->isAdmin() || $this->request->isAjax() || $this->request->isActivation(); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @since 5.0.0.p |
|
46 | - */ |
|
47 | - protected function registerDependencies() |
|
48 | - { |
|
49 | - if ($this->load_pue) { |
|
50 | - $this->dependency_map->registerDependencies( |
|
51 | - 'EventEspresso\caffeinated\core\services\licensing\LicenseService', |
|
52 | - [ |
|
53 | - 'EventEspresso\caffeinated\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
54 | - 'EventEspresso\caffeinated\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
55 | - ] |
|
56 | - ); |
|
57 | - $this->dependency_map->registerDependencies( |
|
58 | - 'EventEspresso\caffeinated\core\domain\services\pue\Stats', |
|
59 | - [ |
|
60 | - 'EventEspresso\caffeinated\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
61 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
62 | - 'EventEspresso\caffeinated\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
63 | - ] |
|
64 | - ); |
|
65 | - $this->dependency_map->registerDependencies( |
|
66 | - 'EventEspresso\caffeinated\core\domain\services\pue\Config', |
|
67 | - [ |
|
68 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
69 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
70 | - ] |
|
71 | - ); |
|
72 | - $this->dependency_map->registerDependencies( |
|
73 | - 'EventEspresso\caffeinated\core\domain\services\pue\StatsGatherer', |
|
74 | - [ |
|
75 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
76 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
77 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
78 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
79 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
80 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
81 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
82 | - ] |
|
83 | - ); |
|
84 | - $this->dependency_map->registerDependencies( |
|
85 | - 'EventEspresso\caffeinated\core\services\licensing\UserExperienceForm', |
|
86 | - [ |
|
87 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
88 | - 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
89 | - ] |
|
90 | - ); |
|
91 | - } |
|
92 | - } |
|
44 | + /** |
|
45 | + * @since 5.0.0.p |
|
46 | + */ |
|
47 | + protected function registerDependencies() |
|
48 | + { |
|
49 | + if ($this->load_pue) { |
|
50 | + $this->dependency_map->registerDependencies( |
|
51 | + 'EventEspresso\caffeinated\core\services\licensing\LicenseService', |
|
52 | + [ |
|
53 | + 'EventEspresso\caffeinated\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
54 | + 'EventEspresso\caffeinated\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
55 | + ] |
|
56 | + ); |
|
57 | + $this->dependency_map->registerDependencies( |
|
58 | + 'EventEspresso\caffeinated\core\domain\services\pue\Stats', |
|
59 | + [ |
|
60 | + 'EventEspresso\caffeinated\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
61 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
62 | + 'EventEspresso\caffeinated\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
63 | + ] |
|
64 | + ); |
|
65 | + $this->dependency_map->registerDependencies( |
|
66 | + 'EventEspresso\caffeinated\core\domain\services\pue\Config', |
|
67 | + [ |
|
68 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
69 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
70 | + ] |
|
71 | + ); |
|
72 | + $this->dependency_map->registerDependencies( |
|
73 | + 'EventEspresso\caffeinated\core\domain\services\pue\StatsGatherer', |
|
74 | + [ |
|
75 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
76 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
77 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
78 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
79 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
80 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
81 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
82 | + ] |
|
83 | + ); |
|
84 | + $this->dependency_map->registerDependencies( |
|
85 | + 'EventEspresso\caffeinated\core\services\licensing\UserExperienceForm', |
|
86 | + [ |
|
87 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
88 | + 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
89 | + ] |
|
90 | + ); |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | 94 | |
95 | - /** |
|
96 | - * implements logic required to run during request |
|
97 | - * |
|
98 | - * @return bool |
|
99 | - * @since 5.0.0.p |
|
100 | - */ |
|
101 | - protected function requestHandler(): bool |
|
102 | - { |
|
103 | - add_filter( |
|
104 | - 'FHEE__EE_Register_Addon__register', |
|
105 | - [RegisterAddonPUE::class, 'registerPUE'], |
|
106 | - 10, |
|
107 | - 4 |
|
108 | - ); |
|
109 | - add_action( |
|
110 | - 'AHEE__EE_Register_Addon___load_and_init_addon_class', |
|
111 | - [RegisterAddonPUE::class, 'setAddonPueSlug'], |
|
112 | - 10, |
|
113 | - 2 |
|
114 | - ); |
|
115 | - if ($this->load_pue) { |
|
116 | - add_action('AHEE__EE_System__brew_espresso__complete', [$this, 'loadLicenseService']); |
|
117 | - add_filter( |
|
118 | - 'FHEE__EventEspresso_admin_pages_general_settings_OrganizationSettings__generate__form', |
|
119 | - [$this, 'loadUserExperienceForm'] |
|
120 | - ); |
|
121 | - } |
|
95 | + /** |
|
96 | + * implements logic required to run during request |
|
97 | + * |
|
98 | + * @return bool |
|
99 | + * @since 5.0.0.p |
|
100 | + */ |
|
101 | + protected function requestHandler(): bool |
|
102 | + { |
|
103 | + add_filter( |
|
104 | + 'FHEE__EE_Register_Addon__register', |
|
105 | + [RegisterAddonPUE::class, 'registerPUE'], |
|
106 | + 10, |
|
107 | + 4 |
|
108 | + ); |
|
109 | + add_action( |
|
110 | + 'AHEE__EE_Register_Addon___load_and_init_addon_class', |
|
111 | + [RegisterAddonPUE::class, 'setAddonPueSlug'], |
|
112 | + 10, |
|
113 | + 2 |
|
114 | + ); |
|
115 | + if ($this->load_pue) { |
|
116 | + add_action('AHEE__EE_System__brew_espresso__complete', [$this, 'loadLicenseService']); |
|
117 | + add_filter( |
|
118 | + 'FHEE__EventEspresso_admin_pages_general_settings_OrganizationSettings__generate__form', |
|
119 | + [$this, 'loadUserExperienceForm'] |
|
120 | + ); |
|
121 | + } |
|
122 | 122 | |
123 | - return true; |
|
124 | - } |
|
123 | + return true; |
|
124 | + } |
|
125 | 125 | |
126 | 126 | |
127 | - public function loadLicenseService() |
|
128 | - { |
|
129 | - /** @var LicenseService $license_service */ |
|
130 | - $license_service = $this->loader->getShared(LicenseService::class); |
|
131 | - $license_service->loadPueClient(); |
|
132 | - } |
|
127 | + public function loadLicenseService() |
|
128 | + { |
|
129 | + /** @var LicenseService $license_service */ |
|
130 | + $license_service = $this->loader->getShared(LicenseService::class); |
|
131 | + $license_service->loadPueClient(); |
|
132 | + } |
|
133 | 133 | |
134 | 134 | |
135 | - /** |
|
136 | - * @throws EE_Error |
|
137 | - */ |
|
138 | - public function loadUserExperienceForm(EE_Form_Section_Proper $org_settings_form): EE_Form_Section_Proper |
|
139 | - { |
|
140 | - /** @var UserExperienceForm $uxip_form */ |
|
141 | - $uxip_form = $this->loader->getShared(UserExperienceForm::class); |
|
142 | - return $uxip_form->uxipFormSections($org_settings_form); |
|
143 | - } |
|
135 | + /** |
|
136 | + * @throws EE_Error |
|
137 | + */ |
|
138 | + public function loadUserExperienceForm(EE_Form_Section_Proper $org_settings_form): EE_Form_Section_Proper |
|
139 | + { |
|
140 | + /** @var UserExperienceForm $uxip_form */ |
|
141 | + $uxip_form = $this->loader->getShared(UserExperienceForm::class); |
|
142 | + return $uxip_form->uxipFormSections($org_settings_form); |
|
143 | + } |
|
144 | 144 | } |
@@ -18,2963 +18,2963 @@ |
||
18 | 18 | */ |
19 | 19 | class Events_Admin_Page extends EE_Admin_Page_CPT |
20 | 20 | { |
21 | - /** |
|
22 | - * This will hold the event object for event_details screen. |
|
21 | + /** |
|
22 | + * This will hold the event object for event_details screen. |
|
23 | + * |
|
24 | + * @var EE_Event $_event |
|
25 | + */ |
|
26 | + protected $_event; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * This will hold the category object for category_details screen. |
|
31 | + * |
|
32 | + * @var stdClass $_category |
|
33 | + */ |
|
34 | + protected $_category; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * This will hold the event model instance |
|
39 | + * |
|
40 | + * @var EEM_Event $_event_model |
|
41 | + */ |
|
42 | + protected $_event_model; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @var EE_Event |
|
47 | + */ |
|
48 | + protected $_cpt_model_obj = null; |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @var NodeGroupDao |
|
53 | + */ |
|
54 | + protected $model_obj_node_group_persister; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var AdvancedEditorAdminFormSection |
|
58 | + */ |
|
59 | + protected $advanced_editor_admin_form; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Initialize page props for this admin page group. |
|
64 | + */ |
|
65 | + protected function _init_page_props() |
|
66 | + { |
|
67 | + $this->page_slug = EVENTS_PG_SLUG; |
|
68 | + $this->page_label = EVENTS_LABEL; |
|
69 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
70 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
71 | + $this->_cpt_model_names = [ |
|
72 | + 'create_new' => 'EEM_Event', |
|
73 | + 'edit' => 'EEM_Event', |
|
74 | + ]; |
|
75 | + $this->_cpt_edit_routes = [ |
|
76 | + 'espresso_events' => 'edit', |
|
77 | + ]; |
|
78 | + add_action( |
|
79 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
80 | + [$this, 'verify_event_edit'], |
|
81 | + 10, |
|
82 | + 2 |
|
83 | + ); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * Sets the ajax hooks used for this admin page group. |
|
89 | + */ |
|
90 | + protected function _ajax_hooks() |
|
91 | + { |
|
92 | + add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Sets the page properties for this admin page group. |
|
98 | + */ |
|
99 | + protected function _define_page_props() |
|
100 | + { |
|
101 | + $event_id = $this->request->getRequestParam('post', 0, DataType::INT); |
|
102 | + if ($event_id) { |
|
103 | + $event_post = get_post($event_id); |
|
104 | + } |
|
105 | + |
|
106 | + $this->_admin_page_title = EVENTS_LABEL; |
|
107 | + $this->_labels = [ |
|
108 | + 'buttons' => [ |
|
109 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
110 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
111 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
112 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
113 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
114 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
115 | + ], |
|
116 | + 'editor_title' => [ |
|
117 | + 'espresso_events' => isset($event_post) && $event_post instanceof WP_Post |
|
118 | + ? $event_post->post_title |
|
119 | + : esc_html__('Edit Event', 'event_espresso'), |
|
120 | + ], |
|
121 | + 'publishbox' => [ |
|
122 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
123 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
124 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
125 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
126 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
127 | + ], |
|
128 | + ]; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * Sets the page routes property for this admin page group. |
|
134 | + */ |
|
135 | + protected function _set_page_routes() |
|
136 | + { |
|
137 | + // load formatter helper |
|
138 | + // load field generator helper |
|
139 | + // is there a evt_id in the request? |
|
140 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT); |
|
141 | + $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, DataType::INT); |
|
142 | + |
|
143 | + $this->_page_routes = [ |
|
144 | + 'default' => [ |
|
145 | + 'func' => [$this, '_events_overview_list_table'], |
|
146 | + 'capability' => 'ee_read_events', |
|
147 | + ], |
|
148 | + 'create_new' => [ |
|
149 | + 'func' => [$this, '_create_new_cpt_item'], |
|
150 | + 'capability' => 'ee_edit_events', |
|
151 | + ], |
|
152 | + 'edit' => [ |
|
153 | + 'func' => [$this, '_edit_cpt_item'], |
|
154 | + 'capability' => 'ee_edit_event', |
|
155 | + 'obj_id' => $EVT_ID, |
|
156 | + ], |
|
157 | + 'copy_event' => [ |
|
158 | + 'func' => [$this, '_copy_events'], |
|
159 | + 'capability' => 'ee_edit_event', |
|
160 | + 'obj_id' => $EVT_ID, |
|
161 | + 'noheader' => true, |
|
162 | + ], |
|
163 | + 'trash_event' => [ |
|
164 | + 'func' => [$this, '_trash_or_restore_event'], |
|
165 | + 'args' => ['event_status' => 'trash'], |
|
166 | + 'capability' => 'ee_delete_event', |
|
167 | + 'obj_id' => $EVT_ID, |
|
168 | + 'noheader' => true, |
|
169 | + ], |
|
170 | + 'trash_events' => [ |
|
171 | + 'func' => [$this, '_trash_or_restore_events'], |
|
172 | + 'args' => ['event_status' => 'trash'], |
|
173 | + 'capability' => 'ee_delete_events', |
|
174 | + 'noheader' => true, |
|
175 | + ], |
|
176 | + 'restore_event' => [ |
|
177 | + 'func' => [$this, '_trash_or_restore_event'], |
|
178 | + 'args' => ['event_status' => 'draft'], |
|
179 | + 'capability' => 'ee_delete_event', |
|
180 | + 'obj_id' => $EVT_ID, |
|
181 | + 'noheader' => true, |
|
182 | + ], |
|
183 | + 'restore_events' => [ |
|
184 | + 'func' => [$this, '_trash_or_restore_events'], |
|
185 | + 'args' => ['event_status' => 'draft'], |
|
186 | + 'capability' => 'ee_delete_events', |
|
187 | + 'noheader' => true, |
|
188 | + ], |
|
189 | + 'delete_event' => [ |
|
190 | + 'func' => [$this, '_delete_event'], |
|
191 | + 'capability' => 'ee_delete_event', |
|
192 | + 'obj_id' => $EVT_ID, |
|
193 | + 'noheader' => true, |
|
194 | + ], |
|
195 | + 'delete_events' => [ |
|
196 | + 'func' => [$this, '_delete_events'], |
|
197 | + 'capability' => 'ee_delete_events', |
|
198 | + 'noheader' => true, |
|
199 | + ], |
|
200 | + 'view_report' => [ |
|
201 | + 'func' => [$this, '_view_report'], |
|
202 | + 'capability' => 'ee_edit_events', |
|
203 | + ], |
|
204 | + 'default_event_settings' => [ |
|
205 | + 'func' => [$this, '_default_event_settings'], |
|
206 | + 'capability' => 'manage_options', |
|
207 | + ], |
|
208 | + 'update_default_event_settings' => [ |
|
209 | + 'func' => [$this, '_update_default_event_settings'], |
|
210 | + 'capability' => 'manage_options', |
|
211 | + 'noheader' => true, |
|
212 | + ], |
|
213 | + 'template_settings' => [ |
|
214 | + 'func' => [$this, '_template_settings'], |
|
215 | + 'capability' => 'manage_options', |
|
216 | + ], |
|
217 | + // event category tab related |
|
218 | + 'add_category' => [ |
|
219 | + 'func' => [$this, '_category_details'], |
|
220 | + 'capability' => 'ee_edit_event_category', |
|
221 | + 'args' => ['view' => 'add'], |
|
222 | + ], |
|
223 | + 'edit_category' => [ |
|
224 | + 'func' => [$this, '_category_details'], |
|
225 | + 'capability' => 'ee_edit_event_category', |
|
226 | + 'args' => ['view' => 'edit'], |
|
227 | + ], |
|
228 | + 'delete_categories' => [ |
|
229 | + 'func' => [$this, '_delete_categories'], |
|
230 | + 'capability' => 'ee_delete_event_category', |
|
231 | + 'noheader' => true, |
|
232 | + ], |
|
233 | + 'delete_category' => [ |
|
234 | + 'func' => [$this, '_delete_categories'], |
|
235 | + 'capability' => 'ee_delete_event_category', |
|
236 | + 'noheader' => true, |
|
237 | + ], |
|
238 | + 'insert_category' => [ |
|
239 | + 'func' => [$this, '_insert_or_update_category'], |
|
240 | + 'args' => ['new_category' => true], |
|
241 | + 'capability' => 'ee_edit_event_category', |
|
242 | + 'noheader' => true, |
|
243 | + ], |
|
244 | + 'update_category' => [ |
|
245 | + 'func' => [$this, '_insert_or_update_category'], |
|
246 | + 'args' => ['new_category' => false], |
|
247 | + 'capability' => 'ee_edit_event_category', |
|
248 | + 'noheader' => true, |
|
249 | + ], |
|
250 | + 'category_list' => [ |
|
251 | + 'func' => [$this, '_category_list_table'], |
|
252 | + 'capability' => 'ee_manage_event_categories', |
|
253 | + ], |
|
254 | + 'preview_deletion' => [ |
|
255 | + 'func' => [$this, 'previewDeletion'], |
|
256 | + 'capability' => 'ee_delete_events', |
|
257 | + ], |
|
258 | + 'confirm_deletion' => [ |
|
259 | + 'func' => [$this, 'confirmDeletion'], |
|
260 | + 'capability' => 'ee_delete_events', |
|
261 | + 'noheader' => true, |
|
262 | + ], |
|
263 | + ]; |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * Set the _page_config property for this admin page group. |
|
269 | + */ |
|
270 | + protected function _set_page_config() |
|
271 | + { |
|
272 | + $post_id = $this->request->getRequestParam('post', 0, DataType::INT); |
|
273 | + $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
274 | + $this->_page_config = [ |
|
275 | + 'default' => [ |
|
276 | + 'nav' => [ |
|
277 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
278 | + 'icon' => 'dashicons-list-view', |
|
279 | + 'order' => 10, |
|
280 | + ], |
|
281 | + 'list_table' => 'Events_Admin_List_Table', |
|
282 | + 'help_tabs' => [ |
|
283 | + 'events_overview_help_tab' => [ |
|
284 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
285 | + 'filename' => 'events_overview', |
|
286 | + ], |
|
287 | + 'events_overview_table_column_headings_help_tab' => [ |
|
288 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
289 | + 'filename' => 'events_overview_table_column_headings', |
|
290 | + ], |
|
291 | + 'events_overview_filters_help_tab' => [ |
|
292 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
293 | + 'filename' => 'events_overview_filters', |
|
294 | + ], |
|
295 | + 'events_overview_view_help_tab' => [ |
|
296 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
297 | + 'filename' => 'events_overview_views', |
|
298 | + ], |
|
299 | + 'events_overview_other_help_tab' => [ |
|
300 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
301 | + 'filename' => 'events_overview_other', |
|
302 | + ], |
|
303 | + ], |
|
304 | + 'require_nonce' => false, |
|
305 | + ], |
|
306 | + 'create_new' => [ |
|
307 | + 'nav' => [ |
|
308 | + 'label' => esc_html__('Add New Event', 'event_espresso'), |
|
309 | + 'icon' => 'dashicons-plus-alt', |
|
310 | + 'order' => 15, |
|
311 | + 'persistent' => false, |
|
312 | + ], |
|
313 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
314 | + 'help_tabs' => [ |
|
315 | + 'event_editor_help_tab' => [ |
|
316 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
317 | + 'filename' => 'event_editor', |
|
318 | + ], |
|
319 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
320 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
321 | + 'filename' => 'event_editor_title_richtexteditor', |
|
322 | + ], |
|
323 | + 'event_editor_venue_details_help_tab' => [ |
|
324 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
325 | + 'filename' => 'event_editor_venue_details', |
|
326 | + ], |
|
327 | + 'event_editor_event_datetimes_help_tab' => [ |
|
328 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
329 | + 'filename' => 'event_editor_event_datetimes', |
|
330 | + ], |
|
331 | + 'event_editor_event_tickets_help_tab' => [ |
|
332 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
333 | + 'filename' => 'event_editor_event_tickets', |
|
334 | + ], |
|
335 | + 'event_editor_event_registration_options_help_tab' => [ |
|
336 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
337 | + 'filename' => 'event_editor_event_registration_options', |
|
338 | + ], |
|
339 | + 'event_editor_tags_categories_help_tab' => [ |
|
340 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
341 | + 'filename' => 'event_editor_tags_categories', |
|
342 | + ], |
|
343 | + 'event_editor_questions_registrants_help_tab' => [ |
|
344 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
345 | + 'filename' => 'event_editor_questions_registrants', |
|
346 | + ], |
|
347 | + 'event_editor_save_new_event_help_tab' => [ |
|
348 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
349 | + 'filename' => 'event_editor_save_new_event', |
|
350 | + ], |
|
351 | + 'event_editor_other_help_tab' => [ |
|
352 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
353 | + 'filename' => 'event_editor_other', |
|
354 | + ], |
|
355 | + ], |
|
356 | + 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
357 | + 'require_nonce' => false, |
|
358 | + ], |
|
359 | + 'edit' => [ |
|
360 | + 'nav' => [ |
|
361 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
362 | + 'icon' => 'dashicons-edit', |
|
363 | + 'order' => 15, |
|
364 | + 'persistent' => false, |
|
365 | + 'url' => $post_id |
|
366 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
367 | + ['post' => $post_id, 'action' => 'edit'], |
|
368 | + $this->_current_page_view_url |
|
369 | + ) |
|
370 | + : $this->_admin_base_url, |
|
371 | + ], |
|
372 | + 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
373 | + 'help_tabs' => [ |
|
374 | + 'event_editor_help_tab' => [ |
|
375 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
376 | + 'filename' => 'event_editor', |
|
377 | + ], |
|
378 | + 'event_editor_title_richtexteditor_help_tab' => [ |
|
379 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
380 | + 'filename' => 'event_editor_title_richtexteditor', |
|
381 | + ], |
|
382 | + 'event_editor_venue_details_help_tab' => [ |
|
383 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
384 | + 'filename' => 'event_editor_venue_details', |
|
385 | + ], |
|
386 | + 'event_editor_event_datetimes_help_tab' => [ |
|
387 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
388 | + 'filename' => 'event_editor_event_datetimes', |
|
389 | + ], |
|
390 | + 'event_editor_event_tickets_help_tab' => [ |
|
391 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
392 | + 'filename' => 'event_editor_event_tickets', |
|
393 | + ], |
|
394 | + 'event_editor_event_registration_options_help_tab' => [ |
|
395 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
396 | + 'filename' => 'event_editor_event_registration_options', |
|
397 | + ], |
|
398 | + 'event_editor_tags_categories_help_tab' => [ |
|
399 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
400 | + 'filename' => 'event_editor_tags_categories', |
|
401 | + ], |
|
402 | + 'event_editor_questions_registrants_help_tab' => [ |
|
403 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
404 | + 'filename' => 'event_editor_questions_registrants', |
|
405 | + ], |
|
406 | + 'event_editor_save_new_event_help_tab' => [ |
|
407 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
408 | + 'filename' => 'event_editor_save_new_event', |
|
409 | + ], |
|
410 | + 'event_editor_other_help_tab' => [ |
|
411 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
412 | + 'filename' => 'event_editor_other', |
|
413 | + ], |
|
414 | + ], |
|
415 | + 'require_nonce' => false, |
|
416 | + ], |
|
417 | + 'default_event_settings' => [ |
|
418 | + 'nav' => [ |
|
419 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
420 | + 'icon' => 'dashicons-admin-generic', |
|
421 | + 'order' => 40, |
|
422 | + ], |
|
423 | + 'metaboxes' => array_merge(['_publish_post_box'], $this->_default_espresso_metaboxes), |
|
424 | + 'labels' => [ |
|
425 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
426 | + ], |
|
427 | + 'help_tabs' => [ |
|
428 | + 'default_settings_help_tab' => [ |
|
429 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
430 | + 'filename' => 'events_default_settings', |
|
431 | + ], |
|
432 | + 'default_settings_status_help_tab' => [ |
|
433 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
434 | + 'filename' => 'events_default_settings_status', |
|
435 | + ], |
|
436 | + 'default_maximum_tickets_help_tab' => [ |
|
437 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
438 | + 'filename' => 'events_default_settings_max_tickets', |
|
439 | + ], |
|
440 | + ], |
|
441 | + 'require_nonce' => false, |
|
442 | + ], |
|
443 | + // template settings |
|
444 | + 'template_settings' => [ |
|
445 | + 'nav' => [ |
|
446 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
447 | + 'icon' => 'dashicons-layout', |
|
448 | + 'order' => 30, |
|
449 | + ], |
|
450 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
451 | + 'help_tabs' => [ |
|
452 | + 'general_settings_templates_help_tab' => [ |
|
453 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
454 | + 'filename' => 'general_settings_templates', |
|
455 | + ], |
|
456 | + ], |
|
457 | + 'require_nonce' => false, |
|
458 | + ], |
|
459 | + // event category stuff |
|
460 | + 'add_category' => [ |
|
461 | + 'nav' => [ |
|
462 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
463 | + 'icon' => 'dashicons-plus-alt', |
|
464 | + 'order' => 25, |
|
465 | + 'persistent' => false, |
|
466 | + ], |
|
467 | + 'help_tabs' => [ |
|
468 | + 'add_category_help_tab' => [ |
|
469 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
470 | + 'filename' => 'events_add_category', |
|
471 | + ], |
|
472 | + ], |
|
473 | + 'metaboxes' => ['_publish_post_box'], |
|
474 | + 'require_nonce' => false, |
|
475 | + ], |
|
476 | + 'edit_category' => [ |
|
477 | + 'nav' => [ |
|
478 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
479 | + 'icon' => 'dashicons-edit', |
|
480 | + 'order' => 25, |
|
481 | + 'persistent' => false, |
|
482 | + 'url' => $EVT_CAT_ID |
|
483 | + ? add_query_arg( |
|
484 | + ['EVT_CAT_ID' => $EVT_CAT_ID], |
|
485 | + $this->_current_page_view_url |
|
486 | + ) |
|
487 | + : $this->_admin_base_url, |
|
488 | + ], |
|
489 | + 'help_tabs' => [ |
|
490 | + 'edit_category_help_tab' => [ |
|
491 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
492 | + 'filename' => 'events_edit_category', |
|
493 | + ], |
|
494 | + ], |
|
495 | + 'metaboxes' => ['_publish_post_box'], |
|
496 | + 'require_nonce' => false, |
|
497 | + ], |
|
498 | + 'category_list' => [ |
|
499 | + 'nav' => [ |
|
500 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
501 | + 'icon' => 'dashicons-networking', |
|
502 | + 'order' => 20, |
|
503 | + ], |
|
504 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
505 | + 'help_tabs' => [ |
|
506 | + 'events_categories_help_tab' => [ |
|
507 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
508 | + 'filename' => 'events_categories', |
|
509 | + ], |
|
510 | + 'events_categories_table_column_headings_help_tab' => [ |
|
511 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
512 | + 'filename' => 'events_categories_table_column_headings', |
|
513 | + ], |
|
514 | + 'events_categories_view_help_tab' => [ |
|
515 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
516 | + 'filename' => 'events_categories_views', |
|
517 | + ], |
|
518 | + 'events_categories_other_help_tab' => [ |
|
519 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
520 | + 'filename' => 'events_categories_other', |
|
521 | + ], |
|
522 | + ], |
|
523 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
524 | + 'require_nonce' => false, |
|
525 | + ], |
|
526 | + 'preview_deletion' => [ |
|
527 | + 'nav' => [ |
|
528 | + 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
529 | + 'icon' => 'dashicons-remove', |
|
530 | + 'order' => 15, |
|
531 | + 'persistent' => false, |
|
532 | + 'url' => '', |
|
533 | + ], |
|
534 | + 'require_nonce' => false, |
|
535 | + ], |
|
536 | + ]; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * Used to register any global screen options if necessary for every route in this admin page group. |
|
542 | + */ |
|
543 | + protected function _add_screen_options() |
|
544 | + { |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * Implementing the screen options for the 'default' route. |
|
550 | + * |
|
551 | + * @throws InvalidArgumentException |
|
552 | + * @throws InvalidDataTypeException |
|
553 | + * @throws InvalidInterfaceException |
|
554 | + */ |
|
555 | + protected function _add_screen_options_default() |
|
556 | + { |
|
557 | + $this->_per_page_screen_option(); |
|
558 | + } |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * Implementing screen options for the category list route. |
|
563 | + * |
|
564 | + * @throws InvalidArgumentException |
|
565 | + * @throws InvalidDataTypeException |
|
566 | + * @throws InvalidInterfaceException |
|
567 | + */ |
|
568 | + protected function _add_screen_options_category_list() |
|
569 | + { |
|
570 | + $page_title = $this->_admin_page_title; |
|
571 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
572 | + $this->_per_page_screen_option(); |
|
573 | + $this->_admin_page_title = $page_title; |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * Used to register any global feature pointers for the admin page group. |
|
579 | + */ |
|
580 | + protected function _add_feature_pointers() |
|
581 | + { |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
587 | + */ |
|
588 | + public function load_scripts_styles() |
|
589 | + { |
|
590 | + wp_register_style( |
|
591 | + 'events-admin-css', |
|
592 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
593 | + [], |
|
594 | + EVENT_ESPRESSO_VERSION |
|
595 | + ); |
|
596 | + wp_register_style( |
|
597 | + 'ee-cat-admin', |
|
598 | + EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
599 | + [], |
|
600 | + EVENT_ESPRESSO_VERSION |
|
601 | + ); |
|
602 | + wp_enqueue_style('events-admin-css'); |
|
603 | + wp_enqueue_style('ee-cat-admin'); |
|
604 | + // scripts |
|
605 | + wp_register_script( |
|
606 | + 'event_editor_js', |
|
607 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
608 | + ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
609 | + EVENT_ESPRESSO_VERSION, |
|
610 | + true |
|
611 | + ); |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * Enqueuing scripts and styles specific to this view |
|
617 | + */ |
|
618 | + public function load_scripts_styles_create_new() |
|
619 | + { |
|
620 | + $this->load_scripts_styles_edit(); |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * Enqueuing scripts and styles specific to this view |
|
626 | + */ |
|
627 | + public function load_scripts_styles_edit() |
|
628 | + { |
|
629 | + // styles |
|
630 | + wp_enqueue_style('espresso-ui-theme'); |
|
631 | + wp_register_style( |
|
632 | + 'event-editor-css', |
|
633 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
634 | + ['ee-admin-css'], |
|
635 | + EVENT_ESPRESSO_VERSION |
|
636 | + ); |
|
637 | + wp_enqueue_style('event-editor-css'); |
|
638 | + // scripts |
|
639 | + if (! $this->admin_config->useAdvancedEditor()) { |
|
640 | + wp_register_script( |
|
641 | + 'event-datetime-metabox', |
|
642 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
643 | + ['event_editor_js', 'ee-datepicker'], |
|
644 | + EVENT_ESPRESSO_VERSION |
|
645 | + ); |
|
646 | + wp_enqueue_script('event-datetime-metabox'); |
|
647 | + } |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * Populating the _views property for the category list table view. |
|
653 | + */ |
|
654 | + protected function _set_list_table_views_category_list() |
|
655 | + { |
|
656 | + $this->_views = [ |
|
657 | + 'all' => [ |
|
658 | + 'slug' => 'all', |
|
659 | + 'label' => esc_html__('All', 'event_espresso'), |
|
660 | + 'count' => 0, |
|
661 | + 'bulk_action' => [ |
|
662 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
663 | + ], |
|
664 | + ], |
|
665 | + ]; |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
671 | + */ |
|
672 | + public function admin_init() |
|
673 | + { |
|
674 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
675 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
676 | + 'event_espresso' |
|
677 | + ); |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + /** |
|
682 | + * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
683 | + * group. |
|
684 | + */ |
|
685 | + public function admin_notices() |
|
686 | + { |
|
687 | + } |
|
688 | + |
|
689 | + |
|
690 | + /** |
|
691 | + * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
692 | + * this admin page group. |
|
693 | + */ |
|
694 | + public function admin_footer_scripts() |
|
695 | + { |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
701 | + * warning (via EE_Error::add_error()); |
|
702 | + * |
|
703 | + * @param EE_Event|null $event Event object |
|
704 | + * @param string $req_type |
|
705 | + * @return void |
|
706 | + * @throws EE_Error |
|
707 | + * @throws ReflectionException |
|
708 | + */ |
|
709 | + public function verify_event_edit(?EE_Base_Class $event = null, string $req_type = '') |
|
710 | + { |
|
711 | + // don't need to do this when processing |
|
712 | + if (! empty($req_type)) { |
|
713 | + return; |
|
714 | + } |
|
715 | + // no event? |
|
716 | + if (! $event instanceof EE_Event) { |
|
717 | + $event = $this->_cpt_model_obj; |
|
718 | + } |
|
719 | + // STILL no event? |
|
720 | + if (! $event instanceof EE_Event) { |
|
721 | + return; |
|
722 | + } |
|
723 | + // don't need to keep calling this |
|
724 | + remove_action( |
|
725 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
726 | + [$this, 'verify_event_edit'] |
|
727 | + ); |
|
728 | + $orig_status = $event->status(); |
|
729 | + // first check if event is active. |
|
730 | + if ( |
|
731 | + $orig_status === EEM_Event::cancelled |
|
732 | + || $orig_status === EEM_Event::postponed |
|
733 | + || $event->is_expired() |
|
734 | + || $event->is_inactive() |
|
735 | + ) { |
|
736 | + return; |
|
737 | + } |
|
738 | + // made it here so it IS active... next check that any of the tickets are sold. |
|
739 | + if ($event->is_sold_out(true)) { |
|
740 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
741 | + EE_Error::add_attention( |
|
742 | + sprintf( |
|
743 | + esc_html__( |
|
744 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
745 | + 'event_espresso' |
|
746 | + ), |
|
747 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
748 | + ) |
|
749 | + ); |
|
750 | + } |
|
751 | + return; |
|
752 | + } |
|
753 | + if ($orig_status === EEM_Event::sold_out) { |
|
754 | + EE_Error::add_attention( |
|
755 | + sprintf( |
|
756 | + esc_html__( |
|
757 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
758 | + 'event_espresso' |
|
759 | + ), |
|
760 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
761 | + ) |
|
762 | + ); |
|
763 | + } |
|
764 | + // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
765 | + if (! $event->tickets_on_sale()) { |
|
766 | + return; |
|
767 | + } |
|
768 | + // made it here so show warning |
|
769 | + $this->_edit_event_warning(); |
|
770 | + } |
|
771 | + |
|
772 | + |
|
773 | + /** |
|
774 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
775 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
776 | + * |
|
777 | + * @access protected |
|
778 | + * @return void |
|
779 | + */ |
|
780 | + protected function _edit_event_warning() |
|
781 | + { |
|
782 | + // we don't want to add warnings during these requests |
|
783 | + if ($this->request->getRequestParam('action') === 'editpost') { |
|
784 | + return; |
|
785 | + } |
|
786 | + EE_Error::add_attention( |
|
787 | + sprintf( |
|
788 | + esc_html__( |
|
789 | + 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
790 | + 'event_espresso' |
|
791 | + ), |
|
792 | + '<a class="espresso-help-tab-lnk ee-help-tab-link">', |
|
793 | + '</a>' |
|
794 | + ) |
|
795 | + ); |
|
796 | + } |
|
797 | + |
|
798 | + |
|
799 | + /** |
|
800 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
801 | + * Otherwise, do the normal logic |
|
802 | + * |
|
803 | + * @return void |
|
804 | + * @throws EE_Error |
|
805 | + * @throws InvalidArgumentException |
|
806 | + * @throws InvalidDataTypeException |
|
807 | + * @throws InvalidInterfaceException |
|
808 | + * @throws ReflectionException |
|
809 | + */ |
|
810 | + protected function _create_new_cpt_item() |
|
811 | + { |
|
812 | + $has_timezone_string = get_option('timezone_string'); |
|
813 | + // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
814 | + if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
815 | + EE_Error::add_attention( |
|
816 | + sprintf( |
|
817 | + esc_html__( |
|
818 | + 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
819 | + 'event_espresso' |
|
820 | + ), |
|
821 | + '<br>', |
|
822 | + '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
823 | + . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
824 | + . '</select>', |
|
825 | + '<button class="button button--secondary timezone-submit">', |
|
826 | + '</button><span class="spinner"></span>' |
|
827 | + ), |
|
828 | + __FILE__, |
|
829 | + __FUNCTION__, |
|
830 | + __LINE__ |
|
831 | + ); |
|
832 | + } |
|
833 | + parent::_create_new_cpt_item(); |
|
834 | + } |
|
835 | + |
|
836 | + |
|
837 | + /** |
|
838 | + * Sets the _views property for the default route in this admin page group. |
|
839 | + */ |
|
840 | + protected function _set_list_table_views_default() |
|
841 | + { |
|
842 | + $this->_views = [ |
|
843 | + 'all' => [ |
|
844 | + 'slug' => 'all', |
|
845 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
846 | + 'count' => 0, |
|
847 | + 'bulk_action' => [ |
|
848 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
849 | + ], |
|
850 | + ], |
|
851 | + 'draft' => [ |
|
852 | + 'slug' => 'draft', |
|
853 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
854 | + 'count' => 0, |
|
855 | + 'bulk_action' => [ |
|
856 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
857 | + ], |
|
858 | + ], |
|
859 | + ]; |
|
860 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
861 | + $this->_views['trash'] = [ |
|
862 | + 'slug' => 'trash', |
|
863 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
864 | + 'count' => 0, |
|
865 | + 'bulk_action' => [ |
|
866 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
867 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
868 | + ], |
|
869 | + ]; |
|
870 | + } |
|
871 | + } |
|
872 | + |
|
873 | + |
|
874 | + /** |
|
875 | + * Provides the legend item array for the default list table view. |
|
876 | + * |
|
877 | + * @return array |
|
878 | + * @throws EE_Error |
|
879 | + * @throws EE_Error |
|
880 | + */ |
|
881 | + protected function _event_legend_items(): array |
|
882 | + { |
|
883 | + $items = [ |
|
884 | + 'view_details' => [ |
|
885 | + 'class' => 'dashicons dashicons-visibility', |
|
886 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
887 | + ], |
|
888 | + 'edit_event' => [ |
|
889 | + 'class' => 'dashicons dashicons-calendar-alt', |
|
890 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
891 | + ], |
|
892 | + 'view_attendees' => [ |
|
893 | + 'class' => 'dashicons dashicons-groups', |
|
894 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
895 | + ], |
|
896 | + ]; |
|
897 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
898 | + $statuses = [ |
|
899 | + 'sold_out_status' => [ |
|
900 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out, |
|
901 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
902 | + ], |
|
903 | + 'active_status' => [ |
|
904 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active, |
|
905 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
906 | + ], |
|
907 | + 'upcoming_status' => [ |
|
908 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming, |
|
909 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
910 | + ], |
|
911 | + 'postponed_status' => [ |
|
912 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed, |
|
913 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
914 | + ], |
|
915 | + 'cancelled_status' => [ |
|
916 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled, |
|
917 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
918 | + ], |
|
919 | + 'expired_status' => [ |
|
920 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired, |
|
921 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
922 | + ], |
|
923 | + 'inactive_status' => [ |
|
924 | + 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive, |
|
925 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
926 | + ], |
|
927 | + ]; |
|
928 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
929 | + return array_merge($items, $statuses); |
|
930 | + } |
|
931 | + |
|
932 | + |
|
933 | + /** |
|
934 | + * @return EEM_Event |
|
935 | + * @throws EE_Error |
|
936 | + * @throws InvalidArgumentException |
|
937 | + * @throws InvalidDataTypeException |
|
938 | + * @throws InvalidInterfaceException |
|
939 | + * @throws ReflectionException |
|
940 | + */ |
|
941 | + private function _event_model(): EEM_Event |
|
942 | + { |
|
943 | + if (! $this->_event_model instanceof EEM_Event) { |
|
944 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
945 | + } |
|
946 | + return $this->_event_model; |
|
947 | + } |
|
948 | + |
|
949 | + |
|
950 | + /** |
|
951 | + * Adds extra buttons to the WP CPT permalink field row. |
|
952 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
953 | + * |
|
954 | + * @param string $return the current html |
|
955 | + * @param int $id the post id for the page |
|
956 | + * @param string|null $new_title What the title is |
|
957 | + * @param string|null $new_slug what the slug is |
|
958 | + * @return string The new html string for the permalink area |
|
959 | + * @deprecated 5.0.0.p |
|
960 | + * @see TicketSelectorShortcodeButton::addButton |
|
961 | + */ |
|
962 | + public function extra_permalink_field_buttons( |
|
963 | + string $return, |
|
964 | + int $id, |
|
965 | + ?string $new_title, |
|
966 | + ?string $new_slug |
|
967 | + ): string { |
|
968 | + return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug); |
|
969 | + } |
|
970 | + |
|
971 | + |
|
972 | + /** |
|
973 | + * _events_overview_list_table |
|
974 | + * This contains the logic for showing the events_overview list |
|
975 | + * |
|
976 | + * @access protected |
|
977 | + * @return void |
|
978 | + * @throws DomainException |
|
979 | + * @throws EE_Error |
|
980 | + * @throws InvalidArgumentException |
|
981 | + * @throws InvalidDataTypeException |
|
982 | + * @throws InvalidInterfaceException |
|
983 | + */ |
|
984 | + protected function _events_overview_list_table() |
|
985 | + { |
|
986 | + $after_list_table = []; |
|
987 | + $links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack'); |
|
988 | + $links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso')); |
|
989 | + $links_html .= EEH_HTML::div( |
|
990 | + EEH_Template::get_button_or_link( |
|
991 | + get_post_type_archive_link('espresso_events'), |
|
992 | + esc_html__('View Event Archive Page', 'event_espresso'), |
|
993 | + 'button button--small button--secondary' |
|
994 | + ), |
|
995 | + '', |
|
996 | + 'ee-admin-button-row ee-admin-button-row--align-start' |
|
997 | + ); |
|
998 | + $links_html .= EEH_HTML::divx(); |
|
999 | + |
|
1000 | + $after_list_table['view_event_list_button'] = $links_html; |
|
1001 | + |
|
1002 | + $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
1003 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
1004 | + 'create_new', |
|
1005 | + 'add', |
|
1006 | + [], |
|
1007 | + 'add-new-h2' |
|
1008 | + ); |
|
1009 | + |
|
1010 | + $this->_template_args['after_list_table'] = array_merge( |
|
1011 | + (array) $this->_template_args['after_list_table'], |
|
1012 | + $after_list_table |
|
1013 | + ); |
|
1014 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1015 | + } |
|
1016 | + |
|
1017 | + |
|
1018 | + /** |
|
1019 | + * this allows for extra misc actions in the default WP publish box |
|
1020 | + * |
|
1021 | + * @return void |
|
1022 | + * @throws DomainException |
|
1023 | + * @throws EE_Error |
|
1024 | + * @throws InvalidArgumentException |
|
1025 | + * @throws InvalidDataTypeException |
|
1026 | + * @throws InvalidInterfaceException |
|
1027 | + * @throws ReflectionException |
|
1028 | + */ |
|
1029 | + public function extra_misc_actions_publish_box() |
|
1030 | + { |
|
1031 | + $this->_generate_publish_box_extra_content(); |
|
1032 | + } |
|
1033 | + |
|
1034 | + |
|
1035 | + /** |
|
1036 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
1037 | + * saved. |
|
1038 | + * Typically you would use this to save any additional data. |
|
1039 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
1040 | + * ALSO very important. When a post transitions from scheduled to published, |
|
1041 | + * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
1042 | + * other meta saves. So MAKE sure that you handle this accordingly. |
|
1043 | + * |
|
1044 | + * @access protected |
|
1045 | + * @abstract |
|
1046 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
1047 | + * @param WP_Post $post The post object of the cpt that was saved. |
|
1048 | + * @return void |
|
1049 | + * @throws EE_Error |
|
1050 | + * @throws InvalidArgumentException |
|
1051 | + * @throws InvalidDataTypeException |
|
1052 | + * @throws InvalidInterfaceException |
|
1053 | + * @throws ReflectionException |
|
1054 | + */ |
|
1055 | + protected function _insert_update_cpt_item($post_id, $post) |
|
1056 | + { |
|
1057 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
1058 | + // get out we're not processing an event save. |
|
1059 | + return; |
|
1060 | + } |
|
1061 | + $event_values = [ |
|
1062 | + 'EVT_member_only' => $this->request->getRequestParam('member_only', false, DataType::BOOL), |
|
1063 | + 'EVT_allow_overflow' => $this->request->getRequestParam('EVT_allow_overflow', false, DataType::BOOL), |
|
1064 | + 'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'), |
|
1065 | + ]; |
|
1066 | + // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
|
1067 | + if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
1068 | + $event_values['EVT_display_ticket_selector'] = $this->request->getRequestParam( |
|
1069 | + 'display_ticket_selector', |
|
1070 | + false, |
|
1071 | + 'bool' |
|
1072 | + ); |
|
1073 | + $event_values['EVT_additional_limit'] = min( |
|
1074 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
1075 | + $this->request->getRequestParam( |
|
1076 | + 'additional_limit', |
|
1077 | + EEM_Event::get_default_additional_limit(), |
|
1078 | + 'int' |
|
1079 | + ) |
|
1080 | + ); |
|
1081 | + $event_values['EVT_default_registration_status'] = $this->request->getRequestParam( |
|
1082 | + 'EVT_default_registration_status', |
|
1083 | + EE_Registry::instance()->CFG->registration->default_STS_ID |
|
1084 | + ); |
|
1085 | + |
|
1086 | + $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL'); |
|
1087 | + $event_values['EVT_phone'] = $this->request->getRequestParam('event_phone'); |
|
1088 | + $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, DataType::BOOL); |
|
1089 | + } elseif ($post instanceof WP_Post) { |
|
1090 | + $event_values['EVT_name'] = $post->post_title; |
|
1091 | + $event_values['EVT_desc'] = $post->post_content; |
|
1092 | + } |
|
1093 | + // update event |
|
1094 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
1095 | + // get event_object for other metaboxes... |
|
1096 | + // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
1097 | + // i have to setup where conditions to override the filters in the model |
|
1098 | + // that filter out auto-draft and inherit statuses so we GET the inherit id! |
|
1099 | + /** @var EE_Event $event */ |
|
1100 | + $event = $this->_event_model()->get_one( |
|
1101 | + [ |
|
1102 | + [ |
|
1103 | + $this->_event_model()->primary_key_name() => $post_id, |
|
1104 | + 'OR' => [ |
|
1105 | + 'status' => $post->post_status, |
|
1106 | + // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
1107 | + // but the returned object here has a status of "publish", so use the original post status as well |
|
1108 | + 'status*1' => $this->request->getRequestParam('original_post_status'), |
|
1109 | + ], |
|
1110 | + ], |
|
1111 | + ] |
|
1112 | + ); |
|
1113 | + |
|
1114 | + // the following are default callbacks for event attachment updates |
|
1115 | + // that can be overridden by caffeinated functionality and/or addons. |
|
1116 | + $event_update_callbacks = []; |
|
1117 | + if (! $this->admin_config->useAdvancedEditor()) { |
|
1118 | + $event_update_callbacks['_default_venue_update'] = [$this, '_default_venue_update']; |
|
1119 | + $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update']; |
|
1120 | + } |
|
1121 | + $event_update_callbacks = apply_filters( |
|
1122 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
1123 | + $event_update_callbacks |
|
1124 | + ); |
|
1125 | + |
|
1126 | + $att_success = true; |
|
1127 | + foreach ($event_update_callbacks as $e_callback) { |
|
1128 | + $_success = is_callable($e_callback) |
|
1129 | + ? $e_callback($event, $this->request->requestParams()) |
|
1130 | + : false; |
|
1131 | + // if ANY of these updates fail then we want the appropriate global error message |
|
1132 | + $att_success = $_success !== false ? $att_success : false; |
|
1133 | + } |
|
1134 | + // any errors? |
|
1135 | + if ($success && $att_success === false) { |
|
1136 | + EE_Error::add_error( |
|
1137 | + esc_html__( |
|
1138 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
1139 | + 'event_espresso' |
|
1140 | + ), |
|
1141 | + __FILE__, |
|
1142 | + __FUNCTION__, |
|
1143 | + __LINE__ |
|
1144 | + ); |
|
1145 | + } elseif ($success === false) { |
|
1146 | + EE_Error::add_error( |
|
1147 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
1148 | + __FILE__, |
|
1149 | + __FUNCTION__, |
|
1150 | + __LINE__ |
|
1151 | + ); |
|
1152 | + } |
|
1153 | + } |
|
1154 | + |
|
1155 | + |
|
1156 | + /** |
|
1157 | + * @param int $post_id |
|
1158 | + * @param int $revision_id |
|
1159 | + * @throws EE_Error |
|
1160 | + * @throws EE_Error |
|
1161 | + * @throws ReflectionException |
|
1162 | + * @see parent::restore_item() |
|
1163 | + */ |
|
1164 | + protected function _restore_cpt_item(int $post_id, int $revision_id) |
|
1165 | + { |
|
1166 | + // copy existing event meta to new post |
|
1167 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
1168 | + if ($post_evt instanceof EE_Event) { |
|
1169 | + // meta revision restore |
|
1170 | + $post_evt->restore_revision($revision_id); |
|
1171 | + // related objs restore |
|
1172 | + $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
1173 | + } |
|
1174 | + } |
|
1175 | + |
|
1176 | + |
|
1177 | + /** |
|
1178 | + * Attach the venue to the Event |
|
1179 | + * |
|
1180 | + * @param EE_Event $event Event Object to add the venue to |
|
1181 | + * @param array $data The request data from the form |
|
1182 | + * @return bool Success or fail. |
|
1183 | + * @throws EE_Error |
|
1184 | + * @throws ReflectionException |
|
1185 | + */ |
|
1186 | + protected function _default_venue_update(EE_Event $event, array $data): bool |
|
1187 | + { |
|
1188 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1189 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
1190 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
1191 | + // very important. If we don't have a venue name... |
|
1192 | + // then we'll get out because not necessary to create empty venue |
|
1193 | + if (empty($data['venue_title'])) { |
|
1194 | + return false; |
|
1195 | + } |
|
1196 | + $venue_array = [ |
|
1197 | + 'VNU_wp_user' => $event->get('EVT_wp_user'), |
|
1198 | + 'VNU_name' => $data['venue_title'], |
|
1199 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
1200 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
1201 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) |
|
1202 | + ? $data['venue_short_description'] |
|
1203 | + : null, |
|
1204 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
1205 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
1206 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
1207 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
1208 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
1209 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
1210 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
1211 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
1212 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
1213 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
1214 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
1215 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
1216 | + 'status' => 'publish', |
|
1217 | + ]; |
|
1218 | + // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
1219 | + if (! empty($venue_id)) { |
|
1220 | + $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
1221 | + $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
1222 | + // we've gotta make sure that the venue is always attached to a revision.. |
|
1223 | + // add_relation_to should take care of making sure that the relation is already present. |
|
1224 | + $event->_add_relation_to($venue_id, 'Venue'); |
|
1225 | + return $rows_affected > 0; |
|
1226 | + } |
|
1227 | + // we insert the venue |
|
1228 | + $venue_id = $venue_model->insert($venue_array); |
|
1229 | + $event->_add_relation_to($venue_id, 'Venue'); |
|
1230 | + return ! empty($venue_id); |
|
1231 | + // when we have the ancestor come in it's already been handled by the revision save. |
|
1232 | + } |
|
1233 | + |
|
1234 | + |
|
1235 | + /** |
|
1236 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
1237 | + * |
|
1238 | + * @param EE_Event $event The Event object we're attaching data to |
|
1239 | + * @param array $data The request data from the form |
|
1240 | + * @return array |
|
1241 | + * @throws EE_Error |
|
1242 | + * @throws ReflectionException |
|
1243 | + * @throws Exception |
|
1244 | + */ |
|
1245 | + protected function _default_tickets_update(EE_Event $event, array $data): array |
|
1246 | + { |
|
1247 | + if ($this->admin_config->useAdvancedEditor()) { |
|
1248 | + return []; |
|
1249 | + } |
|
1250 | + $datetime = null; |
|
1251 | + $saved_tickets = []; |
|
1252 | + $event_timezone = $event->get_timezone(); |
|
1253 | + $date_formats = ['Y-m-d', 'h:i a']; |
|
1254 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
1255 | + // trim all values to ensure any excess whitespace is removed. |
|
1256 | + $datetime_data = array_map('trim', $datetime_data); |
|
1257 | + $datetime_data['DTT_EVT_end'] = |
|
1258 | + isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end']) |
|
1259 | + ? $datetime_data['DTT_EVT_end'] |
|
1260 | + : $datetime_data['DTT_EVT_start']; |
|
1261 | + $datetime_values = [ |
|
1262 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
|
1263 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
1264 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
1265 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'], |
|
1266 | + 'DTT_order' => $row, |
|
1267 | + ]; |
|
1268 | + // if we have an id then let's get existing object first and then set the new values. |
|
1269 | + // Otherwise we instantiate a new object for save. |
|
1270 | + if (! empty($datetime_data['DTT_ID'])) { |
|
1271 | + $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
|
1272 | + if (! $datetime instanceof EE_Datetime) { |
|
1273 | + throw new RuntimeException( |
|
1274 | + sprintf( |
|
1275 | + esc_html__( |
|
1276 | + 'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d', |
|
1277 | + 'event_espresso' |
|
1278 | + ), |
|
1279 | + $datetime_data['DTT_ID'] |
|
1280 | + ) |
|
1281 | + ); |
|
1282 | + } |
|
1283 | + $datetime->set_date_format($date_formats[0]); |
|
1284 | + $datetime->set_time_format($date_formats[1]); |
|
1285 | + foreach ($datetime_values as $field => $value) { |
|
1286 | + $datetime->set($field, $value); |
|
1287 | + } |
|
1288 | + } else { |
|
1289 | + $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
|
1290 | + } |
|
1291 | + if (! $datetime instanceof EE_Datetime) { |
|
1292 | + throw new RuntimeException( |
|
1293 | + sprintf( |
|
1294 | + esc_html__( |
|
1295 | + 'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s', |
|
1296 | + 'event_espresso' |
|
1297 | + ), |
|
1298 | + print_r($datetime_values, true) |
|
1299 | + ) |
|
1300 | + ); |
|
1301 | + } |
|
1302 | + // before going any further make sure our dates are setup correctly |
|
1303 | + // so that the end date is always equal or greater than the start date. |
|
1304 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
1305 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
1306 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
1307 | + } |
|
1308 | + $datetime->save(); |
|
1309 | + $event->_add_relation_to($datetime, 'Datetime'); |
|
1310 | + } |
|
1311 | + // no datetimes get deleted so we don't do any of that logic here. |
|
1312 | + // update tickets next |
|
1313 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
1314 | + |
|
1315 | + // set up some default start and end dates in case those are not present in the incoming data |
|
1316 | + $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
1317 | + $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
1318 | + // use the start date of the first datetime for the end date |
|
1319 | + $first_datetime = $event->first_datetime(); |
|
1320 | + $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
|
1321 | + |
|
1322 | + // now process the incoming data |
|
1323 | + foreach ($data['edit_tickets'] as $row => $ticket_data) { |
|
1324 | + $update_prices = false; |
|
1325 | + $ticket_price = $data['edit_prices'][ $row ][1]['PRC_amount'] ?? 0; |
|
1326 | + // trim inputs to ensure any excess whitespace is removed. |
|
1327 | + $ticket_data = array_map('trim', $ticket_data); |
|
1328 | + $ticket_values = [ |
|
1329 | + 'TKT_ID' => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null, |
|
1330 | + 'TTM_ID' => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0, |
|
1331 | + 'TKT_name' => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '', |
|
1332 | + 'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '', |
|
1333 | + 'TKT_start_date' => ! empty($ticket_data['TKT_start_date']) |
|
1334 | + ? $ticket_data['TKT_start_date'] |
|
1335 | + : $default_start_date, |
|
1336 | + 'TKT_end_date' => ! empty($ticket_data['TKT_end_date']) |
|
1337 | + ? $ticket_data['TKT_end_date'] |
|
1338 | + : $default_end_date, |
|
1339 | + 'TKT_qty' => ! empty($ticket_data['TKT_qty']) |
|
1340 | + || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0) |
|
1341 | + ? $ticket_data['TKT_qty'] |
|
1342 | + : EE_INF, |
|
1343 | + 'TKT_uses' => ! empty($ticket_data['TKT_uses']) |
|
1344 | + || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0) |
|
1345 | + ? $ticket_data['TKT_uses'] |
|
1346 | + : EE_INF, |
|
1347 | + 'TKT_min' => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0, |
|
1348 | + 'TKT_max' => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF, |
|
1349 | + 'TKT_order' => $ticket_data['TKT_order'] ?? $row, |
|
1350 | + 'TKT_price' => $ticket_price, |
|
1351 | + 'TKT_row' => $row, |
|
1352 | + ]; |
|
1353 | + // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly, |
|
1354 | + // which means in turn that the prices will become new prices as well. |
|
1355 | + if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) { |
|
1356 | + $ticket_values['TKT_ID'] = 0; |
|
1357 | + $ticket_values['TKT_is_default'] = 0; |
|
1358 | + $update_prices = true; |
|
1359 | + } |
|
1360 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
1361 | + // we actually do our saves ahead of adding any relations because its entirely possible that this |
|
1362 | + // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
|
1363 | + // keep in mind that if the ticket has been sold (and we have changed pricing information), |
|
1364 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
1365 | + if (! empty($ticket_data['TKT_ID'])) { |
|
1366 | + $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
|
1367 | + if (! $existing_ticket instanceof EE_Ticket) { |
|
1368 | + throw new RuntimeException( |
|
1369 | + sprintf( |
|
1370 | + esc_html__( |
|
1371 | + 'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d', |
|
1372 | + 'event_espresso' |
|
1373 | + ), |
|
1374 | + $ticket_data['TKT_ID'] |
|
1375 | + ) |
|
1376 | + ); |
|
1377 | + } |
|
1378 | + $ticket_sold = $existing_ticket->count_related( |
|
1379 | + 'Registration', |
|
1380 | + [ |
|
1381 | + [ |
|
1382 | + 'STS_ID' => [ |
|
1383 | + 'NOT IN', |
|
1384 | + [EEM_Registration::status_id_incomplete], |
|
1385 | + ], |
|
1386 | + ], |
|
1387 | + ] |
|
1388 | + ) > 0; |
|
1389 | + // let's just check the total price for the existing ticket and determine if it matches the new total price. |
|
1390 | + // if they are different then we create a new ticket (if $ticket_sold) |
|
1391 | + // if they aren't different then we go ahead and modify existing ticket. |
|
1392 | + $create_new_ticket = $ticket_sold |
|
1393 | + && $ticket_price !== $existing_ticket->price() |
|
1394 | + && ! $existing_ticket->deleted(); |
|
1395 | + $existing_ticket->set_date_format($date_formats[0]); |
|
1396 | + $existing_ticket->set_time_format($date_formats[1]); |
|
1397 | + // set new values |
|
1398 | + foreach ($ticket_values as $field => $value) { |
|
1399 | + if ($field == 'TKT_qty') { |
|
1400 | + $existing_ticket->set_qty($value); |
|
1401 | + } elseif ($field == 'TKT_price') { |
|
1402 | + $existing_ticket->set('TKT_price', $ticket_price); |
|
1403 | + } else { |
|
1404 | + $existing_ticket->set($field, $value); |
|
1405 | + } |
|
1406 | + } |
|
1407 | + $ticket = $existing_ticket; |
|
1408 | + // if $create_new_ticket is false then we can safely update the existing ticket. |
|
1409 | + // Otherwise we have to create a new ticket. |
|
1410 | + if ($create_new_ticket) { |
|
1411 | + // archive the old ticket first |
|
1412 | + $existing_ticket->set('TKT_deleted', 1); |
|
1413 | + $existing_ticket->save(); |
|
1414 | + // make sure this ticket is still recorded in our $saved_tickets |
|
1415 | + // so we don't run it through the regular trash routine. |
|
1416 | + $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
1417 | + // create new ticket that's a copy of the existing except, |
|
1418 | + // (a new id of course and not archived) AND has the new TKT_price associated with it. |
|
1419 | + $new_ticket = clone $existing_ticket; |
|
1420 | + $new_ticket->set('TKT_ID', 0); |
|
1421 | + $new_ticket->set('TKT_deleted', 0); |
|
1422 | + $new_ticket->set('TKT_sold', 0); |
|
1423 | + // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
1424 | + $update_prices = true; |
|
1425 | + $ticket = $new_ticket; |
|
1426 | + } |
|
1427 | + } else { |
|
1428 | + // no TKT_id so a new ticket |
|
1429 | + $ticket_values['TKT_price'] = $ticket_price; |
|
1430 | + $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
|
1431 | + $update_prices = true; |
|
1432 | + } |
|
1433 | + if (! $ticket instanceof EE_Ticket) { |
|
1434 | + throw new RuntimeException( |
|
1435 | + sprintf( |
|
1436 | + esc_html__( |
|
1437 | + 'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s', |
|
1438 | + 'event_espresso' |
|
1439 | + ), |
|
1440 | + print_r($ticket_values, true) |
|
1441 | + ) |
|
1442 | + ); |
|
1443 | + } |
|
1444 | + // cap ticket qty by datetime reg limits |
|
1445 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
1446 | + // update ticket. |
|
1447 | + $ticket->save(); |
|
1448 | + // before going any further make sure our dates are setup correctly |
|
1449 | + // so that the end date is always equal or greater than the start date. |
|
1450 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
1451 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
1452 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
1453 | + $ticket->save(); |
|
1454 | + } |
|
1455 | + // initially let's add the ticket to the datetime |
|
1456 | + $datetime->_add_relation_to($ticket, 'Ticket'); |
|
1457 | + $saved_tickets[ $ticket->ID() ] = $ticket; |
|
1458 | + // add prices to ticket |
|
1459 | + $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ]) |
|
1460 | + ? $data['edit_prices'][ $row ] |
|
1461 | + : []; |
|
1462 | + $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices); |
|
1463 | + } |
|
1464 | + // however now we need to handle permanently deleting tickets via the ui. |
|
1465 | + // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
1466 | + // However, it does allow for deleting tickets that have no tickets sold, |
|
1467 | + // in which case we want to get rid of permanently because there is no need to save in db. |
|
1468 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets; |
|
1469 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
1470 | + foreach ($tickets_removed as $id) { |
|
1471 | + $id = absint($id); |
|
1472 | + // get the ticket for this id |
|
1473 | + $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
1474 | + if (! $ticket_to_remove instanceof EE_Ticket) { |
|
1475 | + continue; |
|
1476 | + } |
|
1477 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
1478 | + // (remember this process can ONLY kick off if there are NO tickets sold) |
|
1479 | + $related_datetimes = $ticket_to_remove->get_many_related('Datetime'); |
|
1480 | + foreach ($related_datetimes as $related_datetime) { |
|
1481 | + $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime'); |
|
1482 | + } |
|
1483 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
1484 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
1485 | + $ticket_to_remove->delete_related_permanently('Price'); |
|
1486 | + // finally let's delete this ticket |
|
1487 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
1488 | + $ticket_to_remove->delete_permanently(); |
|
1489 | + } |
|
1490 | + return [$datetime, $saved_tickets]; |
|
1491 | + } |
|
1492 | + |
|
1493 | + |
|
1494 | + /** |
|
1495 | + * This attaches a list of given prices to a ticket. |
|
1496 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) |
|
1497 | + * because if there is a change in price information on a ticket, a new ticket is created anyways |
|
1498 | + * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket. |
|
1499 | + * |
|
1500 | + * @access private |
|
1501 | + * @param array $prices_data Array of prices from the form. |
|
1502 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
1503 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
1504 | + * @return void |
|
1505 | + * @throws EE_Error |
|
1506 | + * @throws ReflectionException |
|
1507 | + */ |
|
1508 | + private function _add_prices_to_ticket(array $prices_data, EE_Ticket $ticket, bool $new_prices = false) |
|
1509 | + { |
|
1510 | + $timezone = $ticket->get_timezone(); |
|
1511 | + foreach ($prices_data as $row => $price_data) { |
|
1512 | + $price_values = [ |
|
1513 | + 'PRC_ID' => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null, |
|
1514 | + 'PRT_ID' => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null, |
|
1515 | + 'PRC_amount' => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0, |
|
1516 | + 'PRC_name' => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '', |
|
1517 | + 'PRC_desc' => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '', |
|
1518 | + 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
1519 | + 'PRC_order' => $row, |
|
1520 | + ]; |
|
1521 | + if ($new_prices || empty($price_values['PRC_ID'])) { |
|
1522 | + $price_values['PRC_ID'] = 0; |
|
1523 | + $price = EE_Price::new_instance($price_values, $timezone); |
|
1524 | + } else { |
|
1525 | + $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']); |
|
1526 | + // update this price with new values |
|
1527 | + foreach ($price_values as $field => $new_price) { |
|
1528 | + $price->set($field, $new_price); |
|
1529 | + } |
|
1530 | + } |
|
1531 | + if (! $price instanceof EE_Price) { |
|
1532 | + throw new RuntimeException( |
|
1533 | + sprintf( |
|
1534 | + esc_html__( |
|
1535 | + 'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s', |
|
1536 | + 'event_espresso' |
|
1537 | + ), |
|
1538 | + print_r($price_values, true) |
|
1539 | + ) |
|
1540 | + ); |
|
1541 | + } |
|
1542 | + $price->save(); |
|
1543 | + $ticket->_add_relation_to($price, 'Price'); |
|
1544 | + } |
|
1545 | + } |
|
1546 | + |
|
1547 | + |
|
1548 | + /** |
|
1549 | + * Add in our autosave ajax handlers |
|
1550 | + * |
|
1551 | + */ |
|
1552 | + protected function _ee_autosave_create_new() |
|
1553 | + { |
|
1554 | + } |
|
1555 | + |
|
1556 | + |
|
1557 | + /** |
|
1558 | + * More autosave handlers. |
|
1559 | + */ |
|
1560 | + protected function _ee_autosave_edit() |
|
1561 | + { |
|
1562 | + } |
|
1563 | + |
|
1564 | + |
|
1565 | + /** |
|
1566 | + * @throws EE_Error |
|
1567 | + * @throws ReflectionException |
|
1568 | + */ |
|
1569 | + private function _generate_publish_box_extra_content() |
|
1570 | + { |
|
1571 | + // load formatter helper |
|
1572 | + // args for getting related registrations |
|
1573 | + $approved_query_args = [ |
|
1574 | + [ |
|
1575 | + 'REG_deleted' => 0, |
|
1576 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
1577 | + ], |
|
1578 | + ]; |
|
1579 | + $not_approved_query_args = [ |
|
1580 | + [ |
|
1581 | + 'REG_deleted' => 0, |
|
1582 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
1583 | + ], |
|
1584 | + ]; |
|
1585 | + $pending_payment_query_args = [ |
|
1586 | + [ |
|
1587 | + 'REG_deleted' => 0, |
|
1588 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
1589 | + ], |
|
1590 | + ]; |
|
1591 | + // publish box |
|
1592 | + $publish_box_extra_args = [ |
|
1593 | + 'view_approved_reg_url' => add_query_arg( |
|
1594 | + [ |
|
1595 | + 'action' => 'default', |
|
1596 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1597 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1598 | + 'use_filters' => true, |
|
1599 | + ], |
|
1600 | + REG_ADMIN_URL |
|
1601 | + ), |
|
1602 | + 'view_not_approved_reg_url' => add_query_arg( |
|
1603 | + [ |
|
1604 | + 'action' => 'default', |
|
1605 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1606 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1607 | + 'use_filters' => true, |
|
1608 | + ], |
|
1609 | + REG_ADMIN_URL |
|
1610 | + ), |
|
1611 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
1612 | + [ |
|
1613 | + 'action' => 'default', |
|
1614 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1615 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1616 | + 'use_filters' => true, |
|
1617 | + ], |
|
1618 | + REG_ADMIN_URL |
|
1619 | + ), |
|
1620 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
1621 | + 'Registration', |
|
1622 | + $approved_query_args |
|
1623 | + ), |
|
1624 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
1625 | + 'Registration', |
|
1626 | + $not_approved_query_args |
|
1627 | + ), |
|
1628 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
1629 | + 'Registration', |
|
1630 | + $pending_payment_query_args |
|
1631 | + ), |
|
1632 | + 'misc_pub_section_class' => apply_filters( |
|
1633 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
1634 | + 'misc-pub-section' |
|
1635 | + ), |
|
1636 | + ]; |
|
1637 | + ob_start(); |
|
1638 | + do_action( |
|
1639 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
1640 | + $this->_cpt_model_obj |
|
1641 | + ); |
|
1642 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
1643 | + // load template |
|
1644 | + EEH_Template::display_template( |
|
1645 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1646 | + $publish_box_extra_args |
|
1647 | + ); |
|
1648 | + } |
|
1649 | + |
|
1650 | + |
|
1651 | + /** |
|
1652 | + * @return EE_Event |
|
1653 | + */ |
|
1654 | + public function get_event_object() |
|
1655 | + { |
|
1656 | + return $this->_cpt_model_obj; |
|
1657 | + } |
|
1658 | + |
|
1659 | + |
|
1660 | + |
|
1661 | + |
|
1662 | + /** METABOXES * */ |
|
1663 | + /** |
|
1664 | + * _register_event_editor_meta_boxes |
|
1665 | + * add all metaboxes related to the event_editor |
|
1666 | + * |
|
1667 | + * @return void |
|
1668 | + * @throws EE_Error |
|
1669 | + * @throws ReflectionException |
|
1670 | + */ |
|
1671 | + protected function _register_event_editor_meta_boxes() |
|
1672 | + { |
|
1673 | + $this->verify_cpt_object(); |
|
1674 | + $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
|
1675 | + // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
1676 | + if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
1677 | + $this->addMetaBox( |
|
1678 | + 'espresso_event_editor_event_options', |
|
1679 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
1680 | + [$this, 'registration_options_meta_box'], |
|
1681 | + $this->page_slug, |
|
1682 | + 'side' |
|
1683 | + ); |
|
1684 | + } |
|
1685 | + if (! $use_advanced_editor) { |
|
1686 | + $this->addMetaBox( |
|
1687 | + 'espresso_event_editor_tickets', |
|
1688 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
1689 | + [$this, 'ticket_metabox'], |
|
1690 | + $this->page_slug, |
|
1691 | + 'normal', |
|
1692 | + 'high' |
|
1693 | + ); |
|
1694 | + } elseif ($this->feature->allowed('use_reg_options_meta_box')) { |
|
1695 | + add_action( |
|
1696 | + 'add_meta_boxes_espresso_events', |
|
1697 | + function () { |
|
1698 | + global $current_screen; |
|
1699 | + remove_meta_box('authordiv', $current_screen, 'normal'); |
|
1700 | + }, |
|
1701 | + 99 |
|
1702 | + ); |
|
1703 | + } |
|
1704 | + // NOTE: if you're looking for other metaboxes in here, |
|
1705 | + // where a metabox has a related management page in the admin |
|
1706 | + // you will find it setup in the related management page's "_Hooks" file. |
|
1707 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
1708 | + } |
|
1709 | + |
|
1710 | + |
|
1711 | + /** |
|
1712 | + * @throws DomainException |
|
1713 | + * @throws EE_Error |
|
1714 | + * @throws ReflectionException |
|
1715 | + */ |
|
1716 | + public function ticket_metabox() |
|
1717 | + { |
|
1718 | + $existing_datetime_ids = $existing_ticket_ids = []; |
|
1719 | + // defaults for template args |
|
1720 | + $template_args = [ |
|
1721 | + 'ticket_rows' => '', |
|
1722 | + 'total_ticket_rows' => 1, |
|
1723 | + 'trash_icon' => 'dashicons dashicons-lock', |
|
1724 | + 'disabled' => '', |
|
1725 | + ]; |
|
1726 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
1727 | + /** |
|
1728 | + * 1. Start with retrieving Datetimes |
|
1729 | + * 2. Fore each datetime get related tickets |
|
1730 | + * 3. For each ticket get related prices |
|
1731 | + */ |
|
1732 | + /** @var EEM_Datetime $datetime_model */ |
|
1733 | + $datetime_model = EE_Registry::instance()->load_model('Datetime'); |
|
1734 | + /** @var EEM_Ticket $datetime_model */ |
|
1735 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1736 | + $times = $datetime_model->get_all_event_dates($event_id); |
|
1737 | + /** @type EE_Datetime $first_datetime */ |
|
1738 | + $first_datetime = reset($times); |
|
1739 | + // do we get related tickets? |
|
1740 | + if ( |
|
1741 | + $first_datetime instanceof EE_Datetime |
|
1742 | + && $first_datetime->ID() !== 0 |
|
1743 | + ) { |
|
1744 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
1745 | + $template_args['time'] = $first_datetime; |
|
1746 | + $related_tickets = $first_datetime->tickets( |
|
1747 | + [ |
|
1748 | + ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
1749 | + 'default_where_conditions' => 'none', |
|
1750 | + ] |
|
1751 | + ); |
|
1752 | + if (! empty($related_tickets)) { |
|
1753 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
1754 | + $row = 0; |
|
1755 | + foreach ($related_tickets as $ticket) { |
|
1756 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
1757 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
1758 | + $row++; |
|
1759 | + } |
|
1760 | + } else { |
|
1761 | + $template_args['total_ticket_rows'] = 1; |
|
1762 | + /** @type EE_Ticket $ticket */ |
|
1763 | + $ticket = $ticket_model->create_default_object(); |
|
1764 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1765 | + } |
|
1766 | + } else { |
|
1767 | + $template_args['time'] = $times[0]; |
|
1768 | + /** @type EE_Ticket[] $tickets */ |
|
1769 | + $tickets = $ticket_model->get_all_default_tickets(); |
|
1770 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
1771 | + // NOTE: we're just sending the first default row |
|
1772 | + // (decaf can't manage default tickets so this should be sufficient); |
|
1773 | + } |
|
1774 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
1775 | + 'event_editor_event_datetimes_help_tab' |
|
1776 | + ); |
|
1777 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
1778 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1779 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1780 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
1781 | + $ticket_model->create_default_object(), |
|
1782 | + true |
|
1783 | + ); |
|
1784 | + $template = apply_filters( |
|
1785 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
1786 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1787 | + ); |
|
1788 | + EEH_Template::display_template($template, $template_args); |
|
1789 | + } |
|
1790 | + |
|
1791 | + |
|
1792 | + /** |
|
1793 | + * Setup an individual ticket form for the decaf event editor page |
|
1794 | + * |
|
1795 | + * @access private |
|
1796 | + * @param EE_Ticket $ticket the ticket object |
|
1797 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
1798 | + * @param int $row |
|
1799 | + * @return string generated html for the ticket row. |
|
1800 | + * @throws EE_Error |
|
1801 | + * @throws ReflectionException |
|
1802 | + */ |
|
1803 | + private function _get_ticket_row(EE_Ticket $ticket, bool $skeleton = false, int $row = 0): string |
|
1804 | + { |
|
1805 | + $template_args = [ |
|
1806 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1807 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
1808 | + : '', |
|
1809 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
1810 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
1811 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
1812 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
1813 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
1814 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
1815 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1816 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1817 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
1818 | + 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1819 | + && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1820 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock', |
|
1821 | + 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1822 | + : ' disabled=disabled', |
|
1823 | + ]; |
|
1824 | + $price = $ticket->ID() !== 0 |
|
1825 | + ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
1826 | + : null; |
|
1827 | + $price = $price instanceof EE_Price |
|
1828 | + ? $price |
|
1829 | + : EEM_Price::instance()->create_default_object(); |
|
1830 | + $price_args = [ |
|
1831 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1832 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
1833 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
1834 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
1835 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
1836 | + ]; |
|
1837 | + // make sure we have default start and end dates if skeleton |
|
1838 | + // handle rows that should NOT be empty |
|
1839 | + if (empty($template_args['TKT_start_date'])) { |
|
1840 | + // if empty then the start date will be now. |
|
1841 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
1842 | + } |
|
1843 | + if (empty($template_args['TKT_end_date'])) { |
|
1844 | + // get the earliest datetime (if present); |
|
1845 | + $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
1846 | + ? $this->_cpt_model_obj->get_first_related( |
|
1847 | + 'Datetime', |
|
1848 | + ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
1849 | + ) |
|
1850 | + : null; |
|
1851 | + $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime |
|
1852 | + ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a') |
|
1853 | + : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))); |
|
1854 | + } |
|
1855 | + $template_args = array_merge($template_args, $price_args); |
|
1856 | + $template = apply_filters( |
|
1857 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
1858 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1859 | + $ticket |
|
1860 | + ); |
|
1861 | + return EEH_Template::display_template($template, $template_args, true); |
|
1862 | + } |
|
1863 | + |
|
1864 | + |
|
1865 | + /** |
|
1866 | + * @throws EE_Error |
|
1867 | + * @throws ReflectionException |
|
1868 | + */ |
|
1869 | + public function registration_options_meta_box() |
|
1870 | + { |
|
1871 | + $yes_no_values = [ |
|
1872 | + ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
1873 | + ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
1874 | + ]; |
|
1875 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
1876 | + [ |
|
1877 | + EEM_Registration::status_id_cancelled, |
|
1878 | + EEM_Registration::status_id_declined, |
|
1879 | + EEM_Registration::status_id_incomplete, |
|
1880 | + ], |
|
1881 | + true |
|
1882 | + ); |
|
1883 | + // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
1884 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
1885 | + $template_args['event'] = $this->_cpt_model_obj; |
|
1886 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
1887 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
1888 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
1889 | + 'default_reg_status', |
|
1890 | + $default_reg_status_values, |
|
1891 | + $this->_cpt_model_obj->default_registration_status() |
|
1892 | + ); |
|
1893 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
1894 | + 'display_desc', |
|
1895 | + $yes_no_values, |
|
1896 | + $this->_cpt_model_obj->display_description() |
|
1897 | + ); |
|
1898 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
1899 | + 'display_ticket_selector', |
|
1900 | + $yes_no_values, |
|
1901 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
1902 | + '', |
|
1903 | + '', |
|
1904 | + false |
|
1905 | + ); |
|
1906 | + $template_args['additional_registration_options'] = apply_filters( |
|
1907 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
1908 | + '', |
|
1909 | + $template_args, |
|
1910 | + $yes_no_values, |
|
1911 | + $default_reg_status_values |
|
1912 | + ); |
|
1913 | + EEH_Template::display_template( |
|
1914 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1915 | + $template_args |
|
1916 | + ); |
|
1917 | + } |
|
1918 | + |
|
1919 | + |
|
1920 | + /** |
|
1921 | + * _get_events() |
|
1922 | + * This method simply returns all the events (for the given _view and paging) |
|
1923 | + * |
|
1924 | + * @access public |
|
1925 | + * @param int $per_page count of items per page (20 default); |
|
1926 | + * @param int $current_page what is the current page being viewed. |
|
1927 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
1928 | + * If FALSE then we return an array of event objects |
|
1929 | + * that match the given _view and paging parameters. |
|
1930 | + * @return array|int an array of event objects or a count of them. |
|
1931 | + * @throws Exception |
|
1932 | + */ |
|
1933 | + public function get_events(int $per_page = 10, int $current_page = 1, bool $count = false) |
|
1934 | + { |
|
1935 | + $EEM_Event = $this->_event_model(); |
|
1936 | + $offset = ($current_page - 1) * $per_page; |
|
1937 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
1938 | + $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
|
1939 | + $order = $this->request->getRequestParam('order', 'DESC'); |
|
1940 | + $month_range = $this->request->getRequestParam('month_range'); |
|
1941 | + if ($month_range) { |
|
1942 | + $pieces = explode(' ', $month_range, 3); |
|
1943 | + // simulate the FIRST day of the month, that fixes issues for months like February |
|
1944 | + // where PHP doesn't know what to assume for date. |
|
1945 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
1946 | + $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
1947 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1948 | + } |
|
1949 | + $where = []; |
|
1950 | + $status = $this->request->getRequestParam('status'); |
|
1951 | + // determine what post_status our condition will have for the query. |
|
1952 | + switch ($status) { |
|
1953 | + case 'month': |
|
1954 | + case 'today': |
|
1955 | + case null: |
|
1956 | + case 'all': |
|
1957 | + break; |
|
1958 | + case 'draft': |
|
1959 | + $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
1960 | + break; |
|
1961 | + default: |
|
1962 | + $where['status'] = $status; |
|
1963 | + } |
|
1964 | + // categories? The default for all categories is -1 |
|
1965 | + $category = $this->request->getRequestParam('EVT_CAT', -1, DataType::INT); |
|
1966 | + if ($category !== -1) { |
|
1967 | + $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
1968 | + $where['Term_Taxonomy.term_id'] = $category; |
|
1969 | + } |
|
1970 | + // date where conditions |
|
1971 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1972 | + if ($month_range) { |
|
1973 | + $DateTime = new DateTime( |
|
1974 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
1975 | + new DateTimeZone('UTC') |
|
1976 | + ); |
|
1977 | + $start = $DateTime->getTimestamp(); |
|
1978 | + // set the datetime to be the end of the month |
|
1979 | + $DateTime->setDate( |
|
1980 | + $year_r, |
|
1981 | + $month_r, |
|
1982 | + $DateTime->format('t') |
|
1983 | + )->setTime(23, 59, 59); |
|
1984 | + $end = $DateTime->getTimestamp(); |
|
1985 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
1986 | + } elseif ($status === 'today') { |
|
1987 | + $DateTime = |
|
1988 | + new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1989 | + $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
1990 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1991 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
1992 | + } elseif ($status === 'month') { |
|
1993 | + $now = date('Y-m-01'); |
|
1994 | + $DateTime = |
|
1995 | + new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1996 | + $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
1997 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
1998 | + ->setTime(23, 59, 59) |
|
1999 | + ->format(implode(' ', $start_formats)); |
|
2000 | + $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
2001 | + } |
|
2002 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
2003 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
2004 | + } else { |
|
2005 | + if (! isset($where['status'])) { |
|
2006 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
2007 | + $where['OR'] = [ |
|
2008 | + 'status*restrict_private' => ['!=', 'private'], |
|
2009 | + 'AND' => [ |
|
2010 | + 'status*inclusive' => ['=', 'private'], |
|
2011 | + 'EVT_wp_user' => get_current_user_id(), |
|
2012 | + ], |
|
2013 | + ]; |
|
2014 | + } |
|
2015 | + } |
|
2016 | + } |
|
2017 | + $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, DataType::INT); |
|
2018 | + if ( |
|
2019 | + $wp_user |
|
2020 | + && $wp_user !== get_current_user_id() |
|
2021 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
2022 | + ) { |
|
2023 | + $where['EVT_wp_user'] = $wp_user; |
|
2024 | + } |
|
2025 | + // search query handling |
|
2026 | + $search_term = $this->request->getRequestParam('s'); |
|
2027 | + if ($search_term) { |
|
2028 | + $search_term = '%' . $search_term . '%'; |
|
2029 | + $where['OR'] = [ |
|
2030 | + 'EVT_name' => ['LIKE', $search_term], |
|
2031 | + 'EVT_desc' => ['LIKE', $search_term], |
|
2032 | + 'EVT_short_desc' => ['LIKE', $search_term], |
|
2033 | + ]; |
|
2034 | + } |
|
2035 | + // filter events by venue. |
|
2036 | + $venue = $this->request->getRequestParam('venue', 0, DataType::INT); |
|
2037 | + if ($venue) { |
|
2038 | + $where['Venue.VNU_ID'] = $venue; |
|
2039 | + } |
|
2040 | + $request_params = $this->request->requestParams(); |
|
2041 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params); |
|
2042 | + $query_params = apply_filters( |
|
2043 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
2044 | + [ |
|
2045 | + $where, |
|
2046 | + 'limit' => $limit, |
|
2047 | + 'order_by' => $orderby, |
|
2048 | + 'order' => $order, |
|
2049 | + 'group_by' => 'EVT_ID', |
|
2050 | + ], |
|
2051 | + $request_params |
|
2052 | + ); |
|
2053 | + |
|
2054 | + // let's first check if we have special requests coming in. |
|
2055 | + $active_status = $this->request->getRequestParam('active_status'); |
|
2056 | + if ($active_status) { |
|
2057 | + switch ($active_status) { |
|
2058 | + case 'upcoming': |
|
2059 | + return $EEM_Event->get_upcoming_events($query_params, $count); |
|
2060 | + case 'expired': |
|
2061 | + return $EEM_Event->get_expired_events($query_params, $count); |
|
2062 | + case 'active': |
|
2063 | + return $EEM_Event->get_active_events($query_params, $count); |
|
2064 | + case 'inactive': |
|
2065 | + return $EEM_Event->get_inactive_events($query_params, $count); |
|
2066 | + } |
|
2067 | + } |
|
2068 | + |
|
2069 | + return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params); |
|
2070 | + } |
|
2071 | + |
|
2072 | + |
|
2073 | + /** |
|
2074 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
2075 | + * |
|
2076 | + * @param string $post_id |
|
2077 | + * @throws EE_Error |
|
2078 | + * @throws ReflectionException |
|
2079 | + */ |
|
2080 | + public function trash_cpt_item($post_id) |
|
2081 | + { |
|
2082 | + $this->request->setRequestParam('EVT_ID', $post_id); |
|
2083 | + $this->_trash_or_restore_event('trash', false); |
|
2084 | + } |
|
2085 | + |
|
2086 | + |
|
2087 | + /** |
|
2088 | + * @param string $post_id |
|
2089 | + * @throws EE_Error |
|
2090 | + * @throws ReflectionException |
|
2091 | + */ |
|
2092 | + public function restore_cpt_item($post_id) |
|
2093 | + { |
|
2094 | + $this->request->setRequestParam('EVT_ID', $post_id); |
|
2095 | + $this->_trash_or_restore_event('draft', false); |
|
2096 | + } |
|
2097 | + |
|
2098 | + |
|
2099 | + /** |
|
2100 | + * @param string $post_id |
|
2101 | + * @throws EE_Error |
|
2102 | + * @throws EE_Error |
|
2103 | + */ |
|
2104 | + public function delete_cpt_item($post_id) |
|
2105 | + { |
|
2106 | + throw new EE_Error( |
|
2107 | + esc_html__( |
|
2108 | + 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
2109 | + 'event_espresso' |
|
2110 | + ) |
|
2111 | + ); |
|
2112 | + // $this->request->setRequestParam('EVT_ID', $post_id); |
|
2113 | + // $this->_delete_event(); |
|
2114 | + } |
|
2115 | + |
|
2116 | + |
|
2117 | + /** |
|
2118 | + * _trash_or_restore_event |
|
2119 | + * |
|
2120 | + * @access protected |
|
2121 | + * @param string $event_status |
|
2122 | + * @param bool $redirect_after |
|
2123 | + * @throws EE_Error |
|
2124 | + * @throws EE_Error |
|
2125 | + * @throws ReflectionException |
|
2126 | + */ |
|
2127 | + protected function _trash_or_restore_event(string $event_status = 'trash', bool $redirect_after = true) |
|
2128 | + { |
|
2129 | + // determine the event id and set to array. |
|
2130 | + $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT); |
|
2131 | + // loop thru events |
|
2132 | + if ($EVT_ID) { |
|
2133 | + // clean status |
|
2134 | + $event_status = sanitize_key($event_status); |
|
2135 | + // grab status |
|
2136 | + if (! empty($event_status)) { |
|
2137 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
2138 | + } else { |
|
2139 | + $success = false; |
|
2140 | + $msg = esc_html__( |
|
2141 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2142 | + 'event_espresso' |
|
2143 | + ); |
|
2144 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2145 | + } |
|
2146 | + } else { |
|
2147 | + $success = false; |
|
2148 | + $msg = esc_html__( |
|
2149 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
2150 | + 'event_espresso' |
|
2151 | + ); |
|
2152 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2153 | + } |
|
2154 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2155 | + if ($redirect_after) { |
|
2156 | + $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
2157 | + } |
|
2158 | + } |
|
2159 | + |
|
2160 | + |
|
2161 | + /** |
|
2162 | + * _trash_or_restore_events |
|
2163 | + * |
|
2164 | + * @access protected |
|
2165 | + * @param string $event_status |
|
2166 | + * @return void |
|
2167 | + * @throws EE_Error |
|
2168 | + * @throws EE_Error |
|
2169 | + * @throws ReflectionException |
|
2170 | + */ |
|
2171 | + protected function _trash_or_restore_events(string $event_status = 'trash') |
|
2172 | + { |
|
2173 | + // clean status |
|
2174 | + $event_status = sanitize_key($event_status); |
|
2175 | + // grab status |
|
2176 | + if (! empty($event_status)) { |
|
2177 | + $success = true; |
|
2178 | + // determine the event id and set to array. |
|
2179 | + $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
2180 | + // loop thru events |
|
2181 | + foreach ($EVT_IDs as $EVT_ID) { |
|
2182 | + if ($EVT_ID = absint($EVT_ID)) { |
|
2183 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
2184 | + $success = $results !== false ? $success : false; |
|
2185 | + } else { |
|
2186 | + $msg = sprintf( |
|
2187 | + esc_html__( |
|
2188 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
2189 | + 'event_espresso' |
|
2190 | + ), |
|
2191 | + $EVT_ID |
|
2192 | + ); |
|
2193 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2194 | + $success = false; |
|
2195 | + } |
|
2196 | + } |
|
2197 | + } else { |
|
2198 | + $success = false; |
|
2199 | + $msg = esc_html__( |
|
2200 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2201 | + 'event_espresso' |
|
2202 | + ); |
|
2203 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2204 | + } |
|
2205 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2206 | + $success = $success ? 2 : false; |
|
2207 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2208 | + $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
2209 | + } |
|
2210 | + |
|
2211 | + |
|
2212 | + /** |
|
2213 | + * @param int $EVT_ID |
|
2214 | + * @param string $event_status |
|
2215 | + * @return bool |
|
2216 | + * @throws EE_Error |
|
2217 | + * @throws ReflectionException |
|
2218 | + */ |
|
2219 | + private function _change_event_status(int $EVT_ID = 0, string $event_status = ''): bool |
|
2220 | + { |
|
2221 | + // grab event id |
|
2222 | + if (! $EVT_ID) { |
|
2223 | + $msg = esc_html__( |
|
2224 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2225 | + 'event_espresso' |
|
2226 | + ); |
|
2227 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2228 | + return false; |
|
2229 | + } |
|
2230 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2231 | + // clean status |
|
2232 | + $event_status = sanitize_key($event_status); |
|
2233 | + // grab status |
|
2234 | + if (empty($event_status)) { |
|
2235 | + $msg = esc_html__( |
|
2236 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
2237 | + 'event_espresso' |
|
2238 | + ); |
|
2239 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2240 | + return false; |
|
2241 | + } |
|
2242 | + // was event trashed or restored ? |
|
2243 | + switch ($event_status) { |
|
2244 | + case 'draft': |
|
2245 | + $action = 'restored from the trash'; |
|
2246 | + $hook = 'AHEE_event_restored_from_trash'; |
|
2247 | + break; |
|
2248 | + case 'trash': |
|
2249 | + $action = 'moved to the trash'; |
|
2250 | + $hook = 'AHEE_event_moved_to_trash'; |
|
2251 | + break; |
|
2252 | + default: |
|
2253 | + $action = 'updated'; |
|
2254 | + $hook = false; |
|
2255 | + } |
|
2256 | + // use class to change status |
|
2257 | + $this->_cpt_model_obj->set_status($event_status); |
|
2258 | + $success = $this->_cpt_model_obj->save(); |
|
2259 | + if (! $success) { |
|
2260 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
2261 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2262 | + return false; |
|
2263 | + } |
|
2264 | + if ($hook) { |
|
2265 | + do_action($hook); |
|
2266 | + // fake the action hook in EE_Soft_Delete_Base_Class::delete_or_restore() |
|
2267 | + // because events side step that and it otherwise won't get called |
|
2268 | + do_action( |
|
2269 | + 'AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', |
|
2270 | + $this->_cpt_model_obj, |
|
2271 | + $hook === 'AHEE_event_moved_to_trash', |
|
2272 | + $success |
|
2273 | + ); |
|
2274 | + } |
|
2275 | + return true; |
|
2276 | + } |
|
2277 | + |
|
2278 | + |
|
2279 | + /** |
|
2280 | + * @param array $event_ids |
|
2281 | + * @return array |
|
2282 | + * @since 4.10.23.p |
|
2283 | + */ |
|
2284 | + private function cleanEventIds(array $event_ids): array |
|
2285 | + { |
|
2286 | + return array_map('absint', $event_ids); |
|
2287 | + } |
|
2288 | + |
|
2289 | + |
|
2290 | + /** |
|
2291 | + * @return array |
|
2292 | + * @since 4.10.23.p |
|
2293 | + */ |
|
2294 | + private function getEventIdsFromRequest(): array |
|
2295 | + { |
|
2296 | + if ($this->request->requestParamIsSet('EVT_IDs')) { |
|
2297 | + return $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
2298 | + } else { |
|
2299 | + return $this->request->getRequestParam('EVT_ID', [], 'int', true); |
|
2300 | + } |
|
2301 | + } |
|
2302 | + |
|
2303 | + |
|
2304 | + /** |
|
2305 | + * @param bool $preview_delete |
|
2306 | + * @throws EE_Error |
|
2307 | + * @throws ReflectionException |
|
2308 | + */ |
|
2309 | + protected function _delete_event(bool $preview_delete = true) |
|
2310 | + { |
|
2311 | + $this->_delete_events($preview_delete); |
|
2312 | + } |
|
2313 | + |
|
2314 | + |
|
2315 | + /** |
|
2316 | + * Gets the tree traversal batch persister. |
|
2317 | + * |
|
2318 | + * @return NodeGroupDao |
|
2319 | + * @throws InvalidArgumentException |
|
2320 | + * @throws InvalidDataTypeException |
|
2321 | + * @throws InvalidInterfaceException |
|
2322 | + * @since 4.10.12.p |
|
2323 | + */ |
|
2324 | + protected function getModelObjNodeGroupPersister(): NodeGroupDao |
|
2325 | + { |
|
2326 | + if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
2327 | + $this->model_obj_node_group_persister = |
|
2328 | + $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
2329 | + } |
|
2330 | + return $this->model_obj_node_group_persister; |
|
2331 | + } |
|
2332 | + |
|
2333 | + |
|
2334 | + /** |
|
2335 | + * @param bool $preview_delete |
|
2336 | + * @return void |
|
2337 | + * @throws EE_Error |
|
2338 | + * @throws ReflectionException |
|
2339 | + */ |
|
2340 | + protected function _delete_events(bool $preview_delete = true) |
|
2341 | + { |
|
2342 | + $event_ids = $this->getEventIdsFromRequest(); |
|
2343 | + if ($preview_delete) { |
|
2344 | + $this->generateDeletionPreview($event_ids); |
|
2345 | + } else { |
|
2346 | + foreach ($event_ids as $event_id) { |
|
2347 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
2348 | + if ($event instanceof EE_Event) { |
|
2349 | + $event->delete_permanently(); |
|
2350 | + } |
|
2351 | + } |
|
2352 | + } |
|
2353 | + } |
|
2354 | + |
|
2355 | + |
|
2356 | + /** |
|
2357 | + * @param array $event_ids |
|
2358 | + */ |
|
2359 | + protected function generateDeletionPreview(array $event_ids) |
|
2360 | + { |
|
2361 | + $event_ids = $this->cleanEventIds($event_ids); |
|
2362 | + // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
2363 | + $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
2364 | + $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
2365 | + [ |
|
2366 | + 'action' => 'preview_deletion', |
|
2367 | + 'deletion_job_code' => $deletion_job_code, |
|
2368 | + ], |
|
2369 | + $this->_admin_base_url |
|
2370 | + ); |
|
2371 | + EEH_URL::safeRedirectAndExit( |
|
2372 | + EE_Admin_Page::add_query_args_and_nonce( |
|
2373 | + [ |
|
2374 | + 'page' => EED_Batch::PAGE_SLUG, |
|
2375 | + 'batch' => EED_Batch::batch_job, |
|
2376 | + 'EVT_IDs' => $event_ids, |
|
2377 | + 'deletion_job_code' => $deletion_job_code, |
|
2378 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
2379 | + 'return_url' => urlencode($return_url), |
|
2380 | + ], |
|
2381 | + admin_url() |
|
2382 | + ) |
|
2383 | + ); |
|
2384 | + } |
|
2385 | + |
|
2386 | + |
|
2387 | + /** |
|
2388 | + * Checks for a POST submission |
|
2389 | + * |
|
2390 | + * @since 4.10.12.p |
|
2391 | + */ |
|
2392 | + protected function confirmDeletion() |
|
2393 | + { |
|
2394 | + $deletion_redirect_logic = $this->getLoader()->getShared( |
|
2395 | + 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' |
|
2396 | + ); |
|
2397 | + $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
2398 | + } |
|
2399 | + |
|
2400 | + |
|
2401 | + /** |
|
2402 | + * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
2403 | + * |
|
2404 | + * @throws EE_Error |
|
2405 | + * @since 4.10.12.p |
|
2406 | + */ |
|
2407 | + protected function previewDeletion() |
|
2408 | + { |
|
2409 | + $preview_deletion_logic = $this->getLoader()->getShared( |
|
2410 | + 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' |
|
2411 | + ); |
|
2412 | + $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
2413 | + $this->display_admin_page_with_no_sidebar(); |
|
2414 | + } |
|
2415 | + |
|
2416 | + |
|
2417 | + /** |
|
2418 | + * get total number of events |
|
2419 | + * |
|
2420 | + * @access public |
|
2421 | + * @return int |
|
2422 | + * @throws EE_Error |
|
2423 | + * @throws EE_Error |
|
2424 | + * @throws ReflectionException |
|
2425 | + */ |
|
2426 | + public function total_events(): int |
|
2427 | + { |
|
2428 | + return EEM_Event::instance()->count( |
|
2429 | + ['caps' => 'read_admin'], |
|
2430 | + 'EVT_ID', |
|
2431 | + true |
|
2432 | + ); |
|
2433 | + } |
|
2434 | + |
|
2435 | + |
|
2436 | + /** |
|
2437 | + * get total number of draft events |
|
2438 | + * |
|
2439 | + * @access public |
|
2440 | + * @return int |
|
2441 | + * @throws EE_Error |
|
2442 | + * @throws EE_Error |
|
2443 | + * @throws ReflectionException |
|
2444 | + */ |
|
2445 | + public function total_events_draft(): int |
|
2446 | + { |
|
2447 | + return EEM_Event::instance()->count( |
|
2448 | + [ |
|
2449 | + ['status' => ['IN', ['draft', 'auto-draft']]], |
|
2450 | + 'caps' => 'read_admin', |
|
2451 | + ], |
|
2452 | + 'EVT_ID', |
|
2453 | + true |
|
2454 | + ); |
|
2455 | + } |
|
2456 | + |
|
2457 | + |
|
2458 | + /** |
|
2459 | + * get total number of trashed events |
|
2460 | + * |
|
2461 | + * @access public |
|
2462 | + * @return int |
|
2463 | + * @throws EE_Error |
|
2464 | + * @throws EE_Error |
|
2465 | + * @throws ReflectionException |
|
2466 | + */ |
|
2467 | + public function total_trashed_events(): int |
|
2468 | + { |
|
2469 | + return EEM_Event::instance()->count( |
|
2470 | + [ |
|
2471 | + ['status' => 'trash'], |
|
2472 | + 'caps' => 'read_admin', |
|
2473 | + ], |
|
2474 | + 'EVT_ID', |
|
2475 | + true |
|
2476 | + ); |
|
2477 | + } |
|
2478 | + |
|
2479 | + |
|
2480 | + /** |
|
2481 | + * _default_event_settings |
|
2482 | + * This generates the Default Settings Tab |
|
2483 | + * |
|
2484 | + * @return void |
|
2485 | + * @throws DomainException |
|
2486 | + * @throws EE_Error |
|
2487 | + * @throws InvalidArgumentException |
|
2488 | + * @throws InvalidDataTypeException |
|
2489 | + * @throws InvalidInterfaceException |
|
2490 | + */ |
|
2491 | + protected function _default_event_settings() |
|
2492 | + { |
|
2493 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
2494 | + $this->_set_publish_post_box_vars(); |
|
2495 | + $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
2496 | + $this->_default_event_settings_form()->get_html(), |
|
2497 | + '', |
|
2498 | + 'padding' |
|
2499 | + ); |
|
2500 | + $this->display_admin_page_with_sidebar(); |
|
2501 | + } |
|
2502 | + |
|
2503 | + |
|
2504 | + /** |
|
2505 | + * Return the form for event settings. |
|
2506 | + * |
|
2507 | + * @return EE_Form_Section_Proper |
|
2508 | + * @throws EE_Error |
|
2509 | + */ |
|
2510 | + protected function _default_event_settings_form(): EE_Form_Section_Proper |
|
2511 | + { |
|
2512 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
2513 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
2514 | + // exclude |
|
2515 | + [ |
|
2516 | + EEM_Registration::status_id_cancelled, |
|
2517 | + EEM_Registration::status_id_declined, |
|
2518 | + EEM_Registration::status_id_incomplete, |
|
2519 | + EEM_Registration::status_id_wait_list, |
|
2520 | + ], |
|
2521 | + true |
|
2522 | + ); |
|
2523 | + // setup Advanced Editor ??? |
|
2524 | + if ( |
|
2525 | + $this->raw_req_action === 'default_event_settings' |
|
2526 | + || $this->raw_req_action === 'update_default_event_settings' |
|
2527 | + ) { |
|
2528 | + $this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class); |
|
2529 | + } |
|
2530 | + return new EE_Form_Section_Proper( |
|
2531 | + [ |
|
2532 | + 'name' => 'update_default_event_settings', |
|
2533 | + 'html_id' => 'update_default_event_settings', |
|
2534 | + 'html_class' => 'form-table', |
|
2535 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
2536 | + 'subsections' => apply_filters( |
|
2537 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
2538 | + [ |
|
2539 | + 'defaults_section_header' => new EE_Form_Section_HTML( |
|
2540 | + EEH_HTML::h2( |
|
2541 | + esc_html__('Default Settings', 'event_espresso'), |
|
2542 | + '', |
|
2543 | + 'ee-admin-settings-hdr' |
|
2544 | + ) |
|
2545 | + ), |
|
2546 | + 'default_reg_status' => new EE_Select_Input( |
|
2547 | + $registration_stati_for_selection, |
|
2548 | + [ |
|
2549 | + 'default' => isset($registration_config->default_STS_ID) |
|
2550 | + && array_key_exists( |
|
2551 | + $registration_config->default_STS_ID, |
|
2552 | + $registration_stati_for_selection |
|
2553 | + ) |
|
2554 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
2555 | + : EEM_Registration::status_id_pending_payment, |
|
2556 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
2557 | + . EEH_Template::get_help_tab_link( |
|
2558 | + 'default_settings_status_help_tab' |
|
2559 | + ), |
|
2560 | + 'html_help_text' => esc_html__( |
|
2561 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
2562 | + 'event_espresso' |
|
2563 | + ), |
|
2564 | + ] |
|
2565 | + ), |
|
2566 | + 'default_max_tickets' => new EE_Integer_Input( |
|
2567 | + [ |
|
2568 | + 'default' => $registration_config->default_maximum_number_of_tickets |
|
2569 | + ?? EEM_Event::get_default_additional_limit(), |
|
2570 | + 'html_label_text' => esc_html__( |
|
2571 | + 'Default Maximum Tickets Allowed Per Order:', |
|
2572 | + 'event_espresso' |
|
2573 | + ) |
|
2574 | + . EEH_Template::get_help_tab_link( |
|
2575 | + 'default_maximum_tickets_help_tab"' |
|
2576 | + ), |
|
2577 | + 'html_help_text' => esc_html__( |
|
2578 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
2579 | + 'event_espresso' |
|
2580 | + ), |
|
2581 | + ] |
|
2582 | + ), |
|
2583 | + ] |
|
2584 | + ), |
|
2585 | + ] |
|
2586 | + ); |
|
2587 | + } |
|
2588 | + |
|
2589 | + |
|
2590 | + /** |
|
2591 | + * @return void |
|
2592 | + * @throws EE_Error |
|
2593 | + * @throws InvalidArgumentException |
|
2594 | + * @throws InvalidDataTypeException |
|
2595 | + * @throws InvalidInterfaceException |
|
2596 | + */ |
|
2597 | + protected function _update_default_event_settings() |
|
2598 | + { |
|
2599 | + $form = $this->_default_event_settings_form(); |
|
2600 | + if ($form->was_submitted()) { |
|
2601 | + $form->receive_form_submission(); |
|
2602 | + if ($form->is_valid()) { |
|
2603 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
2604 | + $valid_data = $form->valid_data(); |
|
2605 | + if (isset($valid_data['default_reg_status'])) { |
|
2606 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
2607 | + } |
|
2608 | + if (isset($valid_data['default_max_tickets'])) { |
|
2609 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
2610 | + } |
|
2611 | + do_action( |
|
2612 | + 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
2613 | + $valid_data, |
|
2614 | + EE_Registry::instance()->CFG, |
|
2615 | + $this |
|
2616 | + ); |
|
2617 | + // update because data was valid! |
|
2618 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
2619 | + EE_Error::overwrite_success(); |
|
2620 | + EE_Error::add_success( |
|
2621 | + esc_html__('Default Event Settings were updated', 'event_espresso') |
|
2622 | + ); |
|
2623 | + } |
|
2624 | + } |
|
2625 | + $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
2626 | + } |
|
2627 | + |
|
2628 | + |
|
2629 | + /************* Templates ************* |
|
23 | 2630 | * |
24 | - * @var EE_Event $_event |
|
25 | - */ |
|
26 | - protected $_event; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * This will hold the category object for category_details screen. |
|
31 | - * |
|
32 | - * @var stdClass $_category |
|
33 | - */ |
|
34 | - protected $_category; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * This will hold the event model instance |
|
39 | - * |
|
40 | - * @var EEM_Event $_event_model |
|
41 | - */ |
|
42 | - protected $_event_model; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @var EE_Event |
|
47 | - */ |
|
48 | - protected $_cpt_model_obj = null; |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @var NodeGroupDao |
|
53 | - */ |
|
54 | - protected $model_obj_node_group_persister; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var AdvancedEditorAdminFormSection |
|
58 | - */ |
|
59 | - protected $advanced_editor_admin_form; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Initialize page props for this admin page group. |
|
64 | - */ |
|
65 | - protected function _init_page_props() |
|
66 | - { |
|
67 | - $this->page_slug = EVENTS_PG_SLUG; |
|
68 | - $this->page_label = EVENTS_LABEL; |
|
69 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
70 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
71 | - $this->_cpt_model_names = [ |
|
72 | - 'create_new' => 'EEM_Event', |
|
73 | - 'edit' => 'EEM_Event', |
|
74 | - ]; |
|
75 | - $this->_cpt_edit_routes = [ |
|
76 | - 'espresso_events' => 'edit', |
|
77 | - ]; |
|
78 | - add_action( |
|
79 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
80 | - [$this, 'verify_event_edit'], |
|
81 | - 10, |
|
82 | - 2 |
|
83 | - ); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * Sets the ajax hooks used for this admin page group. |
|
89 | - */ |
|
90 | - protected function _ajax_hooks() |
|
91 | - { |
|
92 | - add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Sets the page properties for this admin page group. |
|
98 | - */ |
|
99 | - protected function _define_page_props() |
|
100 | - { |
|
101 | - $event_id = $this->request->getRequestParam('post', 0, DataType::INT); |
|
102 | - if ($event_id) { |
|
103 | - $event_post = get_post($event_id); |
|
104 | - } |
|
105 | - |
|
106 | - $this->_admin_page_title = EVENTS_LABEL; |
|
107 | - $this->_labels = [ |
|
108 | - 'buttons' => [ |
|
109 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
110 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
111 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
112 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
113 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
114 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
115 | - ], |
|
116 | - 'editor_title' => [ |
|
117 | - 'espresso_events' => isset($event_post) && $event_post instanceof WP_Post |
|
118 | - ? $event_post->post_title |
|
119 | - : esc_html__('Edit Event', 'event_espresso'), |
|
120 | - ], |
|
121 | - 'publishbox' => [ |
|
122 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
123 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
124 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
125 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
126 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
127 | - ], |
|
128 | - ]; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * Sets the page routes property for this admin page group. |
|
134 | - */ |
|
135 | - protected function _set_page_routes() |
|
136 | - { |
|
137 | - // load formatter helper |
|
138 | - // load field generator helper |
|
139 | - // is there a evt_id in the request? |
|
140 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT); |
|
141 | - $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, DataType::INT); |
|
142 | - |
|
143 | - $this->_page_routes = [ |
|
144 | - 'default' => [ |
|
145 | - 'func' => [$this, '_events_overview_list_table'], |
|
146 | - 'capability' => 'ee_read_events', |
|
147 | - ], |
|
148 | - 'create_new' => [ |
|
149 | - 'func' => [$this, '_create_new_cpt_item'], |
|
150 | - 'capability' => 'ee_edit_events', |
|
151 | - ], |
|
152 | - 'edit' => [ |
|
153 | - 'func' => [$this, '_edit_cpt_item'], |
|
154 | - 'capability' => 'ee_edit_event', |
|
155 | - 'obj_id' => $EVT_ID, |
|
156 | - ], |
|
157 | - 'copy_event' => [ |
|
158 | - 'func' => [$this, '_copy_events'], |
|
159 | - 'capability' => 'ee_edit_event', |
|
160 | - 'obj_id' => $EVT_ID, |
|
161 | - 'noheader' => true, |
|
162 | - ], |
|
163 | - 'trash_event' => [ |
|
164 | - 'func' => [$this, '_trash_or_restore_event'], |
|
165 | - 'args' => ['event_status' => 'trash'], |
|
166 | - 'capability' => 'ee_delete_event', |
|
167 | - 'obj_id' => $EVT_ID, |
|
168 | - 'noheader' => true, |
|
169 | - ], |
|
170 | - 'trash_events' => [ |
|
171 | - 'func' => [$this, '_trash_or_restore_events'], |
|
172 | - 'args' => ['event_status' => 'trash'], |
|
173 | - 'capability' => 'ee_delete_events', |
|
174 | - 'noheader' => true, |
|
175 | - ], |
|
176 | - 'restore_event' => [ |
|
177 | - 'func' => [$this, '_trash_or_restore_event'], |
|
178 | - 'args' => ['event_status' => 'draft'], |
|
179 | - 'capability' => 'ee_delete_event', |
|
180 | - 'obj_id' => $EVT_ID, |
|
181 | - 'noheader' => true, |
|
182 | - ], |
|
183 | - 'restore_events' => [ |
|
184 | - 'func' => [$this, '_trash_or_restore_events'], |
|
185 | - 'args' => ['event_status' => 'draft'], |
|
186 | - 'capability' => 'ee_delete_events', |
|
187 | - 'noheader' => true, |
|
188 | - ], |
|
189 | - 'delete_event' => [ |
|
190 | - 'func' => [$this, '_delete_event'], |
|
191 | - 'capability' => 'ee_delete_event', |
|
192 | - 'obj_id' => $EVT_ID, |
|
193 | - 'noheader' => true, |
|
194 | - ], |
|
195 | - 'delete_events' => [ |
|
196 | - 'func' => [$this, '_delete_events'], |
|
197 | - 'capability' => 'ee_delete_events', |
|
198 | - 'noheader' => true, |
|
199 | - ], |
|
200 | - 'view_report' => [ |
|
201 | - 'func' => [$this, '_view_report'], |
|
202 | - 'capability' => 'ee_edit_events', |
|
203 | - ], |
|
204 | - 'default_event_settings' => [ |
|
205 | - 'func' => [$this, '_default_event_settings'], |
|
206 | - 'capability' => 'manage_options', |
|
207 | - ], |
|
208 | - 'update_default_event_settings' => [ |
|
209 | - 'func' => [$this, '_update_default_event_settings'], |
|
210 | - 'capability' => 'manage_options', |
|
211 | - 'noheader' => true, |
|
212 | - ], |
|
213 | - 'template_settings' => [ |
|
214 | - 'func' => [$this, '_template_settings'], |
|
215 | - 'capability' => 'manage_options', |
|
216 | - ], |
|
217 | - // event category tab related |
|
218 | - 'add_category' => [ |
|
219 | - 'func' => [$this, '_category_details'], |
|
220 | - 'capability' => 'ee_edit_event_category', |
|
221 | - 'args' => ['view' => 'add'], |
|
222 | - ], |
|
223 | - 'edit_category' => [ |
|
224 | - 'func' => [$this, '_category_details'], |
|
225 | - 'capability' => 'ee_edit_event_category', |
|
226 | - 'args' => ['view' => 'edit'], |
|
227 | - ], |
|
228 | - 'delete_categories' => [ |
|
229 | - 'func' => [$this, '_delete_categories'], |
|
230 | - 'capability' => 'ee_delete_event_category', |
|
231 | - 'noheader' => true, |
|
232 | - ], |
|
233 | - 'delete_category' => [ |
|
234 | - 'func' => [$this, '_delete_categories'], |
|
235 | - 'capability' => 'ee_delete_event_category', |
|
236 | - 'noheader' => true, |
|
237 | - ], |
|
238 | - 'insert_category' => [ |
|
239 | - 'func' => [$this, '_insert_or_update_category'], |
|
240 | - 'args' => ['new_category' => true], |
|
241 | - 'capability' => 'ee_edit_event_category', |
|
242 | - 'noheader' => true, |
|
243 | - ], |
|
244 | - 'update_category' => [ |
|
245 | - 'func' => [$this, '_insert_or_update_category'], |
|
246 | - 'args' => ['new_category' => false], |
|
247 | - 'capability' => 'ee_edit_event_category', |
|
248 | - 'noheader' => true, |
|
249 | - ], |
|
250 | - 'category_list' => [ |
|
251 | - 'func' => [$this, '_category_list_table'], |
|
252 | - 'capability' => 'ee_manage_event_categories', |
|
253 | - ], |
|
254 | - 'preview_deletion' => [ |
|
255 | - 'func' => [$this, 'previewDeletion'], |
|
256 | - 'capability' => 'ee_delete_events', |
|
257 | - ], |
|
258 | - 'confirm_deletion' => [ |
|
259 | - 'func' => [$this, 'confirmDeletion'], |
|
260 | - 'capability' => 'ee_delete_events', |
|
261 | - 'noheader' => true, |
|
262 | - ], |
|
263 | - ]; |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * Set the _page_config property for this admin page group. |
|
269 | - */ |
|
270 | - protected function _set_page_config() |
|
271 | - { |
|
272 | - $post_id = $this->request->getRequestParam('post', 0, DataType::INT); |
|
273 | - $EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
274 | - $this->_page_config = [ |
|
275 | - 'default' => [ |
|
276 | - 'nav' => [ |
|
277 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
278 | - 'icon' => 'dashicons-list-view', |
|
279 | - 'order' => 10, |
|
280 | - ], |
|
281 | - 'list_table' => 'Events_Admin_List_Table', |
|
282 | - 'help_tabs' => [ |
|
283 | - 'events_overview_help_tab' => [ |
|
284 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
285 | - 'filename' => 'events_overview', |
|
286 | - ], |
|
287 | - 'events_overview_table_column_headings_help_tab' => [ |
|
288 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
289 | - 'filename' => 'events_overview_table_column_headings', |
|
290 | - ], |
|
291 | - 'events_overview_filters_help_tab' => [ |
|
292 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
293 | - 'filename' => 'events_overview_filters', |
|
294 | - ], |
|
295 | - 'events_overview_view_help_tab' => [ |
|
296 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
297 | - 'filename' => 'events_overview_views', |
|
298 | - ], |
|
299 | - 'events_overview_other_help_tab' => [ |
|
300 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
301 | - 'filename' => 'events_overview_other', |
|
302 | - ], |
|
303 | - ], |
|
304 | - 'require_nonce' => false, |
|
305 | - ], |
|
306 | - 'create_new' => [ |
|
307 | - 'nav' => [ |
|
308 | - 'label' => esc_html__('Add New Event', 'event_espresso'), |
|
309 | - 'icon' => 'dashicons-plus-alt', |
|
310 | - 'order' => 15, |
|
311 | - 'persistent' => false, |
|
312 | - ], |
|
313 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
314 | - 'help_tabs' => [ |
|
315 | - 'event_editor_help_tab' => [ |
|
316 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
317 | - 'filename' => 'event_editor', |
|
318 | - ], |
|
319 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
320 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
321 | - 'filename' => 'event_editor_title_richtexteditor', |
|
322 | - ], |
|
323 | - 'event_editor_venue_details_help_tab' => [ |
|
324 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
325 | - 'filename' => 'event_editor_venue_details', |
|
326 | - ], |
|
327 | - 'event_editor_event_datetimes_help_tab' => [ |
|
328 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
329 | - 'filename' => 'event_editor_event_datetimes', |
|
330 | - ], |
|
331 | - 'event_editor_event_tickets_help_tab' => [ |
|
332 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
333 | - 'filename' => 'event_editor_event_tickets', |
|
334 | - ], |
|
335 | - 'event_editor_event_registration_options_help_tab' => [ |
|
336 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
337 | - 'filename' => 'event_editor_event_registration_options', |
|
338 | - ], |
|
339 | - 'event_editor_tags_categories_help_tab' => [ |
|
340 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
341 | - 'filename' => 'event_editor_tags_categories', |
|
342 | - ], |
|
343 | - 'event_editor_questions_registrants_help_tab' => [ |
|
344 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
345 | - 'filename' => 'event_editor_questions_registrants', |
|
346 | - ], |
|
347 | - 'event_editor_save_new_event_help_tab' => [ |
|
348 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
349 | - 'filename' => 'event_editor_save_new_event', |
|
350 | - ], |
|
351 | - 'event_editor_other_help_tab' => [ |
|
352 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
353 | - 'filename' => 'event_editor_other', |
|
354 | - ], |
|
355 | - ], |
|
356 | - 'qtips' => ['EE_Event_Editor_Decaf_Tips'], |
|
357 | - 'require_nonce' => false, |
|
358 | - ], |
|
359 | - 'edit' => [ |
|
360 | - 'nav' => [ |
|
361 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
362 | - 'icon' => 'dashicons-edit', |
|
363 | - 'order' => 15, |
|
364 | - 'persistent' => false, |
|
365 | - 'url' => $post_id |
|
366 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
367 | - ['post' => $post_id, 'action' => 'edit'], |
|
368 | - $this->_current_page_view_url |
|
369 | - ) |
|
370 | - : $this->_admin_base_url, |
|
371 | - ], |
|
372 | - 'metaboxes' => ['_register_event_editor_meta_boxes'], |
|
373 | - 'help_tabs' => [ |
|
374 | - 'event_editor_help_tab' => [ |
|
375 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
376 | - 'filename' => 'event_editor', |
|
377 | - ], |
|
378 | - 'event_editor_title_richtexteditor_help_tab' => [ |
|
379 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
380 | - 'filename' => 'event_editor_title_richtexteditor', |
|
381 | - ], |
|
382 | - 'event_editor_venue_details_help_tab' => [ |
|
383 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
384 | - 'filename' => 'event_editor_venue_details', |
|
385 | - ], |
|
386 | - 'event_editor_event_datetimes_help_tab' => [ |
|
387 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
388 | - 'filename' => 'event_editor_event_datetimes', |
|
389 | - ], |
|
390 | - 'event_editor_event_tickets_help_tab' => [ |
|
391 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
392 | - 'filename' => 'event_editor_event_tickets', |
|
393 | - ], |
|
394 | - 'event_editor_event_registration_options_help_tab' => [ |
|
395 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
396 | - 'filename' => 'event_editor_event_registration_options', |
|
397 | - ], |
|
398 | - 'event_editor_tags_categories_help_tab' => [ |
|
399 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
400 | - 'filename' => 'event_editor_tags_categories', |
|
401 | - ], |
|
402 | - 'event_editor_questions_registrants_help_tab' => [ |
|
403 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
404 | - 'filename' => 'event_editor_questions_registrants', |
|
405 | - ], |
|
406 | - 'event_editor_save_new_event_help_tab' => [ |
|
407 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
408 | - 'filename' => 'event_editor_save_new_event', |
|
409 | - ], |
|
410 | - 'event_editor_other_help_tab' => [ |
|
411 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
412 | - 'filename' => 'event_editor_other', |
|
413 | - ], |
|
414 | - ], |
|
415 | - 'require_nonce' => false, |
|
416 | - ], |
|
417 | - 'default_event_settings' => [ |
|
418 | - 'nav' => [ |
|
419 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
420 | - 'icon' => 'dashicons-admin-generic', |
|
421 | - 'order' => 40, |
|
422 | - ], |
|
423 | - 'metaboxes' => array_merge(['_publish_post_box'], $this->_default_espresso_metaboxes), |
|
424 | - 'labels' => [ |
|
425 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
426 | - ], |
|
427 | - 'help_tabs' => [ |
|
428 | - 'default_settings_help_tab' => [ |
|
429 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
430 | - 'filename' => 'events_default_settings', |
|
431 | - ], |
|
432 | - 'default_settings_status_help_tab' => [ |
|
433 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
434 | - 'filename' => 'events_default_settings_status', |
|
435 | - ], |
|
436 | - 'default_maximum_tickets_help_tab' => [ |
|
437 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
438 | - 'filename' => 'events_default_settings_max_tickets', |
|
439 | - ], |
|
440 | - ], |
|
441 | - 'require_nonce' => false, |
|
442 | - ], |
|
443 | - // template settings |
|
444 | - 'template_settings' => [ |
|
445 | - 'nav' => [ |
|
446 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
447 | - 'icon' => 'dashicons-layout', |
|
448 | - 'order' => 30, |
|
449 | - ], |
|
450 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
451 | - 'help_tabs' => [ |
|
452 | - 'general_settings_templates_help_tab' => [ |
|
453 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
454 | - 'filename' => 'general_settings_templates', |
|
455 | - ], |
|
456 | - ], |
|
457 | - 'require_nonce' => false, |
|
458 | - ], |
|
459 | - // event category stuff |
|
460 | - 'add_category' => [ |
|
461 | - 'nav' => [ |
|
462 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
463 | - 'icon' => 'dashicons-plus-alt', |
|
464 | - 'order' => 25, |
|
465 | - 'persistent' => false, |
|
466 | - ], |
|
467 | - 'help_tabs' => [ |
|
468 | - 'add_category_help_tab' => [ |
|
469 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
470 | - 'filename' => 'events_add_category', |
|
471 | - ], |
|
472 | - ], |
|
473 | - 'metaboxes' => ['_publish_post_box'], |
|
474 | - 'require_nonce' => false, |
|
475 | - ], |
|
476 | - 'edit_category' => [ |
|
477 | - 'nav' => [ |
|
478 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
479 | - 'icon' => 'dashicons-edit', |
|
480 | - 'order' => 25, |
|
481 | - 'persistent' => false, |
|
482 | - 'url' => $EVT_CAT_ID |
|
483 | - ? add_query_arg( |
|
484 | - ['EVT_CAT_ID' => $EVT_CAT_ID], |
|
485 | - $this->_current_page_view_url |
|
486 | - ) |
|
487 | - : $this->_admin_base_url, |
|
488 | - ], |
|
489 | - 'help_tabs' => [ |
|
490 | - 'edit_category_help_tab' => [ |
|
491 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
492 | - 'filename' => 'events_edit_category', |
|
493 | - ], |
|
494 | - ], |
|
495 | - 'metaboxes' => ['_publish_post_box'], |
|
496 | - 'require_nonce' => false, |
|
497 | - ], |
|
498 | - 'category_list' => [ |
|
499 | - 'nav' => [ |
|
500 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
501 | - 'icon' => 'dashicons-networking', |
|
502 | - 'order' => 20, |
|
503 | - ], |
|
504 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
505 | - 'help_tabs' => [ |
|
506 | - 'events_categories_help_tab' => [ |
|
507 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
508 | - 'filename' => 'events_categories', |
|
509 | - ], |
|
510 | - 'events_categories_table_column_headings_help_tab' => [ |
|
511 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
512 | - 'filename' => 'events_categories_table_column_headings', |
|
513 | - ], |
|
514 | - 'events_categories_view_help_tab' => [ |
|
515 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
516 | - 'filename' => 'events_categories_views', |
|
517 | - ], |
|
518 | - 'events_categories_other_help_tab' => [ |
|
519 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
520 | - 'filename' => 'events_categories_other', |
|
521 | - ], |
|
522 | - ], |
|
523 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
524 | - 'require_nonce' => false, |
|
525 | - ], |
|
526 | - 'preview_deletion' => [ |
|
527 | - 'nav' => [ |
|
528 | - 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
529 | - 'icon' => 'dashicons-remove', |
|
530 | - 'order' => 15, |
|
531 | - 'persistent' => false, |
|
532 | - 'url' => '', |
|
533 | - ], |
|
534 | - 'require_nonce' => false, |
|
535 | - ], |
|
536 | - ]; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * Used to register any global screen options if necessary for every route in this admin page group. |
|
542 | - */ |
|
543 | - protected function _add_screen_options() |
|
544 | - { |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * Implementing the screen options for the 'default' route. |
|
550 | - * |
|
551 | - * @throws InvalidArgumentException |
|
552 | - * @throws InvalidDataTypeException |
|
553 | - * @throws InvalidInterfaceException |
|
554 | - */ |
|
555 | - protected function _add_screen_options_default() |
|
556 | - { |
|
557 | - $this->_per_page_screen_option(); |
|
558 | - } |
|
559 | - |
|
560 | - |
|
561 | - /** |
|
562 | - * Implementing screen options for the category list route. |
|
563 | - * |
|
564 | - * @throws InvalidArgumentException |
|
565 | - * @throws InvalidDataTypeException |
|
566 | - * @throws InvalidInterfaceException |
|
567 | - */ |
|
568 | - protected function _add_screen_options_category_list() |
|
569 | - { |
|
570 | - $page_title = $this->_admin_page_title; |
|
571 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
572 | - $this->_per_page_screen_option(); |
|
573 | - $this->_admin_page_title = $page_title; |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * Used to register any global feature pointers for the admin page group. |
|
579 | - */ |
|
580 | - protected function _add_feature_pointers() |
|
581 | - { |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
587 | - */ |
|
588 | - public function load_scripts_styles() |
|
589 | - { |
|
590 | - wp_register_style( |
|
591 | - 'events-admin-css', |
|
592 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
593 | - [], |
|
594 | - EVENT_ESPRESSO_VERSION |
|
595 | - ); |
|
596 | - wp_register_style( |
|
597 | - 'ee-cat-admin', |
|
598 | - EVENTS_ASSETS_URL . 'ee-cat-admin.css', |
|
599 | - [], |
|
600 | - EVENT_ESPRESSO_VERSION |
|
601 | - ); |
|
602 | - wp_enqueue_style('events-admin-css'); |
|
603 | - wp_enqueue_style('ee-cat-admin'); |
|
604 | - // scripts |
|
605 | - wp_register_script( |
|
606 | - 'event_editor_js', |
|
607 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
608 | - ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'], |
|
609 | - EVENT_ESPRESSO_VERSION, |
|
610 | - true |
|
611 | - ); |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * Enqueuing scripts and styles specific to this view |
|
617 | - */ |
|
618 | - public function load_scripts_styles_create_new() |
|
619 | - { |
|
620 | - $this->load_scripts_styles_edit(); |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * Enqueuing scripts and styles specific to this view |
|
626 | - */ |
|
627 | - public function load_scripts_styles_edit() |
|
628 | - { |
|
629 | - // styles |
|
630 | - wp_enqueue_style('espresso-ui-theme'); |
|
631 | - wp_register_style( |
|
632 | - 'event-editor-css', |
|
633 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
634 | - ['ee-admin-css'], |
|
635 | - EVENT_ESPRESSO_VERSION |
|
636 | - ); |
|
637 | - wp_enqueue_style('event-editor-css'); |
|
638 | - // scripts |
|
639 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
640 | - wp_register_script( |
|
641 | - 'event-datetime-metabox', |
|
642 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
643 | - ['event_editor_js', 'ee-datepicker'], |
|
644 | - EVENT_ESPRESSO_VERSION |
|
645 | - ); |
|
646 | - wp_enqueue_script('event-datetime-metabox'); |
|
647 | - } |
|
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * Populating the _views property for the category list table view. |
|
653 | - */ |
|
654 | - protected function _set_list_table_views_category_list() |
|
655 | - { |
|
656 | - $this->_views = [ |
|
657 | - 'all' => [ |
|
658 | - 'slug' => 'all', |
|
659 | - 'label' => esc_html__('All', 'event_espresso'), |
|
660 | - 'count' => 0, |
|
661 | - 'bulk_action' => [ |
|
662 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
663 | - ], |
|
664 | - ], |
|
665 | - ]; |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
671 | - */ |
|
672 | - public function admin_init() |
|
673 | - { |
|
674 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
675 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
676 | - 'event_espresso' |
|
677 | - ); |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - /** |
|
682 | - * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
683 | - * group. |
|
684 | - */ |
|
685 | - public function admin_notices() |
|
686 | - { |
|
687 | - } |
|
688 | - |
|
689 | - |
|
690 | - /** |
|
691 | - * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
692 | - * this admin page group. |
|
693 | - */ |
|
694 | - public function admin_footer_scripts() |
|
695 | - { |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
701 | - * warning (via EE_Error::add_error()); |
|
702 | - * |
|
703 | - * @param EE_Event|null $event Event object |
|
704 | - * @param string $req_type |
|
705 | - * @return void |
|
706 | - * @throws EE_Error |
|
707 | - * @throws ReflectionException |
|
708 | - */ |
|
709 | - public function verify_event_edit(?EE_Base_Class $event = null, string $req_type = '') |
|
710 | - { |
|
711 | - // don't need to do this when processing |
|
712 | - if (! empty($req_type)) { |
|
713 | - return; |
|
714 | - } |
|
715 | - // no event? |
|
716 | - if (! $event instanceof EE_Event) { |
|
717 | - $event = $this->_cpt_model_obj; |
|
718 | - } |
|
719 | - // STILL no event? |
|
720 | - if (! $event instanceof EE_Event) { |
|
721 | - return; |
|
722 | - } |
|
723 | - // don't need to keep calling this |
|
724 | - remove_action( |
|
725 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
726 | - [$this, 'verify_event_edit'] |
|
727 | - ); |
|
728 | - $orig_status = $event->status(); |
|
729 | - // first check if event is active. |
|
730 | - if ( |
|
731 | - $orig_status === EEM_Event::cancelled |
|
732 | - || $orig_status === EEM_Event::postponed |
|
733 | - || $event->is_expired() |
|
734 | - || $event->is_inactive() |
|
735 | - ) { |
|
736 | - return; |
|
737 | - } |
|
738 | - // made it here so it IS active... next check that any of the tickets are sold. |
|
739 | - if ($event->is_sold_out(true)) { |
|
740 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
741 | - EE_Error::add_attention( |
|
742 | - sprintf( |
|
743 | - esc_html__( |
|
744 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
745 | - 'event_espresso' |
|
746 | - ), |
|
747 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
748 | - ) |
|
749 | - ); |
|
750 | - } |
|
751 | - return; |
|
752 | - } |
|
753 | - if ($orig_status === EEM_Event::sold_out) { |
|
754 | - EE_Error::add_attention( |
|
755 | - sprintf( |
|
756 | - esc_html__( |
|
757 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
758 | - 'event_espresso' |
|
759 | - ), |
|
760 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
761 | - ) |
|
762 | - ); |
|
763 | - } |
|
764 | - // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
765 | - if (! $event->tickets_on_sale()) { |
|
766 | - return; |
|
767 | - } |
|
768 | - // made it here so show warning |
|
769 | - $this->_edit_event_warning(); |
|
770 | - } |
|
771 | - |
|
772 | - |
|
773 | - /** |
|
774 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
775 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
776 | - * |
|
777 | - * @access protected |
|
778 | - * @return void |
|
779 | - */ |
|
780 | - protected function _edit_event_warning() |
|
781 | - { |
|
782 | - // we don't want to add warnings during these requests |
|
783 | - if ($this->request->getRequestParam('action') === 'editpost') { |
|
784 | - return; |
|
785 | - } |
|
786 | - EE_Error::add_attention( |
|
787 | - sprintf( |
|
788 | - esc_html__( |
|
789 | - 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
790 | - 'event_espresso' |
|
791 | - ), |
|
792 | - '<a class="espresso-help-tab-lnk ee-help-tab-link">', |
|
793 | - '</a>' |
|
794 | - ) |
|
795 | - ); |
|
796 | - } |
|
797 | - |
|
798 | - |
|
799 | - /** |
|
800 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
801 | - * Otherwise, do the normal logic |
|
802 | - * |
|
803 | - * @return void |
|
804 | - * @throws EE_Error |
|
805 | - * @throws InvalidArgumentException |
|
806 | - * @throws InvalidDataTypeException |
|
807 | - * @throws InvalidInterfaceException |
|
808 | - * @throws ReflectionException |
|
809 | - */ |
|
810 | - protected function _create_new_cpt_item() |
|
811 | - { |
|
812 | - $has_timezone_string = get_option('timezone_string'); |
|
813 | - // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
814 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) { |
|
815 | - EE_Error::add_attention( |
|
816 | - sprintf( |
|
817 | - esc_html__( |
|
818 | - 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
819 | - 'event_espresso' |
|
820 | - ), |
|
821 | - '<br>', |
|
822 | - '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
823 | - . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
824 | - . '</select>', |
|
825 | - '<button class="button button--secondary timezone-submit">', |
|
826 | - '</button><span class="spinner"></span>' |
|
827 | - ), |
|
828 | - __FILE__, |
|
829 | - __FUNCTION__, |
|
830 | - __LINE__ |
|
831 | - ); |
|
832 | - } |
|
833 | - parent::_create_new_cpt_item(); |
|
834 | - } |
|
835 | - |
|
836 | - |
|
837 | - /** |
|
838 | - * Sets the _views property for the default route in this admin page group. |
|
839 | - */ |
|
840 | - protected function _set_list_table_views_default() |
|
841 | - { |
|
842 | - $this->_views = [ |
|
843 | - 'all' => [ |
|
844 | - 'slug' => 'all', |
|
845 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
846 | - 'count' => 0, |
|
847 | - 'bulk_action' => [ |
|
848 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
849 | - ], |
|
850 | - ], |
|
851 | - 'draft' => [ |
|
852 | - 'slug' => 'draft', |
|
853 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
854 | - 'count' => 0, |
|
855 | - 'bulk_action' => [ |
|
856 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
857 | - ], |
|
858 | - ], |
|
859 | - ]; |
|
860 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
861 | - $this->_views['trash'] = [ |
|
862 | - 'slug' => 'trash', |
|
863 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
864 | - 'count' => 0, |
|
865 | - 'bulk_action' => [ |
|
866 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
867 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
868 | - ], |
|
869 | - ]; |
|
870 | - } |
|
871 | - } |
|
872 | - |
|
873 | - |
|
874 | - /** |
|
875 | - * Provides the legend item array for the default list table view. |
|
876 | - * |
|
877 | - * @return array |
|
878 | - * @throws EE_Error |
|
879 | - * @throws EE_Error |
|
880 | - */ |
|
881 | - protected function _event_legend_items(): array |
|
882 | - { |
|
883 | - $items = [ |
|
884 | - 'view_details' => [ |
|
885 | - 'class' => 'dashicons dashicons-visibility', |
|
886 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
887 | - ], |
|
888 | - 'edit_event' => [ |
|
889 | - 'class' => 'dashicons dashicons-calendar-alt', |
|
890 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
891 | - ], |
|
892 | - 'view_attendees' => [ |
|
893 | - 'class' => 'dashicons dashicons-groups', |
|
894 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
895 | - ], |
|
896 | - ]; |
|
897 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
898 | - $statuses = [ |
|
899 | - 'sold_out_status' => [ |
|
900 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out, |
|
901 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
902 | - ], |
|
903 | - 'active_status' => [ |
|
904 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active, |
|
905 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
906 | - ], |
|
907 | - 'upcoming_status' => [ |
|
908 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming, |
|
909 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
910 | - ], |
|
911 | - 'postponed_status' => [ |
|
912 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed, |
|
913 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
914 | - ], |
|
915 | - 'cancelled_status' => [ |
|
916 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled, |
|
917 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
918 | - ], |
|
919 | - 'expired_status' => [ |
|
920 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired, |
|
921 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
922 | - ], |
|
923 | - 'inactive_status' => [ |
|
924 | - 'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive, |
|
925 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
926 | - ], |
|
927 | - ]; |
|
928 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
929 | - return array_merge($items, $statuses); |
|
930 | - } |
|
931 | - |
|
932 | - |
|
933 | - /** |
|
934 | - * @return EEM_Event |
|
935 | - * @throws EE_Error |
|
936 | - * @throws InvalidArgumentException |
|
937 | - * @throws InvalidDataTypeException |
|
938 | - * @throws InvalidInterfaceException |
|
939 | - * @throws ReflectionException |
|
940 | - */ |
|
941 | - private function _event_model(): EEM_Event |
|
942 | - { |
|
943 | - if (! $this->_event_model instanceof EEM_Event) { |
|
944 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
945 | - } |
|
946 | - return $this->_event_model; |
|
947 | - } |
|
948 | - |
|
949 | - |
|
950 | - /** |
|
951 | - * Adds extra buttons to the WP CPT permalink field row. |
|
952 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
953 | - * |
|
954 | - * @param string $return the current html |
|
955 | - * @param int $id the post id for the page |
|
956 | - * @param string|null $new_title What the title is |
|
957 | - * @param string|null $new_slug what the slug is |
|
958 | - * @return string The new html string for the permalink area |
|
959 | - * @deprecated 5.0.0.p |
|
960 | - * @see TicketSelectorShortcodeButton::addButton |
|
961 | - */ |
|
962 | - public function extra_permalink_field_buttons( |
|
963 | - string $return, |
|
964 | - int $id, |
|
965 | - ?string $new_title, |
|
966 | - ?string $new_slug |
|
967 | - ): string { |
|
968 | - return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug); |
|
969 | - } |
|
970 | - |
|
971 | - |
|
972 | - /** |
|
973 | - * _events_overview_list_table |
|
974 | - * This contains the logic for showing the events_overview list |
|
975 | - * |
|
976 | - * @access protected |
|
977 | - * @return void |
|
978 | - * @throws DomainException |
|
979 | - * @throws EE_Error |
|
980 | - * @throws InvalidArgumentException |
|
981 | - * @throws InvalidDataTypeException |
|
982 | - * @throws InvalidInterfaceException |
|
983 | - */ |
|
984 | - protected function _events_overview_list_table() |
|
985 | - { |
|
986 | - $after_list_table = []; |
|
987 | - $links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack'); |
|
988 | - $links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso')); |
|
989 | - $links_html .= EEH_HTML::div( |
|
990 | - EEH_Template::get_button_or_link( |
|
991 | - get_post_type_archive_link('espresso_events'), |
|
992 | - esc_html__('View Event Archive Page', 'event_espresso'), |
|
993 | - 'button button--small button--secondary' |
|
994 | - ), |
|
995 | - '', |
|
996 | - 'ee-admin-button-row ee-admin-button-row--align-start' |
|
997 | - ); |
|
998 | - $links_html .= EEH_HTML::divx(); |
|
999 | - |
|
1000 | - $after_list_table['view_event_list_button'] = $links_html; |
|
1001 | - |
|
1002 | - $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
1003 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
1004 | - 'create_new', |
|
1005 | - 'add', |
|
1006 | - [], |
|
1007 | - 'add-new-h2' |
|
1008 | - ); |
|
1009 | - |
|
1010 | - $this->_template_args['after_list_table'] = array_merge( |
|
1011 | - (array) $this->_template_args['after_list_table'], |
|
1012 | - $after_list_table |
|
1013 | - ); |
|
1014 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1015 | - } |
|
1016 | - |
|
1017 | - |
|
1018 | - /** |
|
1019 | - * this allows for extra misc actions in the default WP publish box |
|
1020 | - * |
|
1021 | - * @return void |
|
1022 | - * @throws DomainException |
|
1023 | - * @throws EE_Error |
|
1024 | - * @throws InvalidArgumentException |
|
1025 | - * @throws InvalidDataTypeException |
|
1026 | - * @throws InvalidInterfaceException |
|
1027 | - * @throws ReflectionException |
|
1028 | - */ |
|
1029 | - public function extra_misc_actions_publish_box() |
|
1030 | - { |
|
1031 | - $this->_generate_publish_box_extra_content(); |
|
1032 | - } |
|
1033 | - |
|
1034 | - |
|
1035 | - /** |
|
1036 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
1037 | - * saved. |
|
1038 | - * Typically you would use this to save any additional data. |
|
1039 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
1040 | - * ALSO very important. When a post transitions from scheduled to published, |
|
1041 | - * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
1042 | - * other meta saves. So MAKE sure that you handle this accordingly. |
|
1043 | - * |
|
1044 | - * @access protected |
|
1045 | - * @abstract |
|
1046 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
1047 | - * @param WP_Post $post The post object of the cpt that was saved. |
|
1048 | - * @return void |
|
1049 | - * @throws EE_Error |
|
1050 | - * @throws InvalidArgumentException |
|
1051 | - * @throws InvalidDataTypeException |
|
1052 | - * @throws InvalidInterfaceException |
|
1053 | - * @throws ReflectionException |
|
1054 | - */ |
|
1055 | - protected function _insert_update_cpt_item($post_id, $post) |
|
1056 | - { |
|
1057 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
1058 | - // get out we're not processing an event save. |
|
1059 | - return; |
|
1060 | - } |
|
1061 | - $event_values = [ |
|
1062 | - 'EVT_member_only' => $this->request->getRequestParam('member_only', false, DataType::BOOL), |
|
1063 | - 'EVT_allow_overflow' => $this->request->getRequestParam('EVT_allow_overflow', false, DataType::BOOL), |
|
1064 | - 'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'), |
|
1065 | - ]; |
|
1066 | - // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version |
|
1067 | - if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
1068 | - $event_values['EVT_display_ticket_selector'] = $this->request->getRequestParam( |
|
1069 | - 'display_ticket_selector', |
|
1070 | - false, |
|
1071 | - 'bool' |
|
1072 | - ); |
|
1073 | - $event_values['EVT_additional_limit'] = min( |
|
1074 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
1075 | - $this->request->getRequestParam( |
|
1076 | - 'additional_limit', |
|
1077 | - EEM_Event::get_default_additional_limit(), |
|
1078 | - 'int' |
|
1079 | - ) |
|
1080 | - ); |
|
1081 | - $event_values['EVT_default_registration_status'] = $this->request->getRequestParam( |
|
1082 | - 'EVT_default_registration_status', |
|
1083 | - EE_Registry::instance()->CFG->registration->default_STS_ID |
|
1084 | - ); |
|
1085 | - |
|
1086 | - $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL'); |
|
1087 | - $event_values['EVT_phone'] = $this->request->getRequestParam('event_phone'); |
|
1088 | - $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, DataType::BOOL); |
|
1089 | - } elseif ($post instanceof WP_Post) { |
|
1090 | - $event_values['EVT_name'] = $post->post_title; |
|
1091 | - $event_values['EVT_desc'] = $post->post_content; |
|
1092 | - } |
|
1093 | - // update event |
|
1094 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
1095 | - // get event_object for other metaboxes... |
|
1096 | - // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. |
|
1097 | - // i have to setup where conditions to override the filters in the model |
|
1098 | - // that filter out auto-draft and inherit statuses so we GET the inherit id! |
|
1099 | - /** @var EE_Event $event */ |
|
1100 | - $event = $this->_event_model()->get_one( |
|
1101 | - [ |
|
1102 | - [ |
|
1103 | - $this->_event_model()->primary_key_name() => $post_id, |
|
1104 | - 'OR' => [ |
|
1105 | - 'status' => $post->post_status, |
|
1106 | - // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
1107 | - // but the returned object here has a status of "publish", so use the original post status as well |
|
1108 | - 'status*1' => $this->request->getRequestParam('original_post_status'), |
|
1109 | - ], |
|
1110 | - ], |
|
1111 | - ] |
|
1112 | - ); |
|
1113 | - |
|
1114 | - // the following are default callbacks for event attachment updates |
|
1115 | - // that can be overridden by caffeinated functionality and/or addons. |
|
1116 | - $event_update_callbacks = []; |
|
1117 | - if (! $this->admin_config->useAdvancedEditor()) { |
|
1118 | - $event_update_callbacks['_default_venue_update'] = [$this, '_default_venue_update']; |
|
1119 | - $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update']; |
|
1120 | - } |
|
1121 | - $event_update_callbacks = apply_filters( |
|
1122 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
1123 | - $event_update_callbacks |
|
1124 | - ); |
|
1125 | - |
|
1126 | - $att_success = true; |
|
1127 | - foreach ($event_update_callbacks as $e_callback) { |
|
1128 | - $_success = is_callable($e_callback) |
|
1129 | - ? $e_callback($event, $this->request->requestParams()) |
|
1130 | - : false; |
|
1131 | - // if ANY of these updates fail then we want the appropriate global error message |
|
1132 | - $att_success = $_success !== false ? $att_success : false; |
|
1133 | - } |
|
1134 | - // any errors? |
|
1135 | - if ($success && $att_success === false) { |
|
1136 | - EE_Error::add_error( |
|
1137 | - esc_html__( |
|
1138 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
1139 | - 'event_espresso' |
|
1140 | - ), |
|
1141 | - __FILE__, |
|
1142 | - __FUNCTION__, |
|
1143 | - __LINE__ |
|
1144 | - ); |
|
1145 | - } elseif ($success === false) { |
|
1146 | - EE_Error::add_error( |
|
1147 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
1148 | - __FILE__, |
|
1149 | - __FUNCTION__, |
|
1150 | - __LINE__ |
|
1151 | - ); |
|
1152 | - } |
|
1153 | - } |
|
1154 | - |
|
1155 | - |
|
1156 | - /** |
|
1157 | - * @param int $post_id |
|
1158 | - * @param int $revision_id |
|
1159 | - * @throws EE_Error |
|
1160 | - * @throws EE_Error |
|
1161 | - * @throws ReflectionException |
|
1162 | - * @see parent::restore_item() |
|
1163 | - */ |
|
1164 | - protected function _restore_cpt_item(int $post_id, int $revision_id) |
|
1165 | - { |
|
1166 | - // copy existing event meta to new post |
|
1167 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
1168 | - if ($post_evt instanceof EE_Event) { |
|
1169 | - // meta revision restore |
|
1170 | - $post_evt->restore_revision($revision_id); |
|
1171 | - // related objs restore |
|
1172 | - $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']); |
|
1173 | - } |
|
1174 | - } |
|
1175 | - |
|
1176 | - |
|
1177 | - /** |
|
1178 | - * Attach the venue to the Event |
|
1179 | - * |
|
1180 | - * @param EE_Event $event Event Object to add the venue to |
|
1181 | - * @param array $data The request data from the form |
|
1182 | - * @return bool Success or fail. |
|
1183 | - * @throws EE_Error |
|
1184 | - * @throws ReflectionException |
|
1185 | - */ |
|
1186 | - protected function _default_venue_update(EE_Event $event, array $data): bool |
|
1187 | - { |
|
1188 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1189 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
1190 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
1191 | - // very important. If we don't have a venue name... |
|
1192 | - // then we'll get out because not necessary to create empty venue |
|
1193 | - if (empty($data['venue_title'])) { |
|
1194 | - return false; |
|
1195 | - } |
|
1196 | - $venue_array = [ |
|
1197 | - 'VNU_wp_user' => $event->get('EVT_wp_user'), |
|
1198 | - 'VNU_name' => $data['venue_title'], |
|
1199 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
1200 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
1201 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) |
|
1202 | - ? $data['venue_short_description'] |
|
1203 | - : null, |
|
1204 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
1205 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
1206 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
1207 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
1208 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
1209 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
1210 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
1211 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
1212 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
1213 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
1214 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
1215 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
1216 | - 'status' => 'publish', |
|
1217 | - ]; |
|
1218 | - // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
1219 | - if (! empty($venue_id)) { |
|
1220 | - $update_where = [$venue_model->primary_key_name() => $venue_id]; |
|
1221 | - $rows_affected = $venue_model->update($venue_array, [$update_where]); |
|
1222 | - // we've gotta make sure that the venue is always attached to a revision.. |
|
1223 | - // add_relation_to should take care of making sure that the relation is already present. |
|
1224 | - $event->_add_relation_to($venue_id, 'Venue'); |
|
1225 | - return $rows_affected > 0; |
|
1226 | - } |
|
1227 | - // we insert the venue |
|
1228 | - $venue_id = $venue_model->insert($venue_array); |
|
1229 | - $event->_add_relation_to($venue_id, 'Venue'); |
|
1230 | - return ! empty($venue_id); |
|
1231 | - // when we have the ancestor come in it's already been handled by the revision save. |
|
1232 | - } |
|
1233 | - |
|
1234 | - |
|
1235 | - /** |
|
1236 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
1237 | - * |
|
1238 | - * @param EE_Event $event The Event object we're attaching data to |
|
1239 | - * @param array $data The request data from the form |
|
1240 | - * @return array |
|
1241 | - * @throws EE_Error |
|
1242 | - * @throws ReflectionException |
|
1243 | - * @throws Exception |
|
1244 | - */ |
|
1245 | - protected function _default_tickets_update(EE_Event $event, array $data): array |
|
1246 | - { |
|
1247 | - if ($this->admin_config->useAdvancedEditor()) { |
|
1248 | - return []; |
|
1249 | - } |
|
1250 | - $datetime = null; |
|
1251 | - $saved_tickets = []; |
|
1252 | - $event_timezone = $event->get_timezone(); |
|
1253 | - $date_formats = ['Y-m-d', 'h:i a']; |
|
1254 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
1255 | - // trim all values to ensure any excess whitespace is removed. |
|
1256 | - $datetime_data = array_map('trim', $datetime_data); |
|
1257 | - $datetime_data['DTT_EVT_end'] = |
|
1258 | - isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end']) |
|
1259 | - ? $datetime_data['DTT_EVT_end'] |
|
1260 | - : $datetime_data['DTT_EVT_start']; |
|
1261 | - $datetime_values = [ |
|
1262 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null, |
|
1263 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
1264 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
1265 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'], |
|
1266 | - 'DTT_order' => $row, |
|
1267 | - ]; |
|
1268 | - // if we have an id then let's get existing object first and then set the new values. |
|
1269 | - // Otherwise we instantiate a new object for save. |
|
1270 | - if (! empty($datetime_data['DTT_ID'])) { |
|
1271 | - $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']); |
|
1272 | - if (! $datetime instanceof EE_Datetime) { |
|
1273 | - throw new RuntimeException( |
|
1274 | - sprintf( |
|
1275 | - esc_html__( |
|
1276 | - 'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d', |
|
1277 | - 'event_espresso' |
|
1278 | - ), |
|
1279 | - $datetime_data['DTT_ID'] |
|
1280 | - ) |
|
1281 | - ); |
|
1282 | - } |
|
1283 | - $datetime->set_date_format($date_formats[0]); |
|
1284 | - $datetime->set_time_format($date_formats[1]); |
|
1285 | - foreach ($datetime_values as $field => $value) { |
|
1286 | - $datetime->set($field, $value); |
|
1287 | - } |
|
1288 | - } else { |
|
1289 | - $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats); |
|
1290 | - } |
|
1291 | - if (! $datetime instanceof EE_Datetime) { |
|
1292 | - throw new RuntimeException( |
|
1293 | - sprintf( |
|
1294 | - esc_html__( |
|
1295 | - 'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s', |
|
1296 | - 'event_espresso' |
|
1297 | - ), |
|
1298 | - print_r($datetime_values, true) |
|
1299 | - ) |
|
1300 | - ); |
|
1301 | - } |
|
1302 | - // before going any further make sure our dates are setup correctly |
|
1303 | - // so that the end date is always equal or greater than the start date. |
|
1304 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
1305 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
1306 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
1307 | - } |
|
1308 | - $datetime->save(); |
|
1309 | - $event->_add_relation_to($datetime, 'Datetime'); |
|
1310 | - } |
|
1311 | - // no datetimes get deleted so we don't do any of that logic here. |
|
1312 | - // update tickets next |
|
1313 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : []; |
|
1314 | - |
|
1315 | - // set up some default start and end dates in case those are not present in the incoming data |
|
1316 | - $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
1317 | - $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]); |
|
1318 | - // use the start date of the first datetime for the end date |
|
1319 | - $first_datetime = $event->first_datetime(); |
|
1320 | - $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]); |
|
1321 | - |
|
1322 | - // now process the incoming data |
|
1323 | - foreach ($data['edit_tickets'] as $row => $ticket_data) { |
|
1324 | - $update_prices = false; |
|
1325 | - $ticket_price = $data['edit_prices'][ $row ][1]['PRC_amount'] ?? 0; |
|
1326 | - // trim inputs to ensure any excess whitespace is removed. |
|
1327 | - $ticket_data = array_map('trim', $ticket_data); |
|
1328 | - $ticket_values = [ |
|
1329 | - 'TKT_ID' => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null, |
|
1330 | - 'TTM_ID' => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0, |
|
1331 | - 'TKT_name' => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '', |
|
1332 | - 'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '', |
|
1333 | - 'TKT_start_date' => ! empty($ticket_data['TKT_start_date']) |
|
1334 | - ? $ticket_data['TKT_start_date'] |
|
1335 | - : $default_start_date, |
|
1336 | - 'TKT_end_date' => ! empty($ticket_data['TKT_end_date']) |
|
1337 | - ? $ticket_data['TKT_end_date'] |
|
1338 | - : $default_end_date, |
|
1339 | - 'TKT_qty' => ! empty($ticket_data['TKT_qty']) |
|
1340 | - || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0) |
|
1341 | - ? $ticket_data['TKT_qty'] |
|
1342 | - : EE_INF, |
|
1343 | - 'TKT_uses' => ! empty($ticket_data['TKT_uses']) |
|
1344 | - || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0) |
|
1345 | - ? $ticket_data['TKT_uses'] |
|
1346 | - : EE_INF, |
|
1347 | - 'TKT_min' => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0, |
|
1348 | - 'TKT_max' => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF, |
|
1349 | - 'TKT_order' => $ticket_data['TKT_order'] ?? $row, |
|
1350 | - 'TKT_price' => $ticket_price, |
|
1351 | - 'TKT_row' => $row, |
|
1352 | - ]; |
|
1353 | - // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly, |
|
1354 | - // which means in turn that the prices will become new prices as well. |
|
1355 | - if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) { |
|
1356 | - $ticket_values['TKT_ID'] = 0; |
|
1357 | - $ticket_values['TKT_is_default'] = 0; |
|
1358 | - $update_prices = true; |
|
1359 | - } |
|
1360 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
1361 | - // we actually do our saves ahead of adding any relations because its entirely possible that this |
|
1362 | - // ticket didn't get removed or added to any datetime in the session but DID have it's items modified. |
|
1363 | - // keep in mind that if the ticket has been sold (and we have changed pricing information), |
|
1364 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
1365 | - if (! empty($ticket_data['TKT_ID'])) { |
|
1366 | - $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']); |
|
1367 | - if (! $existing_ticket instanceof EE_Ticket) { |
|
1368 | - throw new RuntimeException( |
|
1369 | - sprintf( |
|
1370 | - esc_html__( |
|
1371 | - 'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d', |
|
1372 | - 'event_espresso' |
|
1373 | - ), |
|
1374 | - $ticket_data['TKT_ID'] |
|
1375 | - ) |
|
1376 | - ); |
|
1377 | - } |
|
1378 | - $ticket_sold = $existing_ticket->count_related( |
|
1379 | - 'Registration', |
|
1380 | - [ |
|
1381 | - [ |
|
1382 | - 'STS_ID' => [ |
|
1383 | - 'NOT IN', |
|
1384 | - [EEM_Registration::status_id_incomplete], |
|
1385 | - ], |
|
1386 | - ], |
|
1387 | - ] |
|
1388 | - ) > 0; |
|
1389 | - // let's just check the total price for the existing ticket and determine if it matches the new total price. |
|
1390 | - // if they are different then we create a new ticket (if $ticket_sold) |
|
1391 | - // if they aren't different then we go ahead and modify existing ticket. |
|
1392 | - $create_new_ticket = $ticket_sold |
|
1393 | - && $ticket_price !== $existing_ticket->price() |
|
1394 | - && ! $existing_ticket->deleted(); |
|
1395 | - $existing_ticket->set_date_format($date_formats[0]); |
|
1396 | - $existing_ticket->set_time_format($date_formats[1]); |
|
1397 | - // set new values |
|
1398 | - foreach ($ticket_values as $field => $value) { |
|
1399 | - if ($field == 'TKT_qty') { |
|
1400 | - $existing_ticket->set_qty($value); |
|
1401 | - } elseif ($field == 'TKT_price') { |
|
1402 | - $existing_ticket->set('TKT_price', $ticket_price); |
|
1403 | - } else { |
|
1404 | - $existing_ticket->set($field, $value); |
|
1405 | - } |
|
1406 | - } |
|
1407 | - $ticket = $existing_ticket; |
|
1408 | - // if $create_new_ticket is false then we can safely update the existing ticket. |
|
1409 | - // Otherwise we have to create a new ticket. |
|
1410 | - if ($create_new_ticket) { |
|
1411 | - // archive the old ticket first |
|
1412 | - $existing_ticket->set('TKT_deleted', 1); |
|
1413 | - $existing_ticket->save(); |
|
1414 | - // make sure this ticket is still recorded in our $saved_tickets |
|
1415 | - // so we don't run it through the regular trash routine. |
|
1416 | - $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket; |
|
1417 | - // create new ticket that's a copy of the existing except, |
|
1418 | - // (a new id of course and not archived) AND has the new TKT_price associated with it. |
|
1419 | - $new_ticket = clone $existing_ticket; |
|
1420 | - $new_ticket->set('TKT_ID', 0); |
|
1421 | - $new_ticket->set('TKT_deleted', 0); |
|
1422 | - $new_ticket->set('TKT_sold', 0); |
|
1423 | - // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
1424 | - $update_prices = true; |
|
1425 | - $ticket = $new_ticket; |
|
1426 | - } |
|
1427 | - } else { |
|
1428 | - // no TKT_id so a new ticket |
|
1429 | - $ticket_values['TKT_price'] = $ticket_price; |
|
1430 | - $ticket = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats); |
|
1431 | - $update_prices = true; |
|
1432 | - } |
|
1433 | - if (! $ticket instanceof EE_Ticket) { |
|
1434 | - throw new RuntimeException( |
|
1435 | - sprintf( |
|
1436 | - esc_html__( |
|
1437 | - 'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s', |
|
1438 | - 'event_espresso' |
|
1439 | - ), |
|
1440 | - print_r($ticket_values, true) |
|
1441 | - ) |
|
1442 | - ); |
|
1443 | - } |
|
1444 | - // cap ticket qty by datetime reg limits |
|
1445 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
1446 | - // update ticket. |
|
1447 | - $ticket->save(); |
|
1448 | - // before going any further make sure our dates are setup correctly |
|
1449 | - // so that the end date is always equal or greater than the start date. |
|
1450 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
1451 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
1452 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
1453 | - $ticket->save(); |
|
1454 | - } |
|
1455 | - // initially let's add the ticket to the datetime |
|
1456 | - $datetime->_add_relation_to($ticket, 'Ticket'); |
|
1457 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
1458 | - // add prices to ticket |
|
1459 | - $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ]) |
|
1460 | - ? $data['edit_prices'][ $row ] |
|
1461 | - : []; |
|
1462 | - $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices); |
|
1463 | - } |
|
1464 | - // however now we need to handle permanently deleting tickets via the ui. |
|
1465 | - // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. |
|
1466 | - // However, it does allow for deleting tickets that have no tickets sold, |
|
1467 | - // in which case we want to get rid of permanently because there is no need to save in db. |
|
1468 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets; |
|
1469 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
1470 | - foreach ($tickets_removed as $id) { |
|
1471 | - $id = absint($id); |
|
1472 | - // get the ticket for this id |
|
1473 | - $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id); |
|
1474 | - if (! $ticket_to_remove instanceof EE_Ticket) { |
|
1475 | - continue; |
|
1476 | - } |
|
1477 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
1478 | - // (remember this process can ONLY kick off if there are NO tickets sold) |
|
1479 | - $related_datetimes = $ticket_to_remove->get_many_related('Datetime'); |
|
1480 | - foreach ($related_datetimes as $related_datetime) { |
|
1481 | - $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime'); |
|
1482 | - } |
|
1483 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
1484 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
1485 | - $ticket_to_remove->delete_related_permanently('Price'); |
|
1486 | - // finally let's delete this ticket |
|
1487 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
1488 | - $ticket_to_remove->delete_permanently(); |
|
1489 | - } |
|
1490 | - return [$datetime, $saved_tickets]; |
|
1491 | - } |
|
1492 | - |
|
1493 | - |
|
1494 | - /** |
|
1495 | - * This attaches a list of given prices to a ticket. |
|
1496 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) |
|
1497 | - * because if there is a change in price information on a ticket, a new ticket is created anyways |
|
1498 | - * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket. |
|
1499 | - * |
|
1500 | - * @access private |
|
1501 | - * @param array $prices_data Array of prices from the form. |
|
1502 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
1503 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
1504 | - * @return void |
|
1505 | - * @throws EE_Error |
|
1506 | - * @throws ReflectionException |
|
1507 | - */ |
|
1508 | - private function _add_prices_to_ticket(array $prices_data, EE_Ticket $ticket, bool $new_prices = false) |
|
1509 | - { |
|
1510 | - $timezone = $ticket->get_timezone(); |
|
1511 | - foreach ($prices_data as $row => $price_data) { |
|
1512 | - $price_values = [ |
|
1513 | - 'PRC_ID' => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null, |
|
1514 | - 'PRT_ID' => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null, |
|
1515 | - 'PRC_amount' => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0, |
|
1516 | - 'PRC_name' => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '', |
|
1517 | - 'PRC_desc' => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '', |
|
1518 | - 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
1519 | - 'PRC_order' => $row, |
|
1520 | - ]; |
|
1521 | - if ($new_prices || empty($price_values['PRC_ID'])) { |
|
1522 | - $price_values['PRC_ID'] = 0; |
|
1523 | - $price = EE_Price::new_instance($price_values, $timezone); |
|
1524 | - } else { |
|
1525 | - $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']); |
|
1526 | - // update this price with new values |
|
1527 | - foreach ($price_values as $field => $new_price) { |
|
1528 | - $price->set($field, $new_price); |
|
1529 | - } |
|
1530 | - } |
|
1531 | - if (! $price instanceof EE_Price) { |
|
1532 | - throw new RuntimeException( |
|
1533 | - sprintf( |
|
1534 | - esc_html__( |
|
1535 | - 'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s', |
|
1536 | - 'event_espresso' |
|
1537 | - ), |
|
1538 | - print_r($price_values, true) |
|
1539 | - ) |
|
1540 | - ); |
|
1541 | - } |
|
1542 | - $price->save(); |
|
1543 | - $ticket->_add_relation_to($price, 'Price'); |
|
1544 | - } |
|
1545 | - } |
|
1546 | - |
|
1547 | - |
|
1548 | - /** |
|
1549 | - * Add in our autosave ajax handlers |
|
1550 | - * |
|
1551 | - */ |
|
1552 | - protected function _ee_autosave_create_new() |
|
1553 | - { |
|
1554 | - } |
|
1555 | - |
|
1556 | - |
|
1557 | - /** |
|
1558 | - * More autosave handlers. |
|
1559 | - */ |
|
1560 | - protected function _ee_autosave_edit() |
|
1561 | - { |
|
1562 | - } |
|
1563 | - |
|
1564 | - |
|
1565 | - /** |
|
1566 | - * @throws EE_Error |
|
1567 | - * @throws ReflectionException |
|
1568 | - */ |
|
1569 | - private function _generate_publish_box_extra_content() |
|
1570 | - { |
|
1571 | - // load formatter helper |
|
1572 | - // args for getting related registrations |
|
1573 | - $approved_query_args = [ |
|
1574 | - [ |
|
1575 | - 'REG_deleted' => 0, |
|
1576 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
1577 | - ], |
|
1578 | - ]; |
|
1579 | - $not_approved_query_args = [ |
|
1580 | - [ |
|
1581 | - 'REG_deleted' => 0, |
|
1582 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
1583 | - ], |
|
1584 | - ]; |
|
1585 | - $pending_payment_query_args = [ |
|
1586 | - [ |
|
1587 | - 'REG_deleted' => 0, |
|
1588 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
1589 | - ], |
|
1590 | - ]; |
|
1591 | - // publish box |
|
1592 | - $publish_box_extra_args = [ |
|
1593 | - 'view_approved_reg_url' => add_query_arg( |
|
1594 | - [ |
|
1595 | - 'action' => 'default', |
|
1596 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1597 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1598 | - 'use_filters' => true, |
|
1599 | - ], |
|
1600 | - REG_ADMIN_URL |
|
1601 | - ), |
|
1602 | - 'view_not_approved_reg_url' => add_query_arg( |
|
1603 | - [ |
|
1604 | - 'action' => 'default', |
|
1605 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1606 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1607 | - 'use_filters' => true, |
|
1608 | - ], |
|
1609 | - REG_ADMIN_URL |
|
1610 | - ), |
|
1611 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
1612 | - [ |
|
1613 | - 'action' => 'default', |
|
1614 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1615 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1616 | - 'use_filters' => true, |
|
1617 | - ], |
|
1618 | - REG_ADMIN_URL |
|
1619 | - ), |
|
1620 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
1621 | - 'Registration', |
|
1622 | - $approved_query_args |
|
1623 | - ), |
|
1624 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
1625 | - 'Registration', |
|
1626 | - $not_approved_query_args |
|
1627 | - ), |
|
1628 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
1629 | - 'Registration', |
|
1630 | - $pending_payment_query_args |
|
1631 | - ), |
|
1632 | - 'misc_pub_section_class' => apply_filters( |
|
1633 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
1634 | - 'misc-pub-section' |
|
1635 | - ), |
|
1636 | - ]; |
|
1637 | - ob_start(); |
|
1638 | - do_action( |
|
1639 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
1640 | - $this->_cpt_model_obj |
|
1641 | - ); |
|
1642 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
1643 | - // load template |
|
1644 | - EEH_Template::display_template( |
|
1645 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1646 | - $publish_box_extra_args |
|
1647 | - ); |
|
1648 | - } |
|
1649 | - |
|
1650 | - |
|
1651 | - /** |
|
1652 | - * @return EE_Event |
|
1653 | - */ |
|
1654 | - public function get_event_object() |
|
1655 | - { |
|
1656 | - return $this->_cpt_model_obj; |
|
1657 | - } |
|
1658 | - |
|
1659 | - |
|
1660 | - |
|
1661 | - |
|
1662 | - /** METABOXES * */ |
|
1663 | - /** |
|
1664 | - * _register_event_editor_meta_boxes |
|
1665 | - * add all metaboxes related to the event_editor |
|
1666 | - * |
|
1667 | - * @return void |
|
1668 | - * @throws EE_Error |
|
1669 | - * @throws ReflectionException |
|
1670 | - */ |
|
1671 | - protected function _register_event_editor_meta_boxes() |
|
1672 | - { |
|
1673 | - $this->verify_cpt_object(); |
|
1674 | - $use_advanced_editor = $this->admin_config->useAdvancedEditor(); |
|
1675 | - // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version |
|
1676 | - if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) { |
|
1677 | - $this->addMetaBox( |
|
1678 | - 'espresso_event_editor_event_options', |
|
1679 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
1680 | - [$this, 'registration_options_meta_box'], |
|
1681 | - $this->page_slug, |
|
1682 | - 'side' |
|
1683 | - ); |
|
1684 | - } |
|
1685 | - if (! $use_advanced_editor) { |
|
1686 | - $this->addMetaBox( |
|
1687 | - 'espresso_event_editor_tickets', |
|
1688 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
1689 | - [$this, 'ticket_metabox'], |
|
1690 | - $this->page_slug, |
|
1691 | - 'normal', |
|
1692 | - 'high' |
|
1693 | - ); |
|
1694 | - } elseif ($this->feature->allowed('use_reg_options_meta_box')) { |
|
1695 | - add_action( |
|
1696 | - 'add_meta_boxes_espresso_events', |
|
1697 | - function () { |
|
1698 | - global $current_screen; |
|
1699 | - remove_meta_box('authordiv', $current_screen, 'normal'); |
|
1700 | - }, |
|
1701 | - 99 |
|
1702 | - ); |
|
1703 | - } |
|
1704 | - // NOTE: if you're looking for other metaboxes in here, |
|
1705 | - // where a metabox has a related management page in the admin |
|
1706 | - // you will find it setup in the related management page's "_Hooks" file. |
|
1707 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
1708 | - } |
|
1709 | - |
|
1710 | - |
|
1711 | - /** |
|
1712 | - * @throws DomainException |
|
1713 | - * @throws EE_Error |
|
1714 | - * @throws ReflectionException |
|
1715 | - */ |
|
1716 | - public function ticket_metabox() |
|
1717 | - { |
|
1718 | - $existing_datetime_ids = $existing_ticket_ids = []; |
|
1719 | - // defaults for template args |
|
1720 | - $template_args = [ |
|
1721 | - 'ticket_rows' => '', |
|
1722 | - 'total_ticket_rows' => 1, |
|
1723 | - 'trash_icon' => 'dashicons dashicons-lock', |
|
1724 | - 'disabled' => '', |
|
1725 | - ]; |
|
1726 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
1727 | - /** |
|
1728 | - * 1. Start with retrieving Datetimes |
|
1729 | - * 2. Fore each datetime get related tickets |
|
1730 | - * 3. For each ticket get related prices |
|
1731 | - */ |
|
1732 | - /** @var EEM_Datetime $datetime_model */ |
|
1733 | - $datetime_model = EE_Registry::instance()->load_model('Datetime'); |
|
1734 | - /** @var EEM_Ticket $datetime_model */ |
|
1735 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1736 | - $times = $datetime_model->get_all_event_dates($event_id); |
|
1737 | - /** @type EE_Datetime $first_datetime */ |
|
1738 | - $first_datetime = reset($times); |
|
1739 | - // do we get related tickets? |
|
1740 | - if ( |
|
1741 | - $first_datetime instanceof EE_Datetime |
|
1742 | - && $first_datetime->ID() !== 0 |
|
1743 | - ) { |
|
1744 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
1745 | - $template_args['time'] = $first_datetime; |
|
1746 | - $related_tickets = $first_datetime->tickets( |
|
1747 | - [ |
|
1748 | - ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]], |
|
1749 | - 'default_where_conditions' => 'none', |
|
1750 | - ] |
|
1751 | - ); |
|
1752 | - if (! empty($related_tickets)) { |
|
1753 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
1754 | - $row = 0; |
|
1755 | - foreach ($related_tickets as $ticket) { |
|
1756 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
1757 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
1758 | - $row++; |
|
1759 | - } |
|
1760 | - } else { |
|
1761 | - $template_args['total_ticket_rows'] = 1; |
|
1762 | - /** @type EE_Ticket $ticket */ |
|
1763 | - $ticket = $ticket_model->create_default_object(); |
|
1764 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1765 | - } |
|
1766 | - } else { |
|
1767 | - $template_args['time'] = $times[0]; |
|
1768 | - /** @type EE_Ticket[] $tickets */ |
|
1769 | - $tickets = $ticket_model->get_all_default_tickets(); |
|
1770 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]); |
|
1771 | - // NOTE: we're just sending the first default row |
|
1772 | - // (decaf can't manage default tickets so this should be sufficient); |
|
1773 | - } |
|
1774 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
1775 | - 'event_editor_event_datetimes_help_tab' |
|
1776 | - ); |
|
1777 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
1778 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1779 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1780 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
1781 | - $ticket_model->create_default_object(), |
|
1782 | - true |
|
1783 | - ); |
|
1784 | - $template = apply_filters( |
|
1785 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
1786 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1787 | - ); |
|
1788 | - EEH_Template::display_template($template, $template_args); |
|
1789 | - } |
|
1790 | - |
|
1791 | - |
|
1792 | - /** |
|
1793 | - * Setup an individual ticket form for the decaf event editor page |
|
1794 | - * |
|
1795 | - * @access private |
|
1796 | - * @param EE_Ticket $ticket the ticket object |
|
1797 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
1798 | - * @param int $row |
|
1799 | - * @return string generated html for the ticket row. |
|
1800 | - * @throws EE_Error |
|
1801 | - * @throws ReflectionException |
|
1802 | - */ |
|
1803 | - private function _get_ticket_row(EE_Ticket $ticket, bool $skeleton = false, int $row = 0): string |
|
1804 | - { |
|
1805 | - $template_args = [ |
|
1806 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1807 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
1808 | - : '', |
|
1809 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
1810 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
1811 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
1812 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
1813 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
1814 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
1815 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1816 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1817 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
1818 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1819 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1820 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock', |
|
1821 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1822 | - : ' disabled=disabled', |
|
1823 | - ]; |
|
1824 | - $price = $ticket->ID() !== 0 |
|
1825 | - ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none']) |
|
1826 | - : null; |
|
1827 | - $price = $price instanceof EE_Price |
|
1828 | - ? $price |
|
1829 | - : EEM_Price::instance()->create_default_object(); |
|
1830 | - $price_args = [ |
|
1831 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1832 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
1833 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
1834 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
1835 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
1836 | - ]; |
|
1837 | - // make sure we have default start and end dates if skeleton |
|
1838 | - // handle rows that should NOT be empty |
|
1839 | - if (empty($template_args['TKT_start_date'])) { |
|
1840 | - // if empty then the start date will be now. |
|
1841 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
1842 | - } |
|
1843 | - if (empty($template_args['TKT_end_date'])) { |
|
1844 | - // get the earliest datetime (if present); |
|
1845 | - $earliest_datetime = $this->_cpt_model_obj->ID() > 0 |
|
1846 | - ? $this->_cpt_model_obj->get_first_related( |
|
1847 | - 'Datetime', |
|
1848 | - ['order_by' => ['DTT_EVT_start' => 'ASC']] |
|
1849 | - ) |
|
1850 | - : null; |
|
1851 | - $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime |
|
1852 | - ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a') |
|
1853 | - : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))); |
|
1854 | - } |
|
1855 | - $template_args = array_merge($template_args, $price_args); |
|
1856 | - $template = apply_filters( |
|
1857 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
1858 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1859 | - $ticket |
|
1860 | - ); |
|
1861 | - return EEH_Template::display_template($template, $template_args, true); |
|
1862 | - } |
|
1863 | - |
|
1864 | - |
|
1865 | - /** |
|
1866 | - * @throws EE_Error |
|
1867 | - * @throws ReflectionException |
|
1868 | - */ |
|
1869 | - public function registration_options_meta_box() |
|
1870 | - { |
|
1871 | - $yes_no_values = [ |
|
1872 | - ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')], |
|
1873 | - ['id' => false, 'text' => esc_html__('No', 'event_espresso')], |
|
1874 | - ]; |
|
1875 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
1876 | - [ |
|
1877 | - EEM_Registration::status_id_cancelled, |
|
1878 | - EEM_Registration::status_id_declined, |
|
1879 | - EEM_Registration::status_id_incomplete, |
|
1880 | - ], |
|
1881 | - true |
|
1882 | - ); |
|
1883 | - // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
1884 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
1885 | - $template_args['event'] = $this->_cpt_model_obj; |
|
1886 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
1887 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
1888 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
1889 | - 'default_reg_status', |
|
1890 | - $default_reg_status_values, |
|
1891 | - $this->_cpt_model_obj->default_registration_status() |
|
1892 | - ); |
|
1893 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
1894 | - 'display_desc', |
|
1895 | - $yes_no_values, |
|
1896 | - $this->_cpt_model_obj->display_description() |
|
1897 | - ); |
|
1898 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
1899 | - 'display_ticket_selector', |
|
1900 | - $yes_no_values, |
|
1901 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
1902 | - '', |
|
1903 | - '', |
|
1904 | - false |
|
1905 | - ); |
|
1906 | - $template_args['additional_registration_options'] = apply_filters( |
|
1907 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
1908 | - '', |
|
1909 | - $template_args, |
|
1910 | - $yes_no_values, |
|
1911 | - $default_reg_status_values |
|
1912 | - ); |
|
1913 | - EEH_Template::display_template( |
|
1914 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1915 | - $template_args |
|
1916 | - ); |
|
1917 | - } |
|
1918 | - |
|
1919 | - |
|
1920 | - /** |
|
1921 | - * _get_events() |
|
1922 | - * This method simply returns all the events (for the given _view and paging) |
|
1923 | - * |
|
1924 | - * @access public |
|
1925 | - * @param int $per_page count of items per page (20 default); |
|
1926 | - * @param int $current_page what is the current page being viewed. |
|
1927 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
1928 | - * If FALSE then we return an array of event objects |
|
1929 | - * that match the given _view and paging parameters. |
|
1930 | - * @return array|int an array of event objects or a count of them. |
|
1931 | - * @throws Exception |
|
1932 | - */ |
|
1933 | - public function get_events(int $per_page = 10, int $current_page = 1, bool $count = false) |
|
1934 | - { |
|
1935 | - $EEM_Event = $this->_event_model(); |
|
1936 | - $offset = ($current_page - 1) * $per_page; |
|
1937 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
1938 | - $orderby = $this->request->getRequestParam('orderby', 'EVT_ID'); |
|
1939 | - $order = $this->request->getRequestParam('order', 'DESC'); |
|
1940 | - $month_range = $this->request->getRequestParam('month_range'); |
|
1941 | - if ($month_range) { |
|
1942 | - $pieces = explode(' ', $month_range, 3); |
|
1943 | - // simulate the FIRST day of the month, that fixes issues for months like February |
|
1944 | - // where PHP doesn't know what to assume for date. |
|
1945 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
1946 | - $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
1947 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1948 | - } |
|
1949 | - $where = []; |
|
1950 | - $status = $this->request->getRequestParam('status'); |
|
1951 | - // determine what post_status our condition will have for the query. |
|
1952 | - switch ($status) { |
|
1953 | - case 'month': |
|
1954 | - case 'today': |
|
1955 | - case null: |
|
1956 | - case 'all': |
|
1957 | - break; |
|
1958 | - case 'draft': |
|
1959 | - $where['status'] = ['IN', ['draft', 'auto-draft']]; |
|
1960 | - break; |
|
1961 | - default: |
|
1962 | - $where['status'] = $status; |
|
1963 | - } |
|
1964 | - // categories? The default for all categories is -1 |
|
1965 | - $category = $this->request->getRequestParam('EVT_CAT', -1, DataType::INT); |
|
1966 | - if ($category !== -1) { |
|
1967 | - $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
1968 | - $where['Term_Taxonomy.term_id'] = $category; |
|
1969 | - } |
|
1970 | - // date where conditions |
|
1971 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1972 | - if ($month_range) { |
|
1973 | - $DateTime = new DateTime( |
|
1974 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
1975 | - new DateTimeZone('UTC') |
|
1976 | - ); |
|
1977 | - $start = $DateTime->getTimestamp(); |
|
1978 | - // set the datetime to be the end of the month |
|
1979 | - $DateTime->setDate( |
|
1980 | - $year_r, |
|
1981 | - $month_r, |
|
1982 | - $DateTime->format('t') |
|
1983 | - )->setTime(23, 59, 59); |
|
1984 | - $end = $DateTime->getTimestamp(); |
|
1985 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
1986 | - } elseif ($status === 'today') { |
|
1987 | - $DateTime = |
|
1988 | - new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1989 | - $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
1990 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1991 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
1992 | - } elseif ($status === 'month') { |
|
1993 | - $now = date('Y-m-01'); |
|
1994 | - $DateTime = |
|
1995 | - new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1996 | - $start = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats)); |
|
1997 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
1998 | - ->setTime(23, 59, 59) |
|
1999 | - ->format(implode(' ', $start_formats)); |
|
2000 | - $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]]; |
|
2001 | - } |
|
2002 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
2003 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
2004 | - } else { |
|
2005 | - if (! isset($where['status'])) { |
|
2006 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
2007 | - $where['OR'] = [ |
|
2008 | - 'status*restrict_private' => ['!=', 'private'], |
|
2009 | - 'AND' => [ |
|
2010 | - 'status*inclusive' => ['=', 'private'], |
|
2011 | - 'EVT_wp_user' => get_current_user_id(), |
|
2012 | - ], |
|
2013 | - ]; |
|
2014 | - } |
|
2015 | - } |
|
2016 | - } |
|
2017 | - $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, DataType::INT); |
|
2018 | - if ( |
|
2019 | - $wp_user |
|
2020 | - && $wp_user !== get_current_user_id() |
|
2021 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
2022 | - ) { |
|
2023 | - $where['EVT_wp_user'] = $wp_user; |
|
2024 | - } |
|
2025 | - // search query handling |
|
2026 | - $search_term = $this->request->getRequestParam('s'); |
|
2027 | - if ($search_term) { |
|
2028 | - $search_term = '%' . $search_term . '%'; |
|
2029 | - $where['OR'] = [ |
|
2030 | - 'EVT_name' => ['LIKE', $search_term], |
|
2031 | - 'EVT_desc' => ['LIKE', $search_term], |
|
2032 | - 'EVT_short_desc' => ['LIKE', $search_term], |
|
2033 | - ]; |
|
2034 | - } |
|
2035 | - // filter events by venue. |
|
2036 | - $venue = $this->request->getRequestParam('venue', 0, DataType::INT); |
|
2037 | - if ($venue) { |
|
2038 | - $where['Venue.VNU_ID'] = $venue; |
|
2039 | - } |
|
2040 | - $request_params = $this->request->requestParams(); |
|
2041 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params); |
|
2042 | - $query_params = apply_filters( |
|
2043 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
2044 | - [ |
|
2045 | - $where, |
|
2046 | - 'limit' => $limit, |
|
2047 | - 'order_by' => $orderby, |
|
2048 | - 'order' => $order, |
|
2049 | - 'group_by' => 'EVT_ID', |
|
2050 | - ], |
|
2051 | - $request_params |
|
2052 | - ); |
|
2053 | - |
|
2054 | - // let's first check if we have special requests coming in. |
|
2055 | - $active_status = $this->request->getRequestParam('active_status'); |
|
2056 | - if ($active_status) { |
|
2057 | - switch ($active_status) { |
|
2058 | - case 'upcoming': |
|
2059 | - return $EEM_Event->get_upcoming_events($query_params, $count); |
|
2060 | - case 'expired': |
|
2061 | - return $EEM_Event->get_expired_events($query_params, $count); |
|
2062 | - case 'active': |
|
2063 | - return $EEM_Event->get_active_events($query_params, $count); |
|
2064 | - case 'inactive': |
|
2065 | - return $EEM_Event->get_inactive_events($query_params, $count); |
|
2066 | - } |
|
2067 | - } |
|
2068 | - |
|
2069 | - return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params); |
|
2070 | - } |
|
2071 | - |
|
2072 | - |
|
2073 | - /** |
|
2074 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
2075 | - * |
|
2076 | - * @param string $post_id |
|
2077 | - * @throws EE_Error |
|
2078 | - * @throws ReflectionException |
|
2079 | - */ |
|
2080 | - public function trash_cpt_item($post_id) |
|
2081 | - { |
|
2082 | - $this->request->setRequestParam('EVT_ID', $post_id); |
|
2083 | - $this->_trash_or_restore_event('trash', false); |
|
2084 | - } |
|
2085 | - |
|
2086 | - |
|
2087 | - /** |
|
2088 | - * @param string $post_id |
|
2089 | - * @throws EE_Error |
|
2090 | - * @throws ReflectionException |
|
2091 | - */ |
|
2092 | - public function restore_cpt_item($post_id) |
|
2093 | - { |
|
2094 | - $this->request->setRequestParam('EVT_ID', $post_id); |
|
2095 | - $this->_trash_or_restore_event('draft', false); |
|
2096 | - } |
|
2097 | - |
|
2098 | - |
|
2099 | - /** |
|
2100 | - * @param string $post_id |
|
2101 | - * @throws EE_Error |
|
2102 | - * @throws EE_Error |
|
2103 | - */ |
|
2104 | - public function delete_cpt_item($post_id) |
|
2105 | - { |
|
2106 | - throw new EE_Error( |
|
2107 | - esc_html__( |
|
2108 | - 'Please contact Event Espresso support with the details of the steps taken to produce this error.', |
|
2109 | - 'event_espresso' |
|
2110 | - ) |
|
2111 | - ); |
|
2112 | - // $this->request->setRequestParam('EVT_ID', $post_id); |
|
2113 | - // $this->_delete_event(); |
|
2114 | - } |
|
2115 | - |
|
2116 | - |
|
2117 | - /** |
|
2118 | - * _trash_or_restore_event |
|
2119 | - * |
|
2120 | - * @access protected |
|
2121 | - * @param string $event_status |
|
2122 | - * @param bool $redirect_after |
|
2123 | - * @throws EE_Error |
|
2124 | - * @throws EE_Error |
|
2125 | - * @throws ReflectionException |
|
2126 | - */ |
|
2127 | - protected function _trash_or_restore_event(string $event_status = 'trash', bool $redirect_after = true) |
|
2128 | - { |
|
2129 | - // determine the event id and set to array. |
|
2130 | - $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT); |
|
2131 | - // loop thru events |
|
2132 | - if ($EVT_ID) { |
|
2133 | - // clean status |
|
2134 | - $event_status = sanitize_key($event_status); |
|
2135 | - // grab status |
|
2136 | - if (! empty($event_status)) { |
|
2137 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
2138 | - } else { |
|
2139 | - $success = false; |
|
2140 | - $msg = esc_html__( |
|
2141 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2142 | - 'event_espresso' |
|
2143 | - ); |
|
2144 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2145 | - } |
|
2146 | - } else { |
|
2147 | - $success = false; |
|
2148 | - $msg = esc_html__( |
|
2149 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
2150 | - 'event_espresso' |
|
2151 | - ); |
|
2152 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2153 | - } |
|
2154 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2155 | - if ($redirect_after) { |
|
2156 | - $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']); |
|
2157 | - } |
|
2158 | - } |
|
2159 | - |
|
2160 | - |
|
2161 | - /** |
|
2162 | - * _trash_or_restore_events |
|
2163 | - * |
|
2164 | - * @access protected |
|
2165 | - * @param string $event_status |
|
2166 | - * @return void |
|
2167 | - * @throws EE_Error |
|
2168 | - * @throws EE_Error |
|
2169 | - * @throws ReflectionException |
|
2170 | - */ |
|
2171 | - protected function _trash_or_restore_events(string $event_status = 'trash') |
|
2172 | - { |
|
2173 | - // clean status |
|
2174 | - $event_status = sanitize_key($event_status); |
|
2175 | - // grab status |
|
2176 | - if (! empty($event_status)) { |
|
2177 | - $success = true; |
|
2178 | - // determine the event id and set to array. |
|
2179 | - $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
2180 | - // loop thru events |
|
2181 | - foreach ($EVT_IDs as $EVT_ID) { |
|
2182 | - if ($EVT_ID = absint($EVT_ID)) { |
|
2183 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
2184 | - $success = $results !== false ? $success : false; |
|
2185 | - } else { |
|
2186 | - $msg = sprintf( |
|
2187 | - esc_html__( |
|
2188 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
2189 | - 'event_espresso' |
|
2190 | - ), |
|
2191 | - $EVT_ID |
|
2192 | - ); |
|
2193 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2194 | - $success = false; |
|
2195 | - } |
|
2196 | - } |
|
2197 | - } else { |
|
2198 | - $success = false; |
|
2199 | - $msg = esc_html__( |
|
2200 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2201 | - 'event_espresso' |
|
2202 | - ); |
|
2203 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2204 | - } |
|
2205 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2206 | - $success = $success ? 2 : false; |
|
2207 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2208 | - $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']); |
|
2209 | - } |
|
2210 | - |
|
2211 | - |
|
2212 | - /** |
|
2213 | - * @param int $EVT_ID |
|
2214 | - * @param string $event_status |
|
2215 | - * @return bool |
|
2216 | - * @throws EE_Error |
|
2217 | - * @throws ReflectionException |
|
2218 | - */ |
|
2219 | - private function _change_event_status(int $EVT_ID = 0, string $event_status = ''): bool |
|
2220 | - { |
|
2221 | - // grab event id |
|
2222 | - if (! $EVT_ID) { |
|
2223 | - $msg = esc_html__( |
|
2224 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2225 | - 'event_espresso' |
|
2226 | - ); |
|
2227 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2228 | - return false; |
|
2229 | - } |
|
2230 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2231 | - // clean status |
|
2232 | - $event_status = sanitize_key($event_status); |
|
2233 | - // grab status |
|
2234 | - if (empty($event_status)) { |
|
2235 | - $msg = esc_html__( |
|
2236 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
2237 | - 'event_espresso' |
|
2238 | - ); |
|
2239 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2240 | - return false; |
|
2241 | - } |
|
2242 | - // was event trashed or restored ? |
|
2243 | - switch ($event_status) { |
|
2244 | - case 'draft': |
|
2245 | - $action = 'restored from the trash'; |
|
2246 | - $hook = 'AHEE_event_restored_from_trash'; |
|
2247 | - break; |
|
2248 | - case 'trash': |
|
2249 | - $action = 'moved to the trash'; |
|
2250 | - $hook = 'AHEE_event_moved_to_trash'; |
|
2251 | - break; |
|
2252 | - default: |
|
2253 | - $action = 'updated'; |
|
2254 | - $hook = false; |
|
2255 | - } |
|
2256 | - // use class to change status |
|
2257 | - $this->_cpt_model_obj->set_status($event_status); |
|
2258 | - $success = $this->_cpt_model_obj->save(); |
|
2259 | - if (! $success) { |
|
2260 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
2261 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2262 | - return false; |
|
2263 | - } |
|
2264 | - if ($hook) { |
|
2265 | - do_action($hook); |
|
2266 | - // fake the action hook in EE_Soft_Delete_Base_Class::delete_or_restore() |
|
2267 | - // because events side step that and it otherwise won't get called |
|
2268 | - do_action( |
|
2269 | - 'AHEE__EE_Soft_Delete_Base_Class__delete_or_restore__after', |
|
2270 | - $this->_cpt_model_obj, |
|
2271 | - $hook === 'AHEE_event_moved_to_trash', |
|
2272 | - $success |
|
2273 | - ); |
|
2274 | - } |
|
2275 | - return true; |
|
2276 | - } |
|
2277 | - |
|
2278 | - |
|
2279 | - /** |
|
2280 | - * @param array $event_ids |
|
2281 | - * @return array |
|
2282 | - * @since 4.10.23.p |
|
2283 | - */ |
|
2284 | - private function cleanEventIds(array $event_ids): array |
|
2285 | - { |
|
2286 | - return array_map('absint', $event_ids); |
|
2287 | - } |
|
2288 | - |
|
2289 | - |
|
2290 | - /** |
|
2291 | - * @return array |
|
2292 | - * @since 4.10.23.p |
|
2293 | - */ |
|
2294 | - private function getEventIdsFromRequest(): array |
|
2295 | - { |
|
2296 | - if ($this->request->requestParamIsSet('EVT_IDs')) { |
|
2297 | - return $this->request->getRequestParam('EVT_IDs', [], 'int', true); |
|
2298 | - } else { |
|
2299 | - return $this->request->getRequestParam('EVT_ID', [], 'int', true); |
|
2300 | - } |
|
2301 | - } |
|
2302 | - |
|
2303 | - |
|
2304 | - /** |
|
2305 | - * @param bool $preview_delete |
|
2306 | - * @throws EE_Error |
|
2307 | - * @throws ReflectionException |
|
2308 | - */ |
|
2309 | - protected function _delete_event(bool $preview_delete = true) |
|
2310 | - { |
|
2311 | - $this->_delete_events($preview_delete); |
|
2312 | - } |
|
2313 | - |
|
2314 | - |
|
2315 | - /** |
|
2316 | - * Gets the tree traversal batch persister. |
|
2317 | - * |
|
2318 | - * @return NodeGroupDao |
|
2319 | - * @throws InvalidArgumentException |
|
2320 | - * @throws InvalidDataTypeException |
|
2321 | - * @throws InvalidInterfaceException |
|
2322 | - * @since 4.10.12.p |
|
2323 | - */ |
|
2324 | - protected function getModelObjNodeGroupPersister(): NodeGroupDao |
|
2325 | - { |
|
2326 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
2327 | - $this->model_obj_node_group_persister = |
|
2328 | - $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
2329 | - } |
|
2330 | - return $this->model_obj_node_group_persister; |
|
2331 | - } |
|
2332 | - |
|
2333 | - |
|
2334 | - /** |
|
2335 | - * @param bool $preview_delete |
|
2336 | - * @return void |
|
2337 | - * @throws EE_Error |
|
2338 | - * @throws ReflectionException |
|
2339 | - */ |
|
2340 | - protected function _delete_events(bool $preview_delete = true) |
|
2341 | - { |
|
2342 | - $event_ids = $this->getEventIdsFromRequest(); |
|
2343 | - if ($preview_delete) { |
|
2344 | - $this->generateDeletionPreview($event_ids); |
|
2345 | - } else { |
|
2346 | - foreach ($event_ids as $event_id) { |
|
2347 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
2348 | - if ($event instanceof EE_Event) { |
|
2349 | - $event->delete_permanently(); |
|
2350 | - } |
|
2351 | - } |
|
2352 | - } |
|
2353 | - } |
|
2354 | - |
|
2355 | - |
|
2356 | - /** |
|
2357 | - * @param array $event_ids |
|
2358 | - */ |
|
2359 | - protected function generateDeletionPreview(array $event_ids) |
|
2360 | - { |
|
2361 | - $event_ids = $this->cleanEventIds($event_ids); |
|
2362 | - // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
2363 | - $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
2364 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
2365 | - [ |
|
2366 | - 'action' => 'preview_deletion', |
|
2367 | - 'deletion_job_code' => $deletion_job_code, |
|
2368 | - ], |
|
2369 | - $this->_admin_base_url |
|
2370 | - ); |
|
2371 | - EEH_URL::safeRedirectAndExit( |
|
2372 | - EE_Admin_Page::add_query_args_and_nonce( |
|
2373 | - [ |
|
2374 | - 'page' => EED_Batch::PAGE_SLUG, |
|
2375 | - 'batch' => EED_Batch::batch_job, |
|
2376 | - 'EVT_IDs' => $event_ids, |
|
2377 | - 'deletion_job_code' => $deletion_job_code, |
|
2378 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
2379 | - 'return_url' => urlencode($return_url), |
|
2380 | - ], |
|
2381 | - admin_url() |
|
2382 | - ) |
|
2383 | - ); |
|
2384 | - } |
|
2385 | - |
|
2386 | - |
|
2387 | - /** |
|
2388 | - * Checks for a POST submission |
|
2389 | - * |
|
2390 | - * @since 4.10.12.p |
|
2391 | - */ |
|
2392 | - protected function confirmDeletion() |
|
2393 | - { |
|
2394 | - $deletion_redirect_logic = $this->getLoader()->getShared( |
|
2395 | - 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' |
|
2396 | - ); |
|
2397 | - $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
2398 | - } |
|
2399 | - |
|
2400 | - |
|
2401 | - /** |
|
2402 | - * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
2403 | - * |
|
2404 | - * @throws EE_Error |
|
2405 | - * @since 4.10.12.p |
|
2406 | - */ |
|
2407 | - protected function previewDeletion() |
|
2408 | - { |
|
2409 | - $preview_deletion_logic = $this->getLoader()->getShared( |
|
2410 | - 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' |
|
2411 | - ); |
|
2412 | - $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
2413 | - $this->display_admin_page_with_no_sidebar(); |
|
2414 | - } |
|
2415 | - |
|
2416 | - |
|
2417 | - /** |
|
2418 | - * get total number of events |
|
2419 | - * |
|
2420 | - * @access public |
|
2421 | - * @return int |
|
2422 | - * @throws EE_Error |
|
2423 | - * @throws EE_Error |
|
2424 | - * @throws ReflectionException |
|
2425 | - */ |
|
2426 | - public function total_events(): int |
|
2427 | - { |
|
2428 | - return EEM_Event::instance()->count( |
|
2429 | - ['caps' => 'read_admin'], |
|
2430 | - 'EVT_ID', |
|
2431 | - true |
|
2432 | - ); |
|
2433 | - } |
|
2434 | - |
|
2435 | - |
|
2436 | - /** |
|
2437 | - * get total number of draft events |
|
2438 | - * |
|
2439 | - * @access public |
|
2440 | - * @return int |
|
2441 | - * @throws EE_Error |
|
2442 | - * @throws EE_Error |
|
2443 | - * @throws ReflectionException |
|
2444 | - */ |
|
2445 | - public function total_events_draft(): int |
|
2446 | - { |
|
2447 | - return EEM_Event::instance()->count( |
|
2448 | - [ |
|
2449 | - ['status' => ['IN', ['draft', 'auto-draft']]], |
|
2450 | - 'caps' => 'read_admin', |
|
2451 | - ], |
|
2452 | - 'EVT_ID', |
|
2453 | - true |
|
2454 | - ); |
|
2455 | - } |
|
2456 | - |
|
2457 | - |
|
2458 | - /** |
|
2459 | - * get total number of trashed events |
|
2460 | - * |
|
2461 | - * @access public |
|
2462 | - * @return int |
|
2463 | - * @throws EE_Error |
|
2464 | - * @throws EE_Error |
|
2465 | - * @throws ReflectionException |
|
2466 | - */ |
|
2467 | - public function total_trashed_events(): int |
|
2468 | - { |
|
2469 | - return EEM_Event::instance()->count( |
|
2470 | - [ |
|
2471 | - ['status' => 'trash'], |
|
2472 | - 'caps' => 'read_admin', |
|
2473 | - ], |
|
2474 | - 'EVT_ID', |
|
2475 | - true |
|
2476 | - ); |
|
2477 | - } |
|
2478 | - |
|
2479 | - |
|
2480 | - /** |
|
2481 | - * _default_event_settings |
|
2482 | - * This generates the Default Settings Tab |
|
2483 | - * |
|
2484 | - * @return void |
|
2485 | - * @throws DomainException |
|
2486 | - * @throws EE_Error |
|
2487 | - * @throws InvalidArgumentException |
|
2488 | - * @throws InvalidDataTypeException |
|
2489 | - * @throws InvalidInterfaceException |
|
2490 | - */ |
|
2491 | - protected function _default_event_settings() |
|
2492 | - { |
|
2493 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
2494 | - $this->_set_publish_post_box_vars(); |
|
2495 | - $this->_template_args['admin_page_content'] = EEH_HTML::div( |
|
2496 | - $this->_default_event_settings_form()->get_html(), |
|
2497 | - '', |
|
2498 | - 'padding' |
|
2499 | - ); |
|
2500 | - $this->display_admin_page_with_sidebar(); |
|
2501 | - } |
|
2502 | - |
|
2503 | - |
|
2504 | - /** |
|
2505 | - * Return the form for event settings. |
|
2506 | - * |
|
2507 | - * @return EE_Form_Section_Proper |
|
2508 | - * @throws EE_Error |
|
2509 | - */ |
|
2510 | - protected function _default_event_settings_form(): EE_Form_Section_Proper |
|
2511 | - { |
|
2512 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
2513 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
2514 | - // exclude |
|
2515 | - [ |
|
2516 | - EEM_Registration::status_id_cancelled, |
|
2517 | - EEM_Registration::status_id_declined, |
|
2518 | - EEM_Registration::status_id_incomplete, |
|
2519 | - EEM_Registration::status_id_wait_list, |
|
2520 | - ], |
|
2521 | - true |
|
2522 | - ); |
|
2523 | - // setup Advanced Editor ??? |
|
2524 | - if ( |
|
2525 | - $this->raw_req_action === 'default_event_settings' |
|
2526 | - || $this->raw_req_action === 'update_default_event_settings' |
|
2527 | - ) { |
|
2528 | - $this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class); |
|
2529 | - } |
|
2530 | - return new EE_Form_Section_Proper( |
|
2531 | - [ |
|
2532 | - 'name' => 'update_default_event_settings', |
|
2533 | - 'html_id' => 'update_default_event_settings', |
|
2534 | - 'html_class' => 'form-table', |
|
2535 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
2536 | - 'subsections' => apply_filters( |
|
2537 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
2538 | - [ |
|
2539 | - 'defaults_section_header' => new EE_Form_Section_HTML( |
|
2540 | - EEH_HTML::h2( |
|
2541 | - esc_html__('Default Settings', 'event_espresso'), |
|
2542 | - '', |
|
2543 | - 'ee-admin-settings-hdr' |
|
2544 | - ) |
|
2545 | - ), |
|
2546 | - 'default_reg_status' => new EE_Select_Input( |
|
2547 | - $registration_stati_for_selection, |
|
2548 | - [ |
|
2549 | - 'default' => isset($registration_config->default_STS_ID) |
|
2550 | - && array_key_exists( |
|
2551 | - $registration_config->default_STS_ID, |
|
2552 | - $registration_stati_for_selection |
|
2553 | - ) |
|
2554 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
2555 | - : EEM_Registration::status_id_pending_payment, |
|
2556 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
2557 | - . EEH_Template::get_help_tab_link( |
|
2558 | - 'default_settings_status_help_tab' |
|
2559 | - ), |
|
2560 | - 'html_help_text' => esc_html__( |
|
2561 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
2562 | - 'event_espresso' |
|
2563 | - ), |
|
2564 | - ] |
|
2565 | - ), |
|
2566 | - 'default_max_tickets' => new EE_Integer_Input( |
|
2567 | - [ |
|
2568 | - 'default' => $registration_config->default_maximum_number_of_tickets |
|
2569 | - ?? EEM_Event::get_default_additional_limit(), |
|
2570 | - 'html_label_text' => esc_html__( |
|
2571 | - 'Default Maximum Tickets Allowed Per Order:', |
|
2572 | - 'event_espresso' |
|
2573 | - ) |
|
2574 | - . EEH_Template::get_help_tab_link( |
|
2575 | - 'default_maximum_tickets_help_tab"' |
|
2576 | - ), |
|
2577 | - 'html_help_text' => esc_html__( |
|
2578 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
2579 | - 'event_espresso' |
|
2580 | - ), |
|
2581 | - ] |
|
2582 | - ), |
|
2583 | - ] |
|
2584 | - ), |
|
2585 | - ] |
|
2586 | - ); |
|
2587 | - } |
|
2588 | - |
|
2589 | - |
|
2590 | - /** |
|
2591 | - * @return void |
|
2592 | - * @throws EE_Error |
|
2593 | - * @throws InvalidArgumentException |
|
2594 | - * @throws InvalidDataTypeException |
|
2595 | - * @throws InvalidInterfaceException |
|
2596 | - */ |
|
2597 | - protected function _update_default_event_settings() |
|
2598 | - { |
|
2599 | - $form = $this->_default_event_settings_form(); |
|
2600 | - if ($form->was_submitted()) { |
|
2601 | - $form->receive_form_submission(); |
|
2602 | - if ($form->is_valid()) { |
|
2603 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
2604 | - $valid_data = $form->valid_data(); |
|
2605 | - if (isset($valid_data['default_reg_status'])) { |
|
2606 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
2607 | - } |
|
2608 | - if (isset($valid_data['default_max_tickets'])) { |
|
2609 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
2610 | - } |
|
2611 | - do_action( |
|
2612 | - 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
2613 | - $valid_data, |
|
2614 | - EE_Registry::instance()->CFG, |
|
2615 | - $this |
|
2616 | - ); |
|
2617 | - // update because data was valid! |
|
2618 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
2619 | - EE_Error::overwrite_success(); |
|
2620 | - EE_Error::add_success( |
|
2621 | - esc_html__('Default Event Settings were updated', 'event_espresso') |
|
2622 | - ); |
|
2623 | - } |
|
2624 | - } |
|
2625 | - $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true); |
|
2626 | - } |
|
2627 | - |
|
2628 | - |
|
2629 | - /************* Templates ************* |
|
2630 | - * |
|
2631 | - * @throws EE_Error |
|
2632 | - */ |
|
2633 | - protected function _template_settings() |
|
2634 | - { |
|
2635 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
2636 | - $this->_template_args['preview_img'] = '<img src="' |
|
2637 | - . EVENTS_ASSETS_URL |
|
2638 | - . '/images/' |
|
2639 | - . 'caffeinated_template_features.jpg" alt="' |
|
2640 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
2641 | - . '" />'; |
|
2642 | - $this->_template_args['preview_text'] = '<strong>' |
|
2643 | - . esc_html__( |
|
2644 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
2645 | - 'event_espresso' |
|
2646 | - ) . '</strong>'; |
|
2647 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2648 | - } |
|
2649 | - |
|
2650 | - |
|
2651 | - /** Event Category Stuff **/ |
|
2652 | - /** |
|
2653 | - * set the _category property with the category object for the loaded page. |
|
2654 | - * |
|
2655 | - * @access private |
|
2656 | - * @return void |
|
2657 | - */ |
|
2658 | - private function _set_category_object() |
|
2659 | - { |
|
2660 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
2661 | - return; |
|
2662 | - } //already have the category object so get out. |
|
2663 | - // set default category object |
|
2664 | - $this->_set_empty_category_object(); |
|
2665 | - // only set if we've got an id |
|
2666 | - $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
2667 | - if (! $category_ID) { |
|
2668 | - return; |
|
2669 | - } |
|
2670 | - $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2671 | - if (! empty($term)) { |
|
2672 | - $this->_category->category_name = $term->name; |
|
2673 | - $this->_category->category_identifier = $term->slug; |
|
2674 | - $this->_category->category_desc = $term->description; |
|
2675 | - $this->_category->id = $term->term_id; |
|
2676 | - $this->_category->parent = $term->parent; |
|
2677 | - } |
|
2678 | - } |
|
2679 | - |
|
2680 | - |
|
2681 | - /** |
|
2682 | - * Clears out category properties. |
|
2683 | - */ |
|
2684 | - private function _set_empty_category_object() |
|
2685 | - { |
|
2686 | - $this->_category = new stdClass(); |
|
2687 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2688 | - $this->_category->id = $this->_category->parent = 0; |
|
2689 | - } |
|
2690 | - |
|
2691 | - |
|
2692 | - /** |
|
2693 | - * @throws DomainException |
|
2694 | - * @throws EE_Error |
|
2695 | - * @throws InvalidArgumentException |
|
2696 | - * @throws InvalidDataTypeException |
|
2697 | - * @throws InvalidInterfaceException |
|
2698 | - */ |
|
2699 | - protected function _category_list_table() |
|
2700 | - { |
|
2701 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2702 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
2703 | - $this->_admin_page_title .= ' '; |
|
2704 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
2705 | - 'add_category', |
|
2706 | - 'add_category', |
|
2707 | - [], |
|
2708 | - 'add-new-h2' |
|
2709 | - ); |
|
2710 | - $this->display_admin_list_table_page_with_sidebar(); |
|
2711 | - } |
|
2712 | - |
|
2713 | - |
|
2714 | - /** |
|
2715 | - * Output category details view. |
|
2716 | - * |
|
2717 | - * @throws EE_Error |
|
2718 | - * @throws EE_Error |
|
2719 | - */ |
|
2720 | - protected function _category_details($view) |
|
2721 | - { |
|
2722 | - $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
2723 | - $this->_set_add_edit_form_tags($route); |
|
2724 | - $this->_set_category_object(); |
|
2725 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2726 | - $delete_action = 'delete_category'; |
|
2727 | - // custom redirect |
|
2728 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
2729 | - ['action' => 'category_list'], |
|
2730 | - $this->_admin_base_url |
|
2731 | - ); |
|
2732 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect, true); |
|
2733 | - // take care of contents |
|
2734 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
2735 | - $this->display_admin_page_with_sidebar(); |
|
2736 | - } |
|
2737 | - |
|
2738 | - |
|
2739 | - /** |
|
2740 | - * Output category details content. |
|
2741 | - * |
|
2742 | - * @throws DomainException |
|
2743 | - */ |
|
2744 | - protected function _category_details_content(): string |
|
2745 | - { |
|
2746 | - $editor_args['category_desc'] = [ |
|
2747 | - 'type' => 'wp_editor', |
|
2748 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
2749 | - 'class' => 'my_editor_custom', |
|
2750 | - 'wpeditor_args' => ['media_buttons' => false], |
|
2751 | - ]; |
|
2752 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2753 | - $all_terms = get_terms( |
|
2754 | - [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
2755 | - ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
2756 | - ); |
|
2757 | - // setup category select for term parents. |
|
2758 | - $category_select_values[] = [ |
|
2759 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
2760 | - 'id' => 0, |
|
2761 | - ]; |
|
2762 | - foreach ($all_terms as $term) { |
|
2763 | - $category_select_values[] = [ |
|
2764 | - 'text' => $term->name, |
|
2765 | - 'id' => $term->term_id, |
|
2766 | - ]; |
|
2767 | - } |
|
2768 | - $category_select = EEH_Form_Fields::select_input( |
|
2769 | - 'category_parent', |
|
2770 | - $category_select_values, |
|
2771 | - $this->_category->parent |
|
2772 | - ); |
|
2773 | - $template_args = [ |
|
2774 | - 'category' => $this->_category, |
|
2775 | - 'category_select' => $category_select, |
|
2776 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
2777 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
2778 | - 'disable' => '', |
|
2779 | - 'disabled_message' => false, |
|
2780 | - ]; |
|
2781 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2782 | - return EEH_Template::display_template($template, $template_args, true); |
|
2783 | - } |
|
2784 | - |
|
2785 | - |
|
2786 | - /** |
|
2787 | - * Handles deleting categories. |
|
2788 | - * |
|
2789 | - * @throws EE_Error |
|
2790 | - */ |
|
2791 | - protected function _delete_categories() |
|
2792 | - { |
|
2793 | - $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true); |
|
2794 | - foreach ($category_IDs as $category_ID) { |
|
2795 | - $this->_delete_category($category_ID); |
|
2796 | - } |
|
2797 | - // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
2798 | - $query_args = [ |
|
2799 | - 'action' => 'category_list', |
|
2800 | - ]; |
|
2801 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
2802 | - } |
|
2803 | - |
|
2804 | - |
|
2805 | - /** |
|
2806 | - * Handles deleting specific category. |
|
2807 | - * |
|
2808 | - * @param int $cat_id |
|
2809 | - */ |
|
2810 | - protected function _delete_category(int $cat_id) |
|
2811 | - { |
|
2812 | - $cat_id = absint($cat_id); |
|
2813 | - wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2814 | - } |
|
2815 | - |
|
2816 | - |
|
2817 | - /** |
|
2818 | - * Handles triggering the update or insertion of a new category. |
|
2819 | - * |
|
2820 | - * @param bool $new_category true means we're triggering the insert of a new category. |
|
2821 | - * @throws EE_Error |
|
2822 | - * @throws EE_Error |
|
2823 | - */ |
|
2824 | - protected function _insert_or_update_category(bool $new_category) |
|
2825 | - { |
|
2826 | - $cat_id = $this->_insert_category($new_category); |
|
2827 | - $success = 0; // we already have a success message so lets not send another. |
|
2828 | - if ($cat_id) { |
|
2829 | - $query_args = [ |
|
2830 | - 'action' => 'edit_category', |
|
2831 | - 'EVT_CAT_ID' => $cat_id, |
|
2832 | - ]; |
|
2833 | - } else { |
|
2834 | - $query_args = ['action' => 'add_category']; |
|
2835 | - } |
|
2836 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
2837 | - } |
|
2838 | - |
|
2839 | - |
|
2840 | - /** |
|
2841 | - * Inserts or updates category |
|
2842 | - * |
|
2843 | - * @param bool $new_category (true indicates we're updating a category). |
|
2844 | - * @return bool|mixed|string |
|
2845 | - */ |
|
2846 | - private function _insert_category(bool $new_category) |
|
2847 | - { |
|
2848 | - $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
2849 | - $category_name = $this->request->getRequestParam('category_name', ''); |
|
2850 | - $category_desc = $this->request->getRequestParam('category_desc', '', DataType::HTML); |
|
2851 | - $category_parent = $this->request->getRequestParam('category_parent', 0, DataType::INT); |
|
2852 | - $category_identifier = $this->request->getRequestParam('category_identifier', ''); |
|
2853 | - |
|
2854 | - if (empty($category_name)) { |
|
2855 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
2856 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2857 | - return 0; |
|
2858 | - } |
|
2859 | - $term_args = [ |
|
2860 | - 'name' => $category_name, |
|
2861 | - 'description' => $category_desc, |
|
2862 | - 'parent' => $category_parent, |
|
2863 | - ]; |
|
2864 | - // was the category_identifier input disabled? |
|
2865 | - if ($category_identifier) { |
|
2866 | - $term_args['slug'] = $category_identifier; |
|
2867 | - } |
|
2868 | - $insert_ids = $new_category |
|
2869 | - ? wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
2870 | - : wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
2871 | - |
|
2872 | - if ($insert_ids instanceof WP_Error) { |
|
2873 | - EE_Error::add_error($insert_ids->get_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
2874 | - return 0; |
|
2875 | - } |
|
2876 | - $category_ID = $insert_ids['term_id'] ?? 0; |
|
2877 | - if (! $category_ID) { |
|
2878 | - EE_Error::add_error( |
|
2879 | - esc_html__( |
|
2880 | - 'An error occurred and the category has not been saved to the database.', |
|
2881 | - 'event_espresso' |
|
2882 | - ), |
|
2883 | - __FILE__, |
|
2884 | - __FUNCTION__, |
|
2885 | - __LINE__ |
|
2886 | - ); |
|
2887 | - return 0; |
|
2888 | - } |
|
2889 | - EE_Error::add_success( |
|
2890 | - sprintf( |
|
2891 | - esc_html__('The category %s was successfully saved', 'event_espresso'), |
|
2892 | - $category_name |
|
2893 | - ) |
|
2894 | - ); |
|
2895 | - return $category_ID; |
|
2896 | - } |
|
2897 | - |
|
2898 | - |
|
2899 | - /** |
|
2900 | - * Gets categories or count of categories matching the arguments in the request. |
|
2901 | - * |
|
2902 | - * @param int $per_page |
|
2903 | - * @param int $current_page |
|
2904 | - * @param bool $count |
|
2905 | - * @return EE_Term_Taxonomy[]|int |
|
2906 | - * @throws EE_Error |
|
2907 | - * @throws ReflectionException |
|
2908 | - */ |
|
2909 | - public function get_categories(int $per_page = 10, int $current_page = 1, bool $count = false) |
|
2910 | - { |
|
2911 | - // testing term stuff |
|
2912 | - $orderby = $this->request->getRequestParam('orderby', 'Term.term_id'); |
|
2913 | - $order = $this->request->getRequestParam('order', 'DESC'); |
|
2914 | - $limit = ($current_page - 1) * $per_page; |
|
2915 | - $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
2916 | - $search_term = $this->request->getRequestParam('s'); |
|
2917 | - if ($search_term) { |
|
2918 | - $search_term = '%' . $search_term . '%'; |
|
2919 | - $where['OR'] = [ |
|
2920 | - 'Term.name' => ['LIKE', $search_term], |
|
2921 | - 'description' => ['LIKE', $search_term], |
|
2922 | - ]; |
|
2923 | - } |
|
2924 | - $query_params = [ |
|
2925 | - $where, |
|
2926 | - 'order_by' => [$orderby => $order], |
|
2927 | - 'limit' => $limit . ',' . $per_page, |
|
2928 | - 'force_join' => ['Term'], |
|
2929 | - ]; |
|
2930 | - return $count |
|
2931 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
2932 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2933 | - } |
|
2934 | - |
|
2935 | - /* end category stuff */ |
|
2936 | - |
|
2937 | - |
|
2938 | - /**************/ |
|
2939 | - |
|
2940 | - |
|
2941 | - /** |
|
2942 | - * Callback for the `ee_save_timezone_setting` ajax action. |
|
2943 | - * |
|
2944 | - * @throws EE_Error |
|
2945 | - * @throws InvalidArgumentException |
|
2946 | - * @throws InvalidDataTypeException |
|
2947 | - * @throws InvalidInterfaceException |
|
2948 | - */ |
|
2949 | - public function saveTimezoneString() |
|
2950 | - { |
|
2951 | - $timezone_string = $this->request->getRequestParam('timezone_selected'); |
|
2952 | - if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
2953 | - EE_Error::add_error( |
|
2954 | - esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
2955 | - __FILE__, |
|
2956 | - __FUNCTION__, |
|
2957 | - __LINE__ |
|
2958 | - ); |
|
2959 | - $this->_template_args['error'] = true; |
|
2960 | - $this->_return_json(); |
|
2961 | - } |
|
2962 | - |
|
2963 | - update_option('timezone_string', $timezone_string); |
|
2964 | - EE_Error::add_success( |
|
2965 | - esc_html__('Your timezone string was updated.', 'event_espresso') |
|
2966 | - ); |
|
2967 | - $this->_template_args['success'] = true; |
|
2968 | - $this->_return_json(true, ['action' => 'create_new']); |
|
2969 | - } |
|
2970 | - |
|
2971 | - |
|
2972 | - /** |
|
2973 | 2631 | * @throws EE_Error |
2974 | - * @deprecated 4.10.25.p |
|
2975 | 2632 | */ |
2976 | - public function save_timezonestring_setting() |
|
2977 | - { |
|
2978 | - $this->saveTimezoneString(); |
|
2979 | - } |
|
2633 | + protected function _template_settings() |
|
2634 | + { |
|
2635 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
2636 | + $this->_template_args['preview_img'] = '<img src="' |
|
2637 | + . EVENTS_ASSETS_URL |
|
2638 | + . '/images/' |
|
2639 | + . 'caffeinated_template_features.jpg" alt="' |
|
2640 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
2641 | + . '" />'; |
|
2642 | + $this->_template_args['preview_text'] = '<strong>' |
|
2643 | + . esc_html__( |
|
2644 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
2645 | + 'event_espresso' |
|
2646 | + ) . '</strong>'; |
|
2647 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2648 | + } |
|
2649 | + |
|
2650 | + |
|
2651 | + /** Event Category Stuff **/ |
|
2652 | + /** |
|
2653 | + * set the _category property with the category object for the loaded page. |
|
2654 | + * |
|
2655 | + * @access private |
|
2656 | + * @return void |
|
2657 | + */ |
|
2658 | + private function _set_category_object() |
|
2659 | + { |
|
2660 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
2661 | + return; |
|
2662 | + } //already have the category object so get out. |
|
2663 | + // set default category object |
|
2664 | + $this->_set_empty_category_object(); |
|
2665 | + // only set if we've got an id |
|
2666 | + $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
2667 | + if (! $category_ID) { |
|
2668 | + return; |
|
2669 | + } |
|
2670 | + $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2671 | + if (! empty($term)) { |
|
2672 | + $this->_category->category_name = $term->name; |
|
2673 | + $this->_category->category_identifier = $term->slug; |
|
2674 | + $this->_category->category_desc = $term->description; |
|
2675 | + $this->_category->id = $term->term_id; |
|
2676 | + $this->_category->parent = $term->parent; |
|
2677 | + } |
|
2678 | + } |
|
2679 | + |
|
2680 | + |
|
2681 | + /** |
|
2682 | + * Clears out category properties. |
|
2683 | + */ |
|
2684 | + private function _set_empty_category_object() |
|
2685 | + { |
|
2686 | + $this->_category = new stdClass(); |
|
2687 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2688 | + $this->_category->id = $this->_category->parent = 0; |
|
2689 | + } |
|
2690 | + |
|
2691 | + |
|
2692 | + /** |
|
2693 | + * @throws DomainException |
|
2694 | + * @throws EE_Error |
|
2695 | + * @throws InvalidArgumentException |
|
2696 | + * @throws InvalidDataTypeException |
|
2697 | + * @throws InvalidInterfaceException |
|
2698 | + */ |
|
2699 | + protected function _category_list_table() |
|
2700 | + { |
|
2701 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2702 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
2703 | + $this->_admin_page_title .= ' '; |
|
2704 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
2705 | + 'add_category', |
|
2706 | + 'add_category', |
|
2707 | + [], |
|
2708 | + 'add-new-h2' |
|
2709 | + ); |
|
2710 | + $this->display_admin_list_table_page_with_sidebar(); |
|
2711 | + } |
|
2712 | + |
|
2713 | + |
|
2714 | + /** |
|
2715 | + * Output category details view. |
|
2716 | + * |
|
2717 | + * @throws EE_Error |
|
2718 | + * @throws EE_Error |
|
2719 | + */ |
|
2720 | + protected function _category_details($view) |
|
2721 | + { |
|
2722 | + $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
2723 | + $this->_set_add_edit_form_tags($route); |
|
2724 | + $this->_set_category_object(); |
|
2725 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2726 | + $delete_action = 'delete_category'; |
|
2727 | + // custom redirect |
|
2728 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
2729 | + ['action' => 'category_list'], |
|
2730 | + $this->_admin_base_url |
|
2731 | + ); |
|
2732 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect, true); |
|
2733 | + // take care of contents |
|
2734 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
2735 | + $this->display_admin_page_with_sidebar(); |
|
2736 | + } |
|
2737 | + |
|
2738 | + |
|
2739 | + /** |
|
2740 | + * Output category details content. |
|
2741 | + * |
|
2742 | + * @throws DomainException |
|
2743 | + */ |
|
2744 | + protected function _category_details_content(): string |
|
2745 | + { |
|
2746 | + $editor_args['category_desc'] = [ |
|
2747 | + 'type' => 'wp_editor', |
|
2748 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
2749 | + 'class' => 'my_editor_custom', |
|
2750 | + 'wpeditor_args' => ['media_buttons' => false], |
|
2751 | + ]; |
|
2752 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2753 | + $all_terms = get_terms( |
|
2754 | + [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY], |
|
2755 | + ['hide_empty' => 0, 'exclude' => [$this->_category->id]] |
|
2756 | + ); |
|
2757 | + // setup category select for term parents. |
|
2758 | + $category_select_values[] = [ |
|
2759 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
2760 | + 'id' => 0, |
|
2761 | + ]; |
|
2762 | + foreach ($all_terms as $term) { |
|
2763 | + $category_select_values[] = [ |
|
2764 | + 'text' => $term->name, |
|
2765 | + 'id' => $term->term_id, |
|
2766 | + ]; |
|
2767 | + } |
|
2768 | + $category_select = EEH_Form_Fields::select_input( |
|
2769 | + 'category_parent', |
|
2770 | + $category_select_values, |
|
2771 | + $this->_category->parent |
|
2772 | + ); |
|
2773 | + $template_args = [ |
|
2774 | + 'category' => $this->_category, |
|
2775 | + 'category_select' => $category_select, |
|
2776 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
2777 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
2778 | + 'disable' => '', |
|
2779 | + 'disabled_message' => false, |
|
2780 | + ]; |
|
2781 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2782 | + return EEH_Template::display_template($template, $template_args, true); |
|
2783 | + } |
|
2784 | + |
|
2785 | + |
|
2786 | + /** |
|
2787 | + * Handles deleting categories. |
|
2788 | + * |
|
2789 | + * @throws EE_Error |
|
2790 | + */ |
|
2791 | + protected function _delete_categories() |
|
2792 | + { |
|
2793 | + $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true); |
|
2794 | + foreach ($category_IDs as $category_ID) { |
|
2795 | + $this->_delete_category($category_ID); |
|
2796 | + } |
|
2797 | + // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
2798 | + $query_args = [ |
|
2799 | + 'action' => 'category_list', |
|
2800 | + ]; |
|
2801 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
2802 | + } |
|
2803 | + |
|
2804 | + |
|
2805 | + /** |
|
2806 | + * Handles deleting specific category. |
|
2807 | + * |
|
2808 | + * @param int $cat_id |
|
2809 | + */ |
|
2810 | + protected function _delete_category(int $cat_id) |
|
2811 | + { |
|
2812 | + $cat_id = absint($cat_id); |
|
2813 | + wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2814 | + } |
|
2815 | + |
|
2816 | + |
|
2817 | + /** |
|
2818 | + * Handles triggering the update or insertion of a new category. |
|
2819 | + * |
|
2820 | + * @param bool $new_category true means we're triggering the insert of a new category. |
|
2821 | + * @throws EE_Error |
|
2822 | + * @throws EE_Error |
|
2823 | + */ |
|
2824 | + protected function _insert_or_update_category(bool $new_category) |
|
2825 | + { |
|
2826 | + $cat_id = $this->_insert_category($new_category); |
|
2827 | + $success = 0; // we already have a success message so lets not send another. |
|
2828 | + if ($cat_id) { |
|
2829 | + $query_args = [ |
|
2830 | + 'action' => 'edit_category', |
|
2831 | + 'EVT_CAT_ID' => $cat_id, |
|
2832 | + ]; |
|
2833 | + } else { |
|
2834 | + $query_args = ['action' => 'add_category']; |
|
2835 | + } |
|
2836 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
2837 | + } |
|
2838 | + |
|
2839 | + |
|
2840 | + /** |
|
2841 | + * Inserts or updates category |
|
2842 | + * |
|
2843 | + * @param bool $new_category (true indicates we're updating a category). |
|
2844 | + * @return bool|mixed|string |
|
2845 | + */ |
|
2846 | + private function _insert_category(bool $new_category) |
|
2847 | + { |
|
2848 | + $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT); |
|
2849 | + $category_name = $this->request->getRequestParam('category_name', ''); |
|
2850 | + $category_desc = $this->request->getRequestParam('category_desc', '', DataType::HTML); |
|
2851 | + $category_parent = $this->request->getRequestParam('category_parent', 0, DataType::INT); |
|
2852 | + $category_identifier = $this->request->getRequestParam('category_identifier', ''); |
|
2853 | + |
|
2854 | + if (empty($category_name)) { |
|
2855 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
2856 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2857 | + return 0; |
|
2858 | + } |
|
2859 | + $term_args = [ |
|
2860 | + 'name' => $category_name, |
|
2861 | + 'description' => $category_desc, |
|
2862 | + 'parent' => $category_parent, |
|
2863 | + ]; |
|
2864 | + // was the category_identifier input disabled? |
|
2865 | + if ($category_identifier) { |
|
2866 | + $term_args['slug'] = $category_identifier; |
|
2867 | + } |
|
2868 | + $insert_ids = $new_category |
|
2869 | + ? wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
2870 | + : wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
2871 | + |
|
2872 | + if ($insert_ids instanceof WP_Error) { |
|
2873 | + EE_Error::add_error($insert_ids->get_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
2874 | + return 0; |
|
2875 | + } |
|
2876 | + $category_ID = $insert_ids['term_id'] ?? 0; |
|
2877 | + if (! $category_ID) { |
|
2878 | + EE_Error::add_error( |
|
2879 | + esc_html__( |
|
2880 | + 'An error occurred and the category has not been saved to the database.', |
|
2881 | + 'event_espresso' |
|
2882 | + ), |
|
2883 | + __FILE__, |
|
2884 | + __FUNCTION__, |
|
2885 | + __LINE__ |
|
2886 | + ); |
|
2887 | + return 0; |
|
2888 | + } |
|
2889 | + EE_Error::add_success( |
|
2890 | + sprintf( |
|
2891 | + esc_html__('The category %s was successfully saved', 'event_espresso'), |
|
2892 | + $category_name |
|
2893 | + ) |
|
2894 | + ); |
|
2895 | + return $category_ID; |
|
2896 | + } |
|
2897 | + |
|
2898 | + |
|
2899 | + /** |
|
2900 | + * Gets categories or count of categories matching the arguments in the request. |
|
2901 | + * |
|
2902 | + * @param int $per_page |
|
2903 | + * @param int $current_page |
|
2904 | + * @param bool $count |
|
2905 | + * @return EE_Term_Taxonomy[]|int |
|
2906 | + * @throws EE_Error |
|
2907 | + * @throws ReflectionException |
|
2908 | + */ |
|
2909 | + public function get_categories(int $per_page = 10, int $current_page = 1, bool $count = false) |
|
2910 | + { |
|
2911 | + // testing term stuff |
|
2912 | + $orderby = $this->request->getRequestParam('orderby', 'Term.term_id'); |
|
2913 | + $order = $this->request->getRequestParam('order', 'DESC'); |
|
2914 | + $limit = ($current_page - 1) * $per_page; |
|
2915 | + $where = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]; |
|
2916 | + $search_term = $this->request->getRequestParam('s'); |
|
2917 | + if ($search_term) { |
|
2918 | + $search_term = '%' . $search_term . '%'; |
|
2919 | + $where['OR'] = [ |
|
2920 | + 'Term.name' => ['LIKE', $search_term], |
|
2921 | + 'description' => ['LIKE', $search_term], |
|
2922 | + ]; |
|
2923 | + } |
|
2924 | + $query_params = [ |
|
2925 | + $where, |
|
2926 | + 'order_by' => [$orderby => $order], |
|
2927 | + 'limit' => $limit . ',' . $per_page, |
|
2928 | + 'force_join' => ['Term'], |
|
2929 | + ]; |
|
2930 | + return $count |
|
2931 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
2932 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2933 | + } |
|
2934 | + |
|
2935 | + /* end category stuff */ |
|
2936 | + |
|
2937 | + |
|
2938 | + /**************/ |
|
2939 | + |
|
2940 | + |
|
2941 | + /** |
|
2942 | + * Callback for the `ee_save_timezone_setting` ajax action. |
|
2943 | + * |
|
2944 | + * @throws EE_Error |
|
2945 | + * @throws InvalidArgumentException |
|
2946 | + * @throws InvalidDataTypeException |
|
2947 | + * @throws InvalidInterfaceException |
|
2948 | + */ |
|
2949 | + public function saveTimezoneString() |
|
2950 | + { |
|
2951 | + $timezone_string = $this->request->getRequestParam('timezone_selected'); |
|
2952 | + if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
2953 | + EE_Error::add_error( |
|
2954 | + esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
2955 | + __FILE__, |
|
2956 | + __FUNCTION__, |
|
2957 | + __LINE__ |
|
2958 | + ); |
|
2959 | + $this->_template_args['error'] = true; |
|
2960 | + $this->_return_json(); |
|
2961 | + } |
|
2962 | + |
|
2963 | + update_option('timezone_string', $timezone_string); |
|
2964 | + EE_Error::add_success( |
|
2965 | + esc_html__('Your timezone string was updated.', 'event_espresso') |
|
2966 | + ); |
|
2967 | + $this->_template_args['success'] = true; |
|
2968 | + $this->_return_json(true, ['action' => 'create_new']); |
|
2969 | + } |
|
2970 | + |
|
2971 | + |
|
2972 | + /** |
|
2973 | + * @throws EE_Error |
|
2974 | + * @deprecated 4.10.25.p |
|
2975 | + */ |
|
2976 | + public function save_timezonestring_setting() |
|
2977 | + { |
|
2978 | + $this->saveTimezoneString(); |
|
2979 | + } |
|
2980 | 2980 | } |
@@ -37,124 +37,124 @@ |
||
37 | 37 | * @since 4.0 |
38 | 38 | */ |
39 | 39 | if (function_exists('espresso_version')) { |
40 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | - /** |
|
42 | - * espresso_duplicate_plugin_error |
|
43 | - * displays if more than one version of EE is activated at the same time. |
|
44 | - */ |
|
45 | - function espresso_duplicate_plugin_error() |
|
46 | - { |
|
47 | - ?> |
|
40 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | + /** |
|
42 | + * espresso_duplicate_plugin_error |
|
43 | + * displays if more than one version of EE is activated at the same time. |
|
44 | + */ |
|
45 | + function espresso_duplicate_plugin_error() |
|
46 | + { |
|
47 | + ?> |
|
48 | 48 | <div class="error"> |
49 | 49 | <p> |
50 | 50 | <?php |
51 | - echo esc_html__( |
|
52 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
53 | - 'event_espresso' |
|
54 | - ); ?> |
|
51 | + echo esc_html__( |
|
52 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
53 | + 'event_espresso' |
|
54 | + ); ?> |
|
55 | 55 | </p> |
56 | 56 | </div> |
57 | 57 | <?php |
58 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
59 | - } |
|
60 | - } |
|
61 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
58 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
59 | + } |
|
60 | + } |
|
61 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | 62 | } else { |
63 | - define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
64 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | - /** |
|
66 | - * espresso_minimum_php_version_error |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - function espresso_minimum_php_version_error() |
|
71 | - { |
|
72 | - ?> |
|
63 | + define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
64 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | + /** |
|
66 | + * espresso_minimum_php_version_error |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + function espresso_minimum_php_version_error() |
|
71 | + { |
|
72 | + ?> |
|
73 | 73 | <div class="error"> |
74 | 74 | <p> |
75 | 75 | <?php |
76 | - printf( |
|
77 | - esc_html__( |
|
78 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - EE_MIN_PHP_VER_REQUIRED, |
|
82 | - PHP_VERSION, |
|
83 | - '<br/>', |
|
84 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
85 | - ); |
|
86 | - ?> |
|
76 | + printf( |
|
77 | + esc_html__( |
|
78 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + EE_MIN_PHP_VER_REQUIRED, |
|
82 | + PHP_VERSION, |
|
83 | + '<br/>', |
|
84 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
85 | + ); |
|
86 | + ?> |
|
87 | 87 | </p> |
88 | 88 | </div> |
89 | 89 | <?php |
90 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
91 | - } |
|
90 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
91 | + } |
|
92 | 92 | |
93 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
94 | - } else { |
|
95 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
93 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
94 | + } else { |
|
95 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
96 | 96 | |
97 | - require_once __DIR__ . '/vendor/autoload.php'; |
|
98 | - require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
97 | + require_once __DIR__ . '/vendor/autoload.php'; |
|
98 | + require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
99 | 99 | |
100 | - /** |
|
101 | - * espresso_version |
|
102 | - * Returns the plugin version |
|
103 | - * |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - function espresso_version() |
|
107 | - { |
|
108 | - return apply_filters('FHEE__espresso__espresso_version', '5.0.3.rc.000'); |
|
109 | - } |
|
100 | + /** |
|
101 | + * espresso_version |
|
102 | + * Returns the plugin version |
|
103 | + * |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + function espresso_version() |
|
107 | + { |
|
108 | + return apply_filters('FHEE__espresso__espresso_version', '5.0.3.rc.000'); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * espresso_plugin_activation |
|
113 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
114 | - */ |
|
115 | - function espresso_plugin_activation() |
|
116 | - { |
|
117 | - update_option('ee_espresso_activation', true); |
|
118 | - update_option('event-espresso-core_allow_tracking', 'no'); |
|
119 | - update_option('event-espresso-core_tracking_notice', 'hide'); |
|
120 | - // Run WP GraphQL activation callback |
|
121 | - graphql_activation_callback(); |
|
122 | - } |
|
111 | + /** |
|
112 | + * espresso_plugin_activation |
|
113 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
114 | + */ |
|
115 | + function espresso_plugin_activation() |
|
116 | + { |
|
117 | + update_option('ee_espresso_activation', true); |
|
118 | + update_option('event-espresso-core_allow_tracking', 'no'); |
|
119 | + update_option('event-espresso-core_tracking_notice', 'hide'); |
|
120 | + // Run WP GraphQL activation callback |
|
121 | + graphql_activation_callback(); |
|
122 | + } |
|
123 | 123 | |
124 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
124 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
125 | 125 | |
126 | - /** |
|
127 | - * espresso_plugin_deactivation |
|
128 | - */ |
|
129 | - function espresso_plugin_deactivation() |
|
130 | - { |
|
131 | - // Run WP GraphQL deactivation callback |
|
132 | - graphql_deactivation_callback(); |
|
133 | - delete_option('event-espresso-core_allow_tracking'); |
|
134 | - delete_option('event-espresso-core_tracking_notice'); |
|
135 | - } |
|
136 | - register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
126 | + /** |
|
127 | + * espresso_plugin_deactivation |
|
128 | + */ |
|
129 | + function espresso_plugin_deactivation() |
|
130 | + { |
|
131 | + // Run WP GraphQL deactivation callback |
|
132 | + graphql_deactivation_callback(); |
|
133 | + delete_option('event-espresso-core_allow_tracking'); |
|
134 | + delete_option('event-espresso-core_tracking_notice'); |
|
135 | + } |
|
136 | + register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
137 | 137 | |
138 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
139 | - bootstrap_espresso(); |
|
140 | - } |
|
138 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
139 | + bootstrap_espresso(); |
|
140 | + } |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | if (! function_exists('espresso_deactivate_plugin')) { |
144 | - /** |
|
145 | - * deactivate_plugin |
|
146 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
147 | - * |
|
148 | - * @access public |
|
149 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
153 | - { |
|
154 | - if (! function_exists('deactivate_plugins')) { |
|
155 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
156 | - } |
|
157 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
158 | - deactivate_plugins($plugin_basename); |
|
159 | - } |
|
144 | + /** |
|
145 | + * deactivate_plugin |
|
146 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
147 | + * |
|
148 | + * @access public |
|
149 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
153 | + { |
|
154 | + if (! function_exists('deactivate_plugins')) { |
|
155 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
156 | + } |
|
157 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
158 | + deactivate_plugins($plugin_basename); |
|
159 | + } |
|
160 | 160 | } |
@@ -31,455 +31,455 @@ discard block |
||
31 | 31 | */ |
32 | 32 | abstract class EE_Admin_Page_CPT extends EE_Admin_Page |
33 | 33 | { |
34 | - /** |
|
35 | - * This gets set in _setup_cpt |
|
36 | - * It will contain the object for the custom post type. |
|
37 | - * |
|
38 | - * @var EE_CPT_Base |
|
39 | - */ |
|
40 | - protected $_cpt_object; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * a boolean flag to set whether the current route is a cpt route or not. |
|
45 | - * |
|
46 | - * @var bool |
|
47 | - */ |
|
48 | - protected $_cpt_route = false; |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * This property allows cpt classes to define multiple routes as cpt routes. |
|
53 | - * //in this array we define what the custom post type for this route is. |
|
54 | - * array( |
|
55 | - * 'route_name' => 'custom_post_type_slug' |
|
56 | - * ) |
|
57 | - * |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - protected $_cpt_routes = []; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
65 | - * in this format: |
|
66 | - * array( |
|
67 | - * 'post_type_slug' => 'edit_route' |
|
68 | - * ) |
|
69 | - * |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - protected $_cpt_edit_routes = []; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
77 | - * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
78 | - * _cpt_model_names property should be in the following format: array( |
|
79 | - * 'route_defined_by_action_param' => 'Model_Name') |
|
80 | - * |
|
81 | - * @var array $_cpt_model_names |
|
82 | - */ |
|
83 | - protected $_cpt_model_names = []; |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @var EE_CPT_Base |
|
88 | - */ |
|
89 | - protected $_cpt_model_obj = null; |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
94 | - * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
95 | - * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
96 | - * Registration of containers should be done before load_page_dependencies() is run. |
|
97 | - * |
|
98 | - * @var array() |
|
99 | - */ |
|
100 | - protected $_autosave_containers = []; |
|
101 | - |
|
102 | - protected $_autosave_fields = []; |
|
103 | - |
|
104 | - /** |
|
105 | - * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
106 | - * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
107 | - * |
|
108 | - * @var array |
|
109 | - */ |
|
110 | - protected $_pagenow_map; |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
115 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
116 | - * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
117 | - * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
118 | - * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
119 | - * |
|
120 | - * @abstract |
|
121 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
122 | - * @param WP_Post $post The post object of the cpt that was saved. |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - abstract protected function _insert_update_cpt_item($post_id, $post); |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
130 | - * |
|
131 | - * @abstract |
|
132 | - * @param string $post_id The ID of the cpt that was trashed |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - abstract public function trash_cpt_item($post_id); |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
140 | - * |
|
141 | - * @param string $post_id theID of the cpt that was untrashed |
|
142 | - * @return void |
|
143 | - */ |
|
144 | - abstract public function restore_cpt_item($post_id); |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
149 | - * from the db |
|
150 | - * |
|
151 | - * @param string $post_id the ID of the cpt that was deleted |
|
152 | - * @return void |
|
153 | - */ |
|
154 | - abstract public function delete_cpt_item($post_id); |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return LoaderInterface |
|
159 | - * @throws InvalidArgumentException |
|
160 | - * @throws InvalidDataTypeException |
|
161 | - * @throws InvalidInterfaceException |
|
162 | - */ |
|
163 | - protected function getLoader(): LoaderInterface |
|
164 | - { |
|
165 | - if (! $this->loader instanceof LoaderInterface) { |
|
166 | - $this->loader = LoaderFactory::getLoader(); |
|
167 | - } |
|
168 | - return $this->loader; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
174 | - * |
|
175 | - * @return void |
|
176 | - */ |
|
177 | - protected function _before_page_setup() |
|
178 | - { |
|
179 | - $this->raw_req_action = $this->request->getRequestParam('action'); |
|
180 | - $this->raw_req_page = $this->request->getRequestParam('page'); |
|
181 | - $this->_cpt_routes = array_merge( |
|
182 | - [ |
|
183 | - 'create_new' => $this->page_slug, |
|
184 | - 'edit' => $this->page_slug, |
|
185 | - 'trash' => $this->page_slug, |
|
186 | - ], |
|
187 | - $this->_cpt_routes |
|
188 | - ); |
|
189 | - $cpt_route_action = $this->_cpt_routes[ $this->raw_req_action ] ?? null; |
|
190 | - // let's see if the current route has a value for cpt_object_slug. if it does, we use that instead of the page |
|
191 | - $page = $this->raw_req_page ?: $this->page_slug; |
|
192 | - $page = $cpt_route_action ?: $page; |
|
193 | - $this->_cpt_object = get_post_type_object($page); |
|
194 | - // tweak pagenow for page loading. |
|
195 | - if (! $this->_pagenow_map) { |
|
196 | - $this->_pagenow_map = [ |
|
197 | - 'create_new' => 'post-new.php', |
|
198 | - 'edit' => 'post.php', |
|
199 | - 'trash' => 'post.php', |
|
200 | - ]; |
|
201 | - } |
|
202 | - add_action('current_screen', [$this, 'modify_pagenow']); |
|
203 | - // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
204 | - // get current page from autosave |
|
205 | - $current_page = $this->request->getRequestParam('ee_autosave_data[ee-cpt-hidden-inputs][current_page]'); |
|
206 | - $this->_current_page = $this->request->getRequestParam('current_page', $current_page); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Simply ensure that we simulate the correct post route for cpt screens |
|
212 | - * |
|
213 | - * @param WP_Screen|null $current_screen |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - public function modify_pagenow(?WP_Screen $current_screen) |
|
217 | - { |
|
218 | - // possibly reset pagenow. |
|
219 | - if ( |
|
220 | - $this->page_slug === $this->raw_req_page |
|
221 | - && isset($this->_pagenow_map[ $this->raw_req_action ]) |
|
222 | - ) { |
|
223 | - global $pagenow, $hook_suffix; |
|
224 | - $pagenow = $this->_pagenow_map[ $this->raw_req_action ]; |
|
225 | - $hook_suffix = $pagenow; |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This method is used to register additional autosave containers to the _autosave_containers property. |
|
232 | - * |
|
233 | - * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
234 | - * you would send along the id of a metabox container. |
|
235 | - * @return void |
|
236 | - * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
237 | - * automatically register the id for the post metabox as a container. |
|
238 | - */ |
|
239 | - protected function _register_autosave_containers($ids) |
|
240 | - { |
|
241 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
247 | - * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
248 | - */ |
|
249 | - protected function _set_autosave_containers() |
|
250 | - { |
|
251 | - global $wp_meta_boxes; |
|
252 | - $containers = []; |
|
253 | - if (empty($wp_meta_boxes)) { |
|
254 | - return; |
|
255 | - } |
|
256 | - $current_metaboxes = $wp_meta_boxes[ $this->page_slug ] ?? []; |
|
257 | - foreach ($current_metaboxes as $box_context) { |
|
258 | - foreach ($box_context as $box_details) { |
|
259 | - foreach ($box_details as $box) { |
|
260 | - if ( |
|
261 | - is_array($box) && is_array($box['callback']) |
|
262 | - && ( |
|
263 | - $box['callback'][0] instanceof EE_Admin_Page |
|
264 | - || $box['callback'][0] instanceof EE_Admin_Hooks |
|
265 | - ) |
|
266 | - ) { |
|
267 | - $containers[] = $box['id']; |
|
268 | - } |
|
269 | - } |
|
270 | - } |
|
271 | - } |
|
272 | - $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
273 | - // add hidden inputs container |
|
274 | - $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - protected function _load_autosave_scripts_styles() |
|
279 | - { |
|
280 | - /*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 ); |
|
34 | + /** |
|
35 | + * This gets set in _setup_cpt |
|
36 | + * It will contain the object for the custom post type. |
|
37 | + * |
|
38 | + * @var EE_CPT_Base |
|
39 | + */ |
|
40 | + protected $_cpt_object; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * a boolean flag to set whether the current route is a cpt route or not. |
|
45 | + * |
|
46 | + * @var bool |
|
47 | + */ |
|
48 | + protected $_cpt_route = false; |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * This property allows cpt classes to define multiple routes as cpt routes. |
|
53 | + * //in this array we define what the custom post type for this route is. |
|
54 | + * array( |
|
55 | + * 'route_name' => 'custom_post_type_slug' |
|
56 | + * ) |
|
57 | + * |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + protected $_cpt_routes = []; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
65 | + * in this format: |
|
66 | + * array( |
|
67 | + * 'post_type_slug' => 'edit_route' |
|
68 | + * ) |
|
69 | + * |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + protected $_cpt_edit_routes = []; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
77 | + * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
78 | + * _cpt_model_names property should be in the following format: array( |
|
79 | + * 'route_defined_by_action_param' => 'Model_Name') |
|
80 | + * |
|
81 | + * @var array $_cpt_model_names |
|
82 | + */ |
|
83 | + protected $_cpt_model_names = []; |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @var EE_CPT_Base |
|
88 | + */ |
|
89 | + protected $_cpt_model_obj = null; |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
94 | + * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
95 | + * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
96 | + * Registration of containers should be done before load_page_dependencies() is run. |
|
97 | + * |
|
98 | + * @var array() |
|
99 | + */ |
|
100 | + protected $_autosave_containers = []; |
|
101 | + |
|
102 | + protected $_autosave_fields = []; |
|
103 | + |
|
104 | + /** |
|
105 | + * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
106 | + * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
107 | + * |
|
108 | + * @var array |
|
109 | + */ |
|
110 | + protected $_pagenow_map; |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
115 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
116 | + * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
117 | + * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
118 | + * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
119 | + * |
|
120 | + * @abstract |
|
121 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
122 | + * @param WP_Post $post The post object of the cpt that was saved. |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + abstract protected function _insert_update_cpt_item($post_id, $post); |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
130 | + * |
|
131 | + * @abstract |
|
132 | + * @param string $post_id The ID of the cpt that was trashed |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + abstract public function trash_cpt_item($post_id); |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
140 | + * |
|
141 | + * @param string $post_id theID of the cpt that was untrashed |
|
142 | + * @return void |
|
143 | + */ |
|
144 | + abstract public function restore_cpt_item($post_id); |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
149 | + * from the db |
|
150 | + * |
|
151 | + * @param string $post_id the ID of the cpt that was deleted |
|
152 | + * @return void |
|
153 | + */ |
|
154 | + abstract public function delete_cpt_item($post_id); |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return LoaderInterface |
|
159 | + * @throws InvalidArgumentException |
|
160 | + * @throws InvalidDataTypeException |
|
161 | + * @throws InvalidInterfaceException |
|
162 | + */ |
|
163 | + protected function getLoader(): LoaderInterface |
|
164 | + { |
|
165 | + if (! $this->loader instanceof LoaderInterface) { |
|
166 | + $this->loader = LoaderFactory::getLoader(); |
|
167 | + } |
|
168 | + return $this->loader; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
174 | + * |
|
175 | + * @return void |
|
176 | + */ |
|
177 | + protected function _before_page_setup() |
|
178 | + { |
|
179 | + $this->raw_req_action = $this->request->getRequestParam('action'); |
|
180 | + $this->raw_req_page = $this->request->getRequestParam('page'); |
|
181 | + $this->_cpt_routes = array_merge( |
|
182 | + [ |
|
183 | + 'create_new' => $this->page_slug, |
|
184 | + 'edit' => $this->page_slug, |
|
185 | + 'trash' => $this->page_slug, |
|
186 | + ], |
|
187 | + $this->_cpt_routes |
|
188 | + ); |
|
189 | + $cpt_route_action = $this->_cpt_routes[ $this->raw_req_action ] ?? null; |
|
190 | + // let's see if the current route has a value for cpt_object_slug. if it does, we use that instead of the page |
|
191 | + $page = $this->raw_req_page ?: $this->page_slug; |
|
192 | + $page = $cpt_route_action ?: $page; |
|
193 | + $this->_cpt_object = get_post_type_object($page); |
|
194 | + // tweak pagenow for page loading. |
|
195 | + if (! $this->_pagenow_map) { |
|
196 | + $this->_pagenow_map = [ |
|
197 | + 'create_new' => 'post-new.php', |
|
198 | + 'edit' => 'post.php', |
|
199 | + 'trash' => 'post.php', |
|
200 | + ]; |
|
201 | + } |
|
202 | + add_action('current_screen', [$this, 'modify_pagenow']); |
|
203 | + // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
204 | + // get current page from autosave |
|
205 | + $current_page = $this->request->getRequestParam('ee_autosave_data[ee-cpt-hidden-inputs][current_page]'); |
|
206 | + $this->_current_page = $this->request->getRequestParam('current_page', $current_page); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Simply ensure that we simulate the correct post route for cpt screens |
|
212 | + * |
|
213 | + * @param WP_Screen|null $current_screen |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + public function modify_pagenow(?WP_Screen $current_screen) |
|
217 | + { |
|
218 | + // possibly reset pagenow. |
|
219 | + if ( |
|
220 | + $this->page_slug === $this->raw_req_page |
|
221 | + && isset($this->_pagenow_map[ $this->raw_req_action ]) |
|
222 | + ) { |
|
223 | + global $pagenow, $hook_suffix; |
|
224 | + $pagenow = $this->_pagenow_map[ $this->raw_req_action ]; |
|
225 | + $hook_suffix = $pagenow; |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This method is used to register additional autosave containers to the _autosave_containers property. |
|
232 | + * |
|
233 | + * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
234 | + * you would send along the id of a metabox container. |
|
235 | + * @return void |
|
236 | + * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
237 | + * automatically register the id for the post metabox as a container. |
|
238 | + */ |
|
239 | + protected function _register_autosave_containers($ids) |
|
240 | + { |
|
241 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
247 | + * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
248 | + */ |
|
249 | + protected function _set_autosave_containers() |
|
250 | + { |
|
251 | + global $wp_meta_boxes; |
|
252 | + $containers = []; |
|
253 | + if (empty($wp_meta_boxes)) { |
|
254 | + return; |
|
255 | + } |
|
256 | + $current_metaboxes = $wp_meta_boxes[ $this->page_slug ] ?? []; |
|
257 | + foreach ($current_metaboxes as $box_context) { |
|
258 | + foreach ($box_context as $box_details) { |
|
259 | + foreach ($box_details as $box) { |
|
260 | + if ( |
|
261 | + is_array($box) && is_array($box['callback']) |
|
262 | + && ( |
|
263 | + $box['callback'][0] instanceof EE_Admin_Page |
|
264 | + || $box['callback'][0] instanceof EE_Admin_Hooks |
|
265 | + ) |
|
266 | + ) { |
|
267 | + $containers[] = $box['id']; |
|
268 | + } |
|
269 | + } |
|
270 | + } |
|
271 | + } |
|
272 | + $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
273 | + // add hidden inputs container |
|
274 | + $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + protected function _load_autosave_scripts_styles() |
|
279 | + { |
|
280 | + /*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 ); |
|
281 | 281 | wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2 |
282 | 282 | |
283 | - // filter _autosave_containers |
|
284 | - $containers = apply_filters( |
|
285 | - 'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
286 | - $this->_autosave_containers, |
|
287 | - $this |
|
288 | - ); |
|
289 | - $containers = apply_filters( |
|
290 | - 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
291 | - $containers, |
|
292 | - $this |
|
293 | - ); |
|
294 | - |
|
295 | - wp_localize_script( |
|
296 | - 'event_editor_js', |
|
297 | - 'EE_AUTOSAVE_IDS', |
|
298 | - $containers |
|
299 | - ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
300 | - |
|
301 | - $unsaved_data_msg = [ |
|
302 | - 'eventmsg' => sprintf( |
|
303 | - wp_strip_all_tags( |
|
304 | - __( |
|
305 | - "The changes you made to this %s will be lost if you navigate away from this page.", |
|
306 | - 'event_espresso' |
|
307 | - ) |
|
308 | - ), |
|
309 | - $this->_cpt_object->labels->singular_name |
|
310 | - ), |
|
311 | - 'inputChanged' => 0, |
|
312 | - ]; |
|
313 | - wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
319 | - * |
|
320 | - * @return void |
|
321 | - * @throws EE_Error |
|
322 | - * @throws ReflectionException |
|
323 | - */ |
|
324 | - protected function _load_page_dependencies() |
|
325 | - { |
|
326 | - // we only add stuff if this is a cpt_route! |
|
327 | - if (! $this->_cpt_route) { |
|
328 | - parent::_load_page_dependencies(); |
|
329 | - return; |
|
330 | - } |
|
331 | - // now let's do some automatic filters into the wp_system |
|
332 | - // and we'll check to make sure the CHILD class |
|
333 | - // automatically has the required methods in place. |
|
334 | - // the following filters are for setting all the redirects |
|
335 | - // on DEFAULT WP custom post type actions |
|
336 | - // let's add a hidden input to the post-edit form |
|
337 | - // so we know when we have to trigger our custom redirects! |
|
338 | - // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
339 | - add_action('edit_form_after_title', [$this, 'cpt_post_form_hidden_input']); |
|
340 | - // inject our Admin page nav tabs... |
|
341 | - // let's make sure the nav tabs are set if they aren't already |
|
342 | - // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
343 | - add_action('edit_form_top', [$this, 'inject_nav_tabs']); |
|
344 | - // modify the post_updated messages array |
|
345 | - add_action('post_updated_messages', [$this, 'post_update_messages'], 10); |
|
346 | - // This basically allows us to change the title of the "publish" metabox area |
|
347 | - // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
348 | - $screen = $this->_cpt_routes[ $this->_req_action ]; |
|
349 | - if (! empty($this->_labels['publishbox'])) { |
|
350 | - $this->addMetaBox( |
|
351 | - 'submitdiv', |
|
352 | - $this->getPublishBoxTitle(), |
|
353 | - 'post_submit_meta_box', |
|
354 | - $screen, |
|
355 | - 'side', |
|
356 | - 'core' |
|
357 | - ); |
|
358 | - } |
|
359 | - // let's add page_templates metabox if this cpt added support for it. |
|
360 | - if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
361 | - $this->addMetaBox( |
|
362 | - 'page_templates', |
|
363 | - esc_html__('Page Template', 'event_espresso'), |
|
364 | - [$this, 'page_template_meta_box'], |
|
365 | - $screen, |
|
366 | - 'side' |
|
367 | - ); |
|
368 | - } |
|
369 | - // add preview button |
|
370 | - add_filter('get_sample_permalink_html', [PreviewButton::class, 'addButton'], 5, 2); |
|
371 | - // add shortlink button to cpt edit screens. |
|
372 | - // We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts! |
|
373 | - add_filter('get_sample_permalink_html', [EventShortlinkButton::class, 'addButton'], 10, 2); |
|
374 | - // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
375 | - add_filter('get_sample_permalink_html', [TicketSelectorShortcodeButton::class, 'addButton'], 12, 4); |
|
376 | - // insert our own post_stati dropdown |
|
377 | - add_action('post_submitbox_misc_actions', [$this, 'custom_post_stati_dropdown'], 10); |
|
378 | - // This allows adding additional information to the publish post submitbox on the wp post edit form |
|
379 | - if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
380 | - add_action('post_submitbox_misc_actions', [$this, 'extra_misc_actions_publish_box'], 10); |
|
381 | - } |
|
382 | - // This allows for adding additional stuff after the title field on the wp post edit form. |
|
383 | - // This is also before the wp_editor for post description field. |
|
384 | - if (method_exists($this, 'edit_form_after_title')) { |
|
385 | - add_action('edit_form_after_title', [$this, 'edit_form_after_title'], 10); |
|
386 | - } |
|
387 | - /** |
|
388 | - * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
389 | - */ |
|
390 | - add_filter('clean_url', [$this, 'switch_core_wp_urls_with_ours'], 10); |
|
391 | - parent::_load_page_dependencies(); |
|
392 | - // notice we are ALSO going to load the pagenow hook set for this route |
|
393 | - // (see _before_page_setup for the reset of the pagenow global ). |
|
394 | - // This is for any plugins that are doing things properly |
|
395 | - // and hooking into the load page hook for core wp cpt routes. |
|
396 | - global $pagenow; |
|
397 | - add_action('load-' . $pagenow, [$this, 'modify_current_screen'], 20); |
|
398 | - do_action('load-' . $pagenow); |
|
399 | - add_action('admin_enqueue_scripts', [$this, 'setup_autosave_hooks'], 30); |
|
400 | - // we route REALLY early. |
|
401 | - try { |
|
402 | - $this->_route_admin_request(); |
|
403 | - } catch (EE_Error $e) { |
|
404 | - $e->get_error(); |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
411 | - * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
412 | - * route instead. |
|
413 | - * |
|
414 | - * @param string $good_protocol_url The escaped url. |
|
415 | - * @return string possibly a new url for our route. |
|
416 | - */ |
|
417 | - public function switch_core_wp_urls_with_ours(string $good_protocol_url): string |
|
418 | - { |
|
419 | - $routes_to_match = [ |
|
420 | - 0 => [ |
|
421 | - 'edit.php?post_type=espresso_attendees', |
|
422 | - 'admin.php?page=espresso_registrations&action=contact_list', |
|
423 | - ], |
|
424 | - 1 => [ |
|
425 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
426 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
427 | - ], |
|
428 | - ]; |
|
429 | - foreach ($routes_to_match as $route_matches) { |
|
430 | - if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
431 | - return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
432 | - } |
|
433 | - } |
|
434 | - return $good_protocol_url; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * Determine whether the current cpt supports page templates or not. |
|
440 | - * |
|
441 | - * @param string $cpt_name The cpt slug we're checking on. |
|
442 | - * @return bool True supported, false not. |
|
443 | - * @throws InvalidArgumentException |
|
444 | - * @throws InvalidDataTypeException |
|
445 | - * @throws InvalidInterfaceException |
|
446 | - * @since %VER% |
|
447 | - */ |
|
448 | - private function _supports_page_templates(string $cpt_name): bool |
|
449 | - { |
|
450 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
451 | - $custom_post_types = $this->loader->getShared( |
|
452 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
453 | - ); |
|
454 | - $cpt_args = $custom_post_types->getDefinitions(); |
|
455 | - $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : []; |
|
456 | - $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
457 | - |
|
458 | - $post_templates = wp_get_theme()->get_post_templates(); |
|
459 | - // if there are $post_templates for this cpt, then we return false for this method because |
|
460 | - // that means we aren't going to load our page template manager and leave that up to the native |
|
461 | - // cpt template manager. |
|
462 | - return ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * Callback for the page_templates metabox selector. |
|
468 | - * |
|
469 | - * @return void |
|
470 | - * @since %VER% |
|
471 | - */ |
|
472 | - public function page_template_meta_box() |
|
473 | - { |
|
474 | - global $post; |
|
475 | - $template = ''; |
|
476 | - |
|
477 | - $page_template_count = count(get_page_templates()); |
|
478 | - if ($page_template_count) { |
|
479 | - $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
480 | - $template = ! empty($page_template) ? $page_template : ''; |
|
481 | - } |
|
482 | - ?> |
|
283 | + // filter _autosave_containers |
|
284 | + $containers = apply_filters( |
|
285 | + 'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
286 | + $this->_autosave_containers, |
|
287 | + $this |
|
288 | + ); |
|
289 | + $containers = apply_filters( |
|
290 | + 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
291 | + $containers, |
|
292 | + $this |
|
293 | + ); |
|
294 | + |
|
295 | + wp_localize_script( |
|
296 | + 'event_editor_js', |
|
297 | + 'EE_AUTOSAVE_IDS', |
|
298 | + $containers |
|
299 | + ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
300 | + |
|
301 | + $unsaved_data_msg = [ |
|
302 | + 'eventmsg' => sprintf( |
|
303 | + wp_strip_all_tags( |
|
304 | + __( |
|
305 | + "The changes you made to this %s will be lost if you navigate away from this page.", |
|
306 | + 'event_espresso' |
|
307 | + ) |
|
308 | + ), |
|
309 | + $this->_cpt_object->labels->singular_name |
|
310 | + ), |
|
311 | + 'inputChanged' => 0, |
|
312 | + ]; |
|
313 | + wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
319 | + * |
|
320 | + * @return void |
|
321 | + * @throws EE_Error |
|
322 | + * @throws ReflectionException |
|
323 | + */ |
|
324 | + protected function _load_page_dependencies() |
|
325 | + { |
|
326 | + // we only add stuff if this is a cpt_route! |
|
327 | + if (! $this->_cpt_route) { |
|
328 | + parent::_load_page_dependencies(); |
|
329 | + return; |
|
330 | + } |
|
331 | + // now let's do some automatic filters into the wp_system |
|
332 | + // and we'll check to make sure the CHILD class |
|
333 | + // automatically has the required methods in place. |
|
334 | + // the following filters are for setting all the redirects |
|
335 | + // on DEFAULT WP custom post type actions |
|
336 | + // let's add a hidden input to the post-edit form |
|
337 | + // so we know when we have to trigger our custom redirects! |
|
338 | + // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
339 | + add_action('edit_form_after_title', [$this, 'cpt_post_form_hidden_input']); |
|
340 | + // inject our Admin page nav tabs... |
|
341 | + // let's make sure the nav tabs are set if they aren't already |
|
342 | + // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
343 | + add_action('edit_form_top', [$this, 'inject_nav_tabs']); |
|
344 | + // modify the post_updated messages array |
|
345 | + add_action('post_updated_messages', [$this, 'post_update_messages'], 10); |
|
346 | + // This basically allows us to change the title of the "publish" metabox area |
|
347 | + // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
348 | + $screen = $this->_cpt_routes[ $this->_req_action ]; |
|
349 | + if (! empty($this->_labels['publishbox'])) { |
|
350 | + $this->addMetaBox( |
|
351 | + 'submitdiv', |
|
352 | + $this->getPublishBoxTitle(), |
|
353 | + 'post_submit_meta_box', |
|
354 | + $screen, |
|
355 | + 'side', |
|
356 | + 'core' |
|
357 | + ); |
|
358 | + } |
|
359 | + // let's add page_templates metabox if this cpt added support for it. |
|
360 | + if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
361 | + $this->addMetaBox( |
|
362 | + 'page_templates', |
|
363 | + esc_html__('Page Template', 'event_espresso'), |
|
364 | + [$this, 'page_template_meta_box'], |
|
365 | + $screen, |
|
366 | + 'side' |
|
367 | + ); |
|
368 | + } |
|
369 | + // add preview button |
|
370 | + add_filter('get_sample_permalink_html', [PreviewButton::class, 'addButton'], 5, 2); |
|
371 | + // add shortlink button to cpt edit screens. |
|
372 | + // We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts! |
|
373 | + add_filter('get_sample_permalink_html', [EventShortlinkButton::class, 'addButton'], 10, 2); |
|
374 | + // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
375 | + add_filter('get_sample_permalink_html', [TicketSelectorShortcodeButton::class, 'addButton'], 12, 4); |
|
376 | + // insert our own post_stati dropdown |
|
377 | + add_action('post_submitbox_misc_actions', [$this, 'custom_post_stati_dropdown'], 10); |
|
378 | + // This allows adding additional information to the publish post submitbox on the wp post edit form |
|
379 | + if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
380 | + add_action('post_submitbox_misc_actions', [$this, 'extra_misc_actions_publish_box'], 10); |
|
381 | + } |
|
382 | + // This allows for adding additional stuff after the title field on the wp post edit form. |
|
383 | + // This is also before the wp_editor for post description field. |
|
384 | + if (method_exists($this, 'edit_form_after_title')) { |
|
385 | + add_action('edit_form_after_title', [$this, 'edit_form_after_title'], 10); |
|
386 | + } |
|
387 | + /** |
|
388 | + * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
389 | + */ |
|
390 | + add_filter('clean_url', [$this, 'switch_core_wp_urls_with_ours'], 10); |
|
391 | + parent::_load_page_dependencies(); |
|
392 | + // notice we are ALSO going to load the pagenow hook set for this route |
|
393 | + // (see _before_page_setup for the reset of the pagenow global ). |
|
394 | + // This is for any plugins that are doing things properly |
|
395 | + // and hooking into the load page hook for core wp cpt routes. |
|
396 | + global $pagenow; |
|
397 | + add_action('load-' . $pagenow, [$this, 'modify_current_screen'], 20); |
|
398 | + do_action('load-' . $pagenow); |
|
399 | + add_action('admin_enqueue_scripts', [$this, 'setup_autosave_hooks'], 30); |
|
400 | + // we route REALLY early. |
|
401 | + try { |
|
402 | + $this->_route_admin_request(); |
|
403 | + } catch (EE_Error $e) { |
|
404 | + $e->get_error(); |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
411 | + * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
412 | + * route instead. |
|
413 | + * |
|
414 | + * @param string $good_protocol_url The escaped url. |
|
415 | + * @return string possibly a new url for our route. |
|
416 | + */ |
|
417 | + public function switch_core_wp_urls_with_ours(string $good_protocol_url): string |
|
418 | + { |
|
419 | + $routes_to_match = [ |
|
420 | + 0 => [ |
|
421 | + 'edit.php?post_type=espresso_attendees', |
|
422 | + 'admin.php?page=espresso_registrations&action=contact_list', |
|
423 | + ], |
|
424 | + 1 => [ |
|
425 | + 'edit.php?post_type=' . $this->_cpt_object->name, |
|
426 | + 'admin.php?page=' . $this->_cpt_object->name, |
|
427 | + ], |
|
428 | + ]; |
|
429 | + foreach ($routes_to_match as $route_matches) { |
|
430 | + if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
431 | + return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
432 | + } |
|
433 | + } |
|
434 | + return $good_protocol_url; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * Determine whether the current cpt supports page templates or not. |
|
440 | + * |
|
441 | + * @param string $cpt_name The cpt slug we're checking on. |
|
442 | + * @return bool True supported, false not. |
|
443 | + * @throws InvalidArgumentException |
|
444 | + * @throws InvalidDataTypeException |
|
445 | + * @throws InvalidInterfaceException |
|
446 | + * @since %VER% |
|
447 | + */ |
|
448 | + private function _supports_page_templates(string $cpt_name): bool |
|
449 | + { |
|
450 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
451 | + $custom_post_types = $this->loader->getShared( |
|
452 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
453 | + ); |
|
454 | + $cpt_args = $custom_post_types->getDefinitions(); |
|
455 | + $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : []; |
|
456 | + $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
457 | + |
|
458 | + $post_templates = wp_get_theme()->get_post_templates(); |
|
459 | + // if there are $post_templates for this cpt, then we return false for this method because |
|
460 | + // that means we aren't going to load our page template manager and leave that up to the native |
|
461 | + // cpt template manager. |
|
462 | + return ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * Callback for the page_templates metabox selector. |
|
468 | + * |
|
469 | + * @return void |
|
470 | + * @since %VER% |
|
471 | + */ |
|
472 | + public function page_template_meta_box() |
|
473 | + { |
|
474 | + global $post; |
|
475 | + $template = ''; |
|
476 | + |
|
477 | + $page_template_count = count(get_page_templates()); |
|
478 | + if ($page_template_count) { |
|
479 | + $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
480 | + $template = ! empty($page_template) ? $page_template : ''; |
|
481 | + } |
|
482 | + ?> |
|
483 | 483 | <p><strong><?php esc_html_e('Template', 'event_espresso') ?></strong></p> |
484 | 484 | <label class="screen-reader-text" for="page_template"> |
485 | 485 | <?php esc_html_e('Page Template', 'event_espresso') ?> |
@@ -489,457 +489,457 @@ discard block |
||
489 | 489 | <?php page_template_dropdown($template); ?> |
490 | 490 | </select> |
491 | 491 | <?php |
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
497 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
498 | - * |
|
499 | - * @param string $return the current html |
|
500 | - * @param int $id the post id for the page |
|
501 | - * @return string The new html string for the permalink area |
|
502 | - * @deprecated 5.0.0.p |
|
503 | - * @see PreviewButton::addButton() |
|
504 | - */ |
|
505 | - public function preview_button_html(string $return, int $id): string |
|
506 | - { |
|
507 | - return PreviewButton::addButton($return, $id); |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * add our custom post status dropdown on the wp post page for this cpt |
|
513 | - * |
|
514 | - * @return void |
|
515 | - */ |
|
516 | - public function custom_post_stati_dropdown() |
|
517 | - { |
|
518 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
519 | - $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
520 | - ? $statuses[ $this->_cpt_model_obj->status() ] |
|
521 | - : ''; |
|
522 | - $template_args = [ |
|
523 | - 'cur_status' => $this->_cpt_model_obj->status(), |
|
524 | - 'statuses' => $statuses, |
|
525 | - 'cur_status_label' => $cur_status_label, |
|
526 | - 'localized_status_save' => sprintf(esc_html__('Save %s', 'event_espresso'), $cur_status_label), |
|
527 | - ]; |
|
528 | - // we'll add a trash post status (WP doesn't add one for some reason) |
|
529 | - if ($this->_cpt_model_obj->status() === 'trash') { |
|
530 | - $template_args['cur_status_label'] = esc_html__('Trashed', 'event_espresso'); |
|
531 | - $statuses['trash'] = esc_html__('Trashed', 'event_espresso'); |
|
532 | - $template_args['statuses'] = $statuses; |
|
533 | - } |
|
534 | - |
|
535 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
536 | - EEH_Template::display_template($template, $template_args); |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - public function setup_autosave_hooks() |
|
541 | - { |
|
542 | - $this->_set_autosave_containers(); |
|
543 | - $this->_load_autosave_scripts_styles(); |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a post object (available |
|
549 | - * in request data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
550 | - * for the nonce in here, but then this method looks for two things: |
|
551 | - * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
552 | - * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
553 | - * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
554 | - * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
555 | - * template args. |
|
556 | - * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
557 | - * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
558 | - * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
559 | - * $this->_template_args['data']['items'] = array( |
|
560 | - * 'event-datetime-ids' => '1,2,3'; |
|
561 | - * ); |
|
562 | - * Keep in mind the following things: |
|
563 | - * - "where" index is for the input with the id as that string. |
|
564 | - * - "what" index is what will be used for the value of that input. |
|
565 | - * |
|
566 | - * @return void |
|
567 | - * @throws EE_Error |
|
568 | - */ |
|
569 | - public function do_extra_autosave_stuff() |
|
570 | - { |
|
571 | - // next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
572 | - $nonce = $this->request->getRequestParam('autosavenonce'); |
|
573 | - $this->_verify_nonce($nonce, 'autosave'); |
|
574 | - // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
575 | - if (! defined('DOING_AUTOSAVE')) { |
|
576 | - define('DOING_AUTOSAVE', true); |
|
577 | - } |
|
578 | - // if we made it here then the nonce checked out. Let's run our methods and actions |
|
579 | - $autosave = "_ee_autosave_$this->_current_view"; |
|
580 | - if (method_exists($this, $autosave)) { |
|
581 | - $this->$autosave(); |
|
582 | - } else { |
|
583 | - $this->_template_args['success'] = true; |
|
584 | - } |
|
585 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
586 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
587 | - // now let's return json |
|
588 | - $this->_return_json(); |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
594 | - * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
595 | - * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
596 | - * |
|
597 | - * @return void |
|
598 | - * @throws EE_Error |
|
599 | - * @throws ReflectionException |
|
600 | - */ |
|
601 | - protected function _extend_page_config_for_cpt() |
|
602 | - { |
|
603 | - // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
604 | - if ($this->raw_req_page !== $this->page_slug) { |
|
605 | - return; |
|
606 | - } |
|
607 | - // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
608 | - if (! empty($this->_cpt_object)) { |
|
609 | - $this->_page_routes = array_merge( |
|
610 | - [ |
|
611 | - 'create_new' => [$this, '_create_new_cpt_item'], |
|
612 | - 'edit' => [$this, '_edit_cpt_item'], |
|
613 | - ], |
|
614 | - $this->_page_routes |
|
615 | - ); |
|
616 | - $this->_page_config = array_merge( |
|
617 | - [ |
|
618 | - 'create_new' => [ |
|
619 | - 'nav' => [ |
|
620 | - 'label' => $this->_cpt_object->labels->add_new_item, |
|
621 | - 'order' => 5, |
|
622 | - ], |
|
623 | - 'require_nonce' => false, |
|
624 | - ], |
|
625 | - 'edit' => [ |
|
626 | - 'nav' => [ |
|
627 | - 'label' => $this->_cpt_object->labels->edit_item, |
|
628 | - 'order' => 5, |
|
629 | - 'persistent' => false, |
|
630 | - 'url' => '', |
|
631 | - ], |
|
632 | - 'require_nonce' => false, |
|
633 | - ], |
|
634 | - ], |
|
635 | - $this->_page_config |
|
636 | - ); |
|
637 | - } |
|
638 | - // load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
639 | - if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
640 | - return; |
|
641 | - } |
|
642 | - $this->_cpt_route = true; |
|
643 | - // $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]); |
|
644 | - // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
645 | - if (empty($this->_cpt_object)) { |
|
646 | - $msg = sprintf( |
|
647 | - esc_html__( |
|
648 | - '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).', |
|
649 | - 'event_espresso' |
|
650 | - ), |
|
651 | - $this->page_slug, |
|
652 | - $this->_req_action, |
|
653 | - get_class($this) |
|
654 | - ); |
|
655 | - throw new EE_Error($msg); |
|
656 | - } |
|
657 | - $this->_set_model_object($this->request->getRequestParam('post', 0, DataType::INT)); |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
663 | - * |
|
664 | - * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
665 | - * @param bool $ignore_route_check |
|
666 | - * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
667 | - * @throws EE_Error |
|
668 | - * @throws InvalidArgumentException |
|
669 | - * @throws InvalidDataTypeException |
|
670 | - * @throws InvalidInterfaceException |
|
671 | - * @throws ReflectionException |
|
672 | - */ |
|
673 | - protected function _set_model_object(int $id = 0, bool $ignore_route_check = false, string $req_type = '') |
|
674 | - { |
|
675 | - $model = null; |
|
676 | - if ( |
|
677 | - empty($this->_cpt_model_names) |
|
678 | - || ( |
|
679 | - ! $ignore_route_check |
|
680 | - && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
681 | - ) |
|
682 | - || ( |
|
683 | - $this->_cpt_model_obj instanceof EE_CPT_Base |
|
684 | - && $this->_cpt_model_obj->ID() === $id |
|
685 | - ) |
|
686 | - ) { |
|
687 | - // 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. |
|
688 | - return; |
|
689 | - } |
|
690 | - // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
691 | - if ($ignore_route_check) { |
|
692 | - $post_type = get_post_type($id); |
|
693 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
694 | - $custom_post_types = $this->loader->getShared( |
|
695 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
696 | - ); |
|
697 | - $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
698 | - if (isset($model_names[ $post_type ])) { |
|
699 | - $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
700 | - } |
|
701 | - } else { |
|
702 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
703 | - } |
|
704 | - if ($model instanceof EEM_Base) { |
|
705 | - $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
706 | - } |
|
707 | - do_action( |
|
708 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
709 | - $this->_cpt_model_obj, |
|
710 | - $req_type |
|
711 | - ); |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * admin_init_global |
|
717 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
718 | - * This method executes for ALL EE Admin pages. |
|
719 | - * |
|
720 | - * @return void |
|
721 | - */ |
|
722 | - public function admin_init_global() |
|
723 | - { |
|
724 | - $post_ID = $this->request->getRequestParam('post', 0, DataType::INT); |
|
725 | - // its possible this is a new save so let's catch that instead |
|
726 | - $post_ID = $this->request->getRequestParam('post_ID', $post_ID, DataType::INT); |
|
727 | - $post = get_post($post_ID); |
|
728 | - $post_type = $post instanceof WP_Post ? $post->post_type : false; |
|
729 | - $current_route = $this->request->getRequestParam('current_route', 'shouldneverwork'); |
|
730 | - $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
731 | - ? $this->_cpt_routes[ $current_route ] |
|
732 | - : ''; |
|
733 | - add_filter('get_delete_post_link', [$this, 'modify_delete_post_link'], 10, 2); |
|
734 | - add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 2); |
|
735 | - if ($post_type === $route_to_check) { |
|
736 | - add_filter('redirect_post_location', [$this, 'cpt_post_location_redirect'], 10, 2); |
|
737 | - } |
|
738 | - // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
739 | - $revision = $this->request->getRequestParam('revision'); |
|
740 | - if (! empty($revision)) { |
|
741 | - $action = $this->request->getRequestParam('action'); |
|
742 | - // doing a restore? |
|
743 | - if (! empty($action) && $action === 'restore') { |
|
744 | - // get post for revision |
|
745 | - $rev_post = get_post($revision); |
|
746 | - $rev_parent = get_post($rev_post->post_parent); |
|
747 | - // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
748 | - if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
749 | - add_filter('wp_redirect', [$this, 'revision_redirect'], 10); |
|
750 | - // restores of revisions |
|
751 | - add_action('wp_restore_post_revision', [$this, 'restore_revision'], 10, 2); |
|
752 | - } |
|
753 | - } |
|
754 | - } |
|
755 | - // 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! |
|
756 | - if ($post_type && $post_type === $route_to_check) { |
|
757 | - // $post_id, $post |
|
758 | - add_action('save_post', [$this, 'insert_update'], 10, 3); |
|
759 | - // $post_id |
|
760 | - add_action('trashed_post', [$this, 'before_trash_cpt_item'], 10); |
|
761 | - add_action('trashed_post', [$this, 'dont_permanently_delete_ee_cpts'], 10); |
|
762 | - add_action('untrashed_post', [$this, 'before_restore_cpt_item'], 10); |
|
763 | - add_action('after_delete_post', [$this, 'before_delete_cpt_item'], 10); |
|
764 | - } |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * Callback for the WordPress trashed_post hook. |
|
770 | - * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
771 | - * |
|
772 | - * @param int $post_id |
|
773 | - * @throws EE_Error |
|
774 | - * @throws ReflectionException |
|
775 | - */ |
|
776 | - public function before_trash_cpt_item(int $post_id) |
|
777 | - { |
|
778 | - $this->_set_model_object($post_id, true, 'trash'); |
|
779 | - // if our cpt object isn't existent then get out immediately. |
|
780 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
781 | - return; |
|
782 | - } |
|
783 | - $this->trash_cpt_item($post_id); |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - /** |
|
788 | - * Callback for the WordPress untrashed_post hook. |
|
789 | - * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
790 | - * |
|
791 | - * @param $post_id |
|
792 | - * @throws EE_Error |
|
793 | - * @throws ReflectionException |
|
794 | - */ |
|
795 | - public function before_restore_cpt_item($post_id) |
|
796 | - { |
|
797 | - $this->_set_model_object($post_id, true, 'restore'); |
|
798 | - // if our cpt object isn't existent then get out immediately. |
|
799 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
800 | - return; |
|
801 | - } |
|
802 | - $this->restore_cpt_item($post_id); |
|
803 | - } |
|
804 | - |
|
805 | - |
|
806 | - /** |
|
807 | - * Callback for the WordPress after_delete_post hook. |
|
808 | - * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
809 | - * |
|
810 | - * @param $post_id |
|
811 | - * @throws EE_Error |
|
812 | - * @throws ReflectionException |
|
813 | - */ |
|
814 | - public function before_delete_cpt_item($post_id) |
|
815 | - { |
|
816 | - $this->_set_model_object($post_id, true, 'delete'); |
|
817 | - // if our cpt object isn't existent then get out immediately. |
|
818 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
819 | - return; |
|
820 | - } |
|
821 | - $this->delete_cpt_item($post_id); |
|
822 | - } |
|
823 | - |
|
824 | - |
|
825 | - /** |
|
826 | - * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
827 | - * accordingly. |
|
828 | - * |
|
829 | - * @return void |
|
830 | - * @throws EE_Error |
|
831 | - * @throws ReflectionException |
|
832 | - */ |
|
833 | - public function verify_cpt_object() |
|
834 | - { |
|
835 | - $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
836 | - // verify event object |
|
837 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
838 | - throw new EE_Error( |
|
839 | - sprintf( |
|
840 | - esc_html__( |
|
841 | - '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', |
|
842 | - 'event_espresso' |
|
843 | - ), |
|
844 | - $label |
|
845 | - ) |
|
846 | - ); |
|
847 | - } |
|
848 | - // if auto-draft then throw an error |
|
849 | - if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
850 | - EE_Error::overwrite_errors(); |
|
851 | - EE_Error::add_error( |
|
852 | - sprintf( |
|
853 | - esc_html__( |
|
854 | - '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.', |
|
855 | - 'event_espresso' |
|
856 | - ), |
|
857 | - $label |
|
858 | - ), |
|
859 | - __FILE__, |
|
860 | - __FUNCTION__, |
|
861 | - __LINE__ |
|
862 | - ); |
|
863 | - } |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - /** |
|
868 | - * admin_footer_scripts_global |
|
869 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
870 | - * will apply on ALL EE_Admin pages. |
|
871 | - * |
|
872 | - * @return void |
|
873 | - */ |
|
874 | - public function admin_footer_scripts_global() |
|
875 | - { |
|
876 | - $this->_add_admin_page_ajax_loading_img(); |
|
877 | - $this->_add_admin_page_overlay(); |
|
878 | - } |
|
879 | - |
|
880 | - |
|
881 | - /** |
|
882 | - * add in any global scripts for cpt routes |
|
883 | - * |
|
884 | - * @return void |
|
885 | - */ |
|
886 | - public function load_global_scripts_styles() |
|
887 | - { |
|
888 | - parent::load_global_scripts_styles(); |
|
889 | - if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
890 | - // setup custom post status object for localize script but only if we've got a cpt object |
|
891 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
892 | - if (! empty($statuses)) { |
|
893 | - // get ALL statuses! |
|
894 | - $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
895 | - // setup object |
|
896 | - $ee_cpt_statuses = []; |
|
897 | - foreach ($statuses as $status => $label) { |
|
898 | - $ee_cpt_statuses[ $status ] = [ |
|
899 | - 'label' => $label, |
|
900 | - 'save_label' => sprintf( |
|
901 | - wp_strip_all_tags(__('Save as %s', 'event_espresso')), |
|
902 | - $label |
|
903 | - ), |
|
904 | - ]; |
|
905 | - } |
|
906 | - wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
907 | - } |
|
908 | - } |
|
909 | - } |
|
910 | - |
|
911 | - |
|
912 | - /** |
|
913 | - * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
914 | - * insert/updates |
|
915 | - * |
|
916 | - * @param int $post_id ID of post being updated |
|
917 | - * @param WP_Post $post Post object from WP |
|
918 | - * @param bool $update Whether this is an update or a new save. |
|
919 | - * @return void |
|
920 | - * @throws EE_Error |
|
921 | - * @throws ReflectionException |
|
922 | - */ |
|
923 | - public function insert_update(int $post_id, WP_Post $post, bool $update) |
|
924 | - { |
|
925 | - // make sure that if this is a revision OR trash action that we don't do any updates! |
|
926 | - $action = $this->request->getRequestParam('action'); |
|
927 | - if ($action === 'restore' || $action === 'trash') { |
|
928 | - return; |
|
929 | - } |
|
930 | - $this->_set_model_object($post_id, true, 'insert_update'); |
|
931 | - // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
932 | - if ( |
|
933 | - $update |
|
934 | - && ( |
|
935 | - ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
936 | - || $this->_cpt_model_obj->ID() !== $post_id |
|
937 | - ) |
|
938 | - ) { |
|
939 | - return; |
|
940 | - } |
|
941 | - // check for autosave and update our req_data property accordingly. |
|
942 | - /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
497 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
498 | + * |
|
499 | + * @param string $return the current html |
|
500 | + * @param int $id the post id for the page |
|
501 | + * @return string The new html string for the permalink area |
|
502 | + * @deprecated 5.0.0.p |
|
503 | + * @see PreviewButton::addButton() |
|
504 | + */ |
|
505 | + public function preview_button_html(string $return, int $id): string |
|
506 | + { |
|
507 | + return PreviewButton::addButton($return, $id); |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * add our custom post status dropdown on the wp post page for this cpt |
|
513 | + * |
|
514 | + * @return void |
|
515 | + */ |
|
516 | + public function custom_post_stati_dropdown() |
|
517 | + { |
|
518 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
519 | + $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
520 | + ? $statuses[ $this->_cpt_model_obj->status() ] |
|
521 | + : ''; |
|
522 | + $template_args = [ |
|
523 | + 'cur_status' => $this->_cpt_model_obj->status(), |
|
524 | + 'statuses' => $statuses, |
|
525 | + 'cur_status_label' => $cur_status_label, |
|
526 | + 'localized_status_save' => sprintf(esc_html__('Save %s', 'event_espresso'), $cur_status_label), |
|
527 | + ]; |
|
528 | + // we'll add a trash post status (WP doesn't add one for some reason) |
|
529 | + if ($this->_cpt_model_obj->status() === 'trash') { |
|
530 | + $template_args['cur_status_label'] = esc_html__('Trashed', 'event_espresso'); |
|
531 | + $statuses['trash'] = esc_html__('Trashed', 'event_espresso'); |
|
532 | + $template_args['statuses'] = $statuses; |
|
533 | + } |
|
534 | + |
|
535 | + $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
536 | + EEH_Template::display_template($template, $template_args); |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + public function setup_autosave_hooks() |
|
541 | + { |
|
542 | + $this->_set_autosave_containers(); |
|
543 | + $this->_load_autosave_scripts_styles(); |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a post object (available |
|
549 | + * in request data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
550 | + * for the nonce in here, but then this method looks for two things: |
|
551 | + * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
552 | + * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
553 | + * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
554 | + * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
555 | + * template args. |
|
556 | + * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
557 | + * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
558 | + * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
559 | + * $this->_template_args['data']['items'] = array( |
|
560 | + * 'event-datetime-ids' => '1,2,3'; |
|
561 | + * ); |
|
562 | + * Keep in mind the following things: |
|
563 | + * - "where" index is for the input with the id as that string. |
|
564 | + * - "what" index is what will be used for the value of that input. |
|
565 | + * |
|
566 | + * @return void |
|
567 | + * @throws EE_Error |
|
568 | + */ |
|
569 | + public function do_extra_autosave_stuff() |
|
570 | + { |
|
571 | + // next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
572 | + $nonce = $this->request->getRequestParam('autosavenonce'); |
|
573 | + $this->_verify_nonce($nonce, 'autosave'); |
|
574 | + // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
575 | + if (! defined('DOING_AUTOSAVE')) { |
|
576 | + define('DOING_AUTOSAVE', true); |
|
577 | + } |
|
578 | + // if we made it here then the nonce checked out. Let's run our methods and actions |
|
579 | + $autosave = "_ee_autosave_$this->_current_view"; |
|
580 | + if (method_exists($this, $autosave)) { |
|
581 | + $this->$autosave(); |
|
582 | + } else { |
|
583 | + $this->_template_args['success'] = true; |
|
584 | + } |
|
585 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
586 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
587 | + // now let's return json |
|
588 | + $this->_return_json(); |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
594 | + * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
595 | + * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
596 | + * |
|
597 | + * @return void |
|
598 | + * @throws EE_Error |
|
599 | + * @throws ReflectionException |
|
600 | + */ |
|
601 | + protected function _extend_page_config_for_cpt() |
|
602 | + { |
|
603 | + // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
604 | + if ($this->raw_req_page !== $this->page_slug) { |
|
605 | + return; |
|
606 | + } |
|
607 | + // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
608 | + if (! empty($this->_cpt_object)) { |
|
609 | + $this->_page_routes = array_merge( |
|
610 | + [ |
|
611 | + 'create_new' => [$this, '_create_new_cpt_item'], |
|
612 | + 'edit' => [$this, '_edit_cpt_item'], |
|
613 | + ], |
|
614 | + $this->_page_routes |
|
615 | + ); |
|
616 | + $this->_page_config = array_merge( |
|
617 | + [ |
|
618 | + 'create_new' => [ |
|
619 | + 'nav' => [ |
|
620 | + 'label' => $this->_cpt_object->labels->add_new_item, |
|
621 | + 'order' => 5, |
|
622 | + ], |
|
623 | + 'require_nonce' => false, |
|
624 | + ], |
|
625 | + 'edit' => [ |
|
626 | + 'nav' => [ |
|
627 | + 'label' => $this->_cpt_object->labels->edit_item, |
|
628 | + 'order' => 5, |
|
629 | + 'persistent' => false, |
|
630 | + 'url' => '', |
|
631 | + ], |
|
632 | + 'require_nonce' => false, |
|
633 | + ], |
|
634 | + ], |
|
635 | + $this->_page_config |
|
636 | + ); |
|
637 | + } |
|
638 | + // load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
639 | + if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
640 | + return; |
|
641 | + } |
|
642 | + $this->_cpt_route = true; |
|
643 | + // $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]); |
|
644 | + // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
645 | + if (empty($this->_cpt_object)) { |
|
646 | + $msg = sprintf( |
|
647 | + esc_html__( |
|
648 | + '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).', |
|
649 | + 'event_espresso' |
|
650 | + ), |
|
651 | + $this->page_slug, |
|
652 | + $this->_req_action, |
|
653 | + get_class($this) |
|
654 | + ); |
|
655 | + throw new EE_Error($msg); |
|
656 | + } |
|
657 | + $this->_set_model_object($this->request->getRequestParam('post', 0, DataType::INT)); |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
663 | + * |
|
664 | + * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
665 | + * @param bool $ignore_route_check |
|
666 | + * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
667 | + * @throws EE_Error |
|
668 | + * @throws InvalidArgumentException |
|
669 | + * @throws InvalidDataTypeException |
|
670 | + * @throws InvalidInterfaceException |
|
671 | + * @throws ReflectionException |
|
672 | + */ |
|
673 | + protected function _set_model_object(int $id = 0, bool $ignore_route_check = false, string $req_type = '') |
|
674 | + { |
|
675 | + $model = null; |
|
676 | + if ( |
|
677 | + empty($this->_cpt_model_names) |
|
678 | + || ( |
|
679 | + ! $ignore_route_check |
|
680 | + && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
681 | + ) |
|
682 | + || ( |
|
683 | + $this->_cpt_model_obj instanceof EE_CPT_Base |
|
684 | + && $this->_cpt_model_obj->ID() === $id |
|
685 | + ) |
|
686 | + ) { |
|
687 | + // 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. |
|
688 | + return; |
|
689 | + } |
|
690 | + // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
691 | + if ($ignore_route_check) { |
|
692 | + $post_type = get_post_type($id); |
|
693 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
694 | + $custom_post_types = $this->loader->getShared( |
|
695 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
696 | + ); |
|
697 | + $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
698 | + if (isset($model_names[ $post_type ])) { |
|
699 | + $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
700 | + } |
|
701 | + } else { |
|
702 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
703 | + } |
|
704 | + if ($model instanceof EEM_Base) { |
|
705 | + $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
706 | + } |
|
707 | + do_action( |
|
708 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
709 | + $this->_cpt_model_obj, |
|
710 | + $req_type |
|
711 | + ); |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * admin_init_global |
|
717 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
718 | + * This method executes for ALL EE Admin pages. |
|
719 | + * |
|
720 | + * @return void |
|
721 | + */ |
|
722 | + public function admin_init_global() |
|
723 | + { |
|
724 | + $post_ID = $this->request->getRequestParam('post', 0, DataType::INT); |
|
725 | + // its possible this is a new save so let's catch that instead |
|
726 | + $post_ID = $this->request->getRequestParam('post_ID', $post_ID, DataType::INT); |
|
727 | + $post = get_post($post_ID); |
|
728 | + $post_type = $post instanceof WP_Post ? $post->post_type : false; |
|
729 | + $current_route = $this->request->getRequestParam('current_route', 'shouldneverwork'); |
|
730 | + $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
731 | + ? $this->_cpt_routes[ $current_route ] |
|
732 | + : ''; |
|
733 | + add_filter('get_delete_post_link', [$this, 'modify_delete_post_link'], 10, 2); |
|
734 | + add_filter('get_edit_post_link', [$this, 'modify_edit_post_link'], 10, 2); |
|
735 | + if ($post_type === $route_to_check) { |
|
736 | + add_filter('redirect_post_location', [$this, 'cpt_post_location_redirect'], 10, 2); |
|
737 | + } |
|
738 | + // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
739 | + $revision = $this->request->getRequestParam('revision'); |
|
740 | + if (! empty($revision)) { |
|
741 | + $action = $this->request->getRequestParam('action'); |
|
742 | + // doing a restore? |
|
743 | + if (! empty($action) && $action === 'restore') { |
|
744 | + // get post for revision |
|
745 | + $rev_post = get_post($revision); |
|
746 | + $rev_parent = get_post($rev_post->post_parent); |
|
747 | + // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
748 | + if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
749 | + add_filter('wp_redirect', [$this, 'revision_redirect'], 10); |
|
750 | + // restores of revisions |
|
751 | + add_action('wp_restore_post_revision', [$this, 'restore_revision'], 10, 2); |
|
752 | + } |
|
753 | + } |
|
754 | + } |
|
755 | + // 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! |
|
756 | + if ($post_type && $post_type === $route_to_check) { |
|
757 | + // $post_id, $post |
|
758 | + add_action('save_post', [$this, 'insert_update'], 10, 3); |
|
759 | + // $post_id |
|
760 | + add_action('trashed_post', [$this, 'before_trash_cpt_item'], 10); |
|
761 | + add_action('trashed_post', [$this, 'dont_permanently_delete_ee_cpts'], 10); |
|
762 | + add_action('untrashed_post', [$this, 'before_restore_cpt_item'], 10); |
|
763 | + add_action('after_delete_post', [$this, 'before_delete_cpt_item'], 10); |
|
764 | + } |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * Callback for the WordPress trashed_post hook. |
|
770 | + * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
771 | + * |
|
772 | + * @param int $post_id |
|
773 | + * @throws EE_Error |
|
774 | + * @throws ReflectionException |
|
775 | + */ |
|
776 | + public function before_trash_cpt_item(int $post_id) |
|
777 | + { |
|
778 | + $this->_set_model_object($post_id, true, 'trash'); |
|
779 | + // if our cpt object isn't existent then get out immediately. |
|
780 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
781 | + return; |
|
782 | + } |
|
783 | + $this->trash_cpt_item($post_id); |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + /** |
|
788 | + * Callback for the WordPress untrashed_post hook. |
|
789 | + * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
790 | + * |
|
791 | + * @param $post_id |
|
792 | + * @throws EE_Error |
|
793 | + * @throws ReflectionException |
|
794 | + */ |
|
795 | + public function before_restore_cpt_item($post_id) |
|
796 | + { |
|
797 | + $this->_set_model_object($post_id, true, 'restore'); |
|
798 | + // if our cpt object isn't existent then get out immediately. |
|
799 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
800 | + return; |
|
801 | + } |
|
802 | + $this->restore_cpt_item($post_id); |
|
803 | + } |
|
804 | + |
|
805 | + |
|
806 | + /** |
|
807 | + * Callback for the WordPress after_delete_post hook. |
|
808 | + * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
809 | + * |
|
810 | + * @param $post_id |
|
811 | + * @throws EE_Error |
|
812 | + * @throws ReflectionException |
|
813 | + */ |
|
814 | + public function before_delete_cpt_item($post_id) |
|
815 | + { |
|
816 | + $this->_set_model_object($post_id, true, 'delete'); |
|
817 | + // if our cpt object isn't existent then get out immediately. |
|
818 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
819 | + return; |
|
820 | + } |
|
821 | + $this->delete_cpt_item($post_id); |
|
822 | + } |
|
823 | + |
|
824 | + |
|
825 | + /** |
|
826 | + * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
827 | + * accordingly. |
|
828 | + * |
|
829 | + * @return void |
|
830 | + * @throws EE_Error |
|
831 | + * @throws ReflectionException |
|
832 | + */ |
|
833 | + public function verify_cpt_object() |
|
834 | + { |
|
835 | + $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
836 | + // verify event object |
|
837 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
838 | + throw new EE_Error( |
|
839 | + sprintf( |
|
840 | + esc_html__( |
|
841 | + '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', |
|
842 | + 'event_espresso' |
|
843 | + ), |
|
844 | + $label |
|
845 | + ) |
|
846 | + ); |
|
847 | + } |
|
848 | + // if auto-draft then throw an error |
|
849 | + if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
850 | + EE_Error::overwrite_errors(); |
|
851 | + EE_Error::add_error( |
|
852 | + sprintf( |
|
853 | + esc_html__( |
|
854 | + '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.', |
|
855 | + 'event_espresso' |
|
856 | + ), |
|
857 | + $label |
|
858 | + ), |
|
859 | + __FILE__, |
|
860 | + __FUNCTION__, |
|
861 | + __LINE__ |
|
862 | + ); |
|
863 | + } |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + /** |
|
868 | + * admin_footer_scripts_global |
|
869 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
870 | + * will apply on ALL EE_Admin pages. |
|
871 | + * |
|
872 | + * @return void |
|
873 | + */ |
|
874 | + public function admin_footer_scripts_global() |
|
875 | + { |
|
876 | + $this->_add_admin_page_ajax_loading_img(); |
|
877 | + $this->_add_admin_page_overlay(); |
|
878 | + } |
|
879 | + |
|
880 | + |
|
881 | + /** |
|
882 | + * add in any global scripts for cpt routes |
|
883 | + * |
|
884 | + * @return void |
|
885 | + */ |
|
886 | + public function load_global_scripts_styles() |
|
887 | + { |
|
888 | + parent::load_global_scripts_styles(); |
|
889 | + if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
890 | + // setup custom post status object for localize script but only if we've got a cpt object |
|
891 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
892 | + if (! empty($statuses)) { |
|
893 | + // get ALL statuses! |
|
894 | + $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
895 | + // setup object |
|
896 | + $ee_cpt_statuses = []; |
|
897 | + foreach ($statuses as $status => $label) { |
|
898 | + $ee_cpt_statuses[ $status ] = [ |
|
899 | + 'label' => $label, |
|
900 | + 'save_label' => sprintf( |
|
901 | + wp_strip_all_tags(__('Save as %s', 'event_espresso')), |
|
902 | + $label |
|
903 | + ), |
|
904 | + ]; |
|
905 | + } |
|
906 | + wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
907 | + } |
|
908 | + } |
|
909 | + } |
|
910 | + |
|
911 | + |
|
912 | + /** |
|
913 | + * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
914 | + * insert/updates |
|
915 | + * |
|
916 | + * @param int $post_id ID of post being updated |
|
917 | + * @param WP_Post $post Post object from WP |
|
918 | + * @param bool $update Whether this is an update or a new save. |
|
919 | + * @return void |
|
920 | + * @throws EE_Error |
|
921 | + * @throws ReflectionException |
|
922 | + */ |
|
923 | + public function insert_update(int $post_id, WP_Post $post, bool $update) |
|
924 | + { |
|
925 | + // make sure that if this is a revision OR trash action that we don't do any updates! |
|
926 | + $action = $this->request->getRequestParam('action'); |
|
927 | + if ($action === 'restore' || $action === 'trash') { |
|
928 | + return; |
|
929 | + } |
|
930 | + $this->_set_model_object($post_id, true, 'insert_update'); |
|
931 | + // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
932 | + if ( |
|
933 | + $update |
|
934 | + && ( |
|
935 | + ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
936 | + || $this->_cpt_model_obj->ID() !== $post_id |
|
937 | + ) |
|
938 | + ) { |
|
939 | + return; |
|
940 | + } |
|
941 | + // check for autosave and update our req_data property accordingly. |
|
942 | + /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
943 | 943 | foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) { |
944 | 944 | |
945 | 945 | foreach ( (array) $values as $key => $value ) { |
@@ -949,540 +949,540 @@ discard block |
||
949 | 949 | |
950 | 950 | }/**/ // TODO reactivate after autosave is implemented in 4.2 |
951 | 951 | |
952 | - // take care of updating any selected page_template IF this cpt supports it. |
|
953 | - |
|
954 | - $page_template = $this->request->getRequestParam('page_template'); |
|
955 | - if ($this->_supports_page_templates($post->post_type) && ! empty($page_template)) { |
|
956 | - // wp version aware. |
|
957 | - if (RecommendedVersions::compareWordPressVersion('4.7')) { |
|
958 | - $page_templates = wp_get_theme()->get_page_templates(); |
|
959 | - } else { |
|
960 | - $post->page_template = $page_template; |
|
961 | - $page_templates = wp_get_theme()->get_page_templates($post); |
|
962 | - } |
|
963 | - if ($page_template !== 'default' && ! isset($page_templates[ $page_template ])) { |
|
964 | - EE_Error::add_error( |
|
965 | - esc_html__('Invalid Page Template.', 'event_espresso'), |
|
966 | - __FILE__, |
|
967 | - __FUNCTION__, |
|
968 | - __LINE__ |
|
969 | - ); |
|
970 | - } else { |
|
971 | - update_post_meta($post_id, '_wp_page_template', $page_template); |
|
972 | - } |
|
973 | - } |
|
974 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
975 | - return; |
|
976 | - } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
977 | - $this->_insert_update_cpt_item($post_id, $post); |
|
978 | - } |
|
979 | - |
|
980 | - |
|
981 | - /** |
|
982 | - * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
983 | - * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
984 | - * so we don't have to check for our CPT. |
|
985 | - * |
|
986 | - * @param int $post_id ID of the post |
|
987 | - * @return void |
|
988 | - */ |
|
989 | - public function dont_permanently_delete_ee_cpts(int $post_id) |
|
990 | - { |
|
991 | - // only do this if we're actually processing one of our CPTs |
|
992 | - // if our cpt object isn't existent then get out immediately. |
|
993 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
994 | - return; |
|
995 | - } |
|
996 | - delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
997 | - delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
998 | - // our cpts may have comments so let's take care of that too |
|
999 | - delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
1000 | - } |
|
1001 | - |
|
1002 | - |
|
1003 | - /** |
|
1004 | - * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1005 | - * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1006 | - * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1007 | - * |
|
1008 | - * @param int $post_id ID of cpt item |
|
1009 | - * @param int $revision_id ID of revision being restored |
|
1010 | - * @return void |
|
1011 | - */ |
|
1012 | - public function restore_revision(int $post_id, int $revision_id) |
|
1013 | - { |
|
1014 | - $this->_restore_cpt_item($post_id, $revision_id); |
|
1015 | - // global action |
|
1016 | - do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1017 | - // class specific action so you can limit hooking into a specific page. |
|
1018 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - /** |
|
1023 | - * @param int $post_id ID of cpt item |
|
1024 | - * @param int $revision_id ID of revision for item |
|
1025 | - * @return void |
|
1026 | - * @see restore_revision() for details |
|
1027 | - */ |
|
1028 | - abstract protected function _restore_cpt_item(int $post_id, int $revision_id); |
|
1029 | - |
|
1030 | - |
|
1031 | - /** |
|
1032 | - * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1033 | - * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1034 | - * To fix we have to reset the current_screen using the page_slug |
|
1035 | - * (which is identical - or should be - to our registered_post_type id.) |
|
1036 | - * Also, since the core WP file loads the admin_header.php for WP |
|
1037 | - * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1038 | - * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1039 | - * |
|
1040 | - * @return void |
|
1041 | - * @throws EE_Error |
|
1042 | - * @throws ReflectionException |
|
1043 | - */ |
|
1044 | - public function modify_current_screen() |
|
1045 | - { |
|
1046 | - // ONLY do this if the current page_route IS a cpt route |
|
1047 | - if (! $this->_cpt_route) { |
|
1048 | - return; |
|
1049 | - } |
|
1050 | - // routing things REALLY early b/c this is a cpt admin page |
|
1051 | - set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
1052 | - $this->_current_screen = get_current_screen(); |
|
1053 | - $this->_current_screen->base = 'event-espresso'; |
|
1054 | - $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
|
1055 | - /*try { |
|
952 | + // take care of updating any selected page_template IF this cpt supports it. |
|
953 | + |
|
954 | + $page_template = $this->request->getRequestParam('page_template'); |
|
955 | + if ($this->_supports_page_templates($post->post_type) && ! empty($page_template)) { |
|
956 | + // wp version aware. |
|
957 | + if (RecommendedVersions::compareWordPressVersion('4.7')) { |
|
958 | + $page_templates = wp_get_theme()->get_page_templates(); |
|
959 | + } else { |
|
960 | + $post->page_template = $page_template; |
|
961 | + $page_templates = wp_get_theme()->get_page_templates($post); |
|
962 | + } |
|
963 | + if ($page_template !== 'default' && ! isset($page_templates[ $page_template ])) { |
|
964 | + EE_Error::add_error( |
|
965 | + esc_html__('Invalid Page Template.', 'event_espresso'), |
|
966 | + __FILE__, |
|
967 | + __FUNCTION__, |
|
968 | + __LINE__ |
|
969 | + ); |
|
970 | + } else { |
|
971 | + update_post_meta($post_id, '_wp_page_template', $page_template); |
|
972 | + } |
|
973 | + } |
|
974 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
975 | + return; |
|
976 | + } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
977 | + $this->_insert_update_cpt_item($post_id, $post); |
|
978 | + } |
|
979 | + |
|
980 | + |
|
981 | + /** |
|
982 | + * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
983 | + * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
984 | + * so we don't have to check for our CPT. |
|
985 | + * |
|
986 | + * @param int $post_id ID of the post |
|
987 | + * @return void |
|
988 | + */ |
|
989 | + public function dont_permanently_delete_ee_cpts(int $post_id) |
|
990 | + { |
|
991 | + // only do this if we're actually processing one of our CPTs |
|
992 | + // if our cpt object isn't existent then get out immediately. |
|
993 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
994 | + return; |
|
995 | + } |
|
996 | + delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
997 | + delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
998 | + // our cpts may have comments so let's take care of that too |
|
999 | + delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
1000 | + } |
|
1001 | + |
|
1002 | + |
|
1003 | + /** |
|
1004 | + * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1005 | + * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1006 | + * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1007 | + * |
|
1008 | + * @param int $post_id ID of cpt item |
|
1009 | + * @param int $revision_id ID of revision being restored |
|
1010 | + * @return void |
|
1011 | + */ |
|
1012 | + public function restore_revision(int $post_id, int $revision_id) |
|
1013 | + { |
|
1014 | + $this->_restore_cpt_item($post_id, $revision_id); |
|
1015 | + // global action |
|
1016 | + do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1017 | + // class specific action so you can limit hooking into a specific page. |
|
1018 | + do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + /** |
|
1023 | + * @param int $post_id ID of cpt item |
|
1024 | + * @param int $revision_id ID of revision for item |
|
1025 | + * @return void |
|
1026 | + * @see restore_revision() for details |
|
1027 | + */ |
|
1028 | + abstract protected function _restore_cpt_item(int $post_id, int $revision_id); |
|
1029 | + |
|
1030 | + |
|
1031 | + /** |
|
1032 | + * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1033 | + * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1034 | + * To fix we have to reset the current_screen using the page_slug |
|
1035 | + * (which is identical - or should be - to our registered_post_type id.) |
|
1036 | + * Also, since the core WP file loads the admin_header.php for WP |
|
1037 | + * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1038 | + * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1039 | + * |
|
1040 | + * @return void |
|
1041 | + * @throws EE_Error |
|
1042 | + * @throws ReflectionException |
|
1043 | + */ |
|
1044 | + public function modify_current_screen() |
|
1045 | + { |
|
1046 | + // ONLY do this if the current page_route IS a cpt route |
|
1047 | + if (! $this->_cpt_route) { |
|
1048 | + return; |
|
1049 | + } |
|
1050 | + // routing things REALLY early b/c this is a cpt admin page |
|
1051 | + set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
1052 | + $this->_current_screen = get_current_screen(); |
|
1053 | + $this->_current_screen->base = 'event-espresso'; |
|
1054 | + $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
|
1055 | + /*try { |
|
1056 | 1056 | $this->_route_admin_request(); |
1057 | 1057 | } catch ( EE_Error $e ) { |
1058 | 1058 | $e->get_error(); |
1059 | 1059 | }/**/ |
1060 | - } |
|
1061 | - |
|
1062 | - |
|
1063 | - /** |
|
1064 | - * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1065 | - * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1066 | - * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1067 | - * default to be. |
|
1068 | - * |
|
1069 | - * @param string $title The new title (or existing if there is no editor_title defined) |
|
1070 | - * @return string |
|
1071 | - */ |
|
1072 | - public function add_custom_editor_default_title(string $title): string |
|
1073 | - { |
|
1074 | - return $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] ?? $title; |
|
1075 | - } |
|
1076 | - |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1080 | - * |
|
1081 | - * @param string $shortlink The already generated shortlink |
|
1082 | - * @param int $id Post ID for this item |
|
1083 | - * @return string |
|
1084 | - * @deprecated 5.0.0.p |
|
1085 | - * @see EventShortlinkButton::addButton() |
|
1086 | - */ |
|
1087 | - public function add_shortlink_button_to_editor(string $shortlink, int $id): string |
|
1088 | - { |
|
1089 | - return EventShortlinkButton::addButton($shortlink, $id); |
|
1090 | - } |
|
1091 | - |
|
1092 | - |
|
1093 | - /** |
|
1094 | - * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1095 | - * already run in modify_current_screen()) |
|
1096 | - * |
|
1097 | - * @return void |
|
1098 | - * @throws EE_Error |
|
1099 | - * @throws ReflectionException |
|
1100 | - */ |
|
1101 | - public function route_admin_request() |
|
1102 | - { |
|
1103 | - if ($this->_cpt_route) { |
|
1104 | - return; |
|
1105 | - } |
|
1106 | - try { |
|
1107 | - $this->_route_admin_request(); |
|
1108 | - } catch (EE_Error $e) { |
|
1109 | - $e->get_error(); |
|
1110 | - } |
|
1111 | - } |
|
1112 | - |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1116 | - * |
|
1117 | - * @return void |
|
1118 | - */ |
|
1119 | - public function cpt_post_form_hidden_input() |
|
1120 | - { |
|
1121 | - // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1122 | - echo ' |
|
1060 | + } |
|
1061 | + |
|
1062 | + |
|
1063 | + /** |
|
1064 | + * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1065 | + * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1066 | + * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1067 | + * default to be. |
|
1068 | + * |
|
1069 | + * @param string $title The new title (or existing if there is no editor_title defined) |
|
1070 | + * @return string |
|
1071 | + */ |
|
1072 | + public function add_custom_editor_default_title(string $title): string |
|
1073 | + { |
|
1074 | + return $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] ?? $title; |
|
1075 | + } |
|
1076 | + |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1080 | + * |
|
1081 | + * @param string $shortlink The already generated shortlink |
|
1082 | + * @param int $id Post ID for this item |
|
1083 | + * @return string |
|
1084 | + * @deprecated 5.0.0.p |
|
1085 | + * @see EventShortlinkButton::addButton() |
|
1086 | + */ |
|
1087 | + public function add_shortlink_button_to_editor(string $shortlink, int $id): string |
|
1088 | + { |
|
1089 | + return EventShortlinkButton::addButton($shortlink, $id); |
|
1090 | + } |
|
1091 | + |
|
1092 | + |
|
1093 | + /** |
|
1094 | + * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1095 | + * already run in modify_current_screen()) |
|
1096 | + * |
|
1097 | + * @return void |
|
1098 | + * @throws EE_Error |
|
1099 | + * @throws ReflectionException |
|
1100 | + */ |
|
1101 | + public function route_admin_request() |
|
1102 | + { |
|
1103 | + if ($this->_cpt_route) { |
|
1104 | + return; |
|
1105 | + } |
|
1106 | + try { |
|
1107 | + $this->_route_admin_request(); |
|
1108 | + } catch (EE_Error $e) { |
|
1109 | + $e->get_error(); |
|
1110 | + } |
|
1111 | + } |
|
1112 | + |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1116 | + * |
|
1117 | + * @return void |
|
1118 | + */ |
|
1119 | + public function cpt_post_form_hidden_input() |
|
1120 | + { |
|
1121 | + // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1122 | + echo ' |
|
1123 | 1123 | <input type="hidden" name="ee_cpt_item_redirect_url" value="' . esc_url_raw($this->_admin_base_url) . '"/> |
1124 | 1124 | <div id="ee-cpt-hidden-inputs"> |
1125 | 1125 | <input type="hidden" id="current_route" name="current_route" value="' . esc_attr($this->_current_view) . '"/> |
1126 | 1126 | <input type="hidden" id="current_page" name="current_page" value="' . esc_attr($this->page_slug) . '"/> |
1127 | 1127 | </div>'; |
1128 | - } |
|
1129 | - |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1133 | - * |
|
1134 | - * @param string $location Original location url |
|
1135 | - * @return string new (or original) url to redirect to. |
|
1136 | - * @throws EE_Error |
|
1137 | - */ |
|
1138 | - public function revision_redirect(string $location): string |
|
1139 | - { |
|
1140 | - // get revision |
|
1141 | - $revision = $this->request->getRequestParam('revision'); |
|
1142 | - // can't do anything without revision so let's get out if not present |
|
1143 | - if (empty($revision)) { |
|
1144 | - return $location; |
|
1145 | - } |
|
1146 | - // get rev_post_data |
|
1147 | - $rev = get_post($revision); |
|
1148 | - $admin_url = $this->_admin_base_url; |
|
1149 | - $query_args = [ |
|
1150 | - 'action' => 'edit', |
|
1151 | - 'post' => $rev->post_parent, |
|
1152 | - 'revision' => $revision, |
|
1153 | - 'message' => 5, |
|
1154 | - ]; |
|
1155 | - $this->_process_notices($query_args, true); |
|
1156 | - return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url); |
|
1157 | - } |
|
1158 | - |
|
1159 | - |
|
1160 | - /** |
|
1161 | - * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1162 | - * |
|
1163 | - * @param string $link the original generated link |
|
1164 | - * @param int $id post id |
|
1165 | - * @return string the link |
|
1166 | - */ |
|
1167 | - public function modify_edit_post_link(string $link, int $id): string |
|
1168 | - { |
|
1169 | - $post = get_post($id); |
|
1170 | - $action = $this->request->getRequestParam('action'); |
|
1171 | - if ( |
|
1172 | - empty($action) |
|
1173 | - || ! isset($this->_cpt_routes[ $action ]) |
|
1174 | - || $post->post_type !== $this->_cpt_routes[ $action ] |
|
1175 | - ) { |
|
1176 | - return $link; |
|
1177 | - } |
|
1178 | - $query_args = [ |
|
1179 | - 'action' => $this->_cpt_edit_routes[ $post->post_type ] ?? 'edit', |
|
1180 | - 'post' => $id, |
|
1181 | - ]; |
|
1182 | - return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1183 | - } |
|
1184 | - |
|
1185 | - |
|
1186 | - /** |
|
1187 | - * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1188 | - * our routes. |
|
1189 | - * |
|
1190 | - * @param string $delete_link original delete link |
|
1191 | - * @param int $post_id id of cpt object |
|
1192 | - * @return string new delete link |
|
1193 | - * @throws EE_Error |
|
1194 | - * @throws ReflectionException |
|
1195 | - */ |
|
1196 | - public function modify_delete_post_link(string $delete_link, int $post_id): string |
|
1197 | - { |
|
1198 | - $post = get_post($post_id); |
|
1199 | - $action = $this->request->getRequestParam('action'); |
|
1200 | - if ( |
|
1201 | - ! $post instanceof WP_Post |
|
1202 | - || empty($action) |
|
1203 | - || ! isset($this->_cpt_routes[ $action ]) |
|
1204 | - || $post->post_type !== $this->_cpt_routes[ $action ] |
|
1205 | - ) { |
|
1206 | - return $delete_link; |
|
1207 | - } |
|
1208 | - $this->_set_model_object($post->ID, true); |
|
1209 | - |
|
1210 | - // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1211 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1212 | - |
|
1213 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
1214 | - [ |
|
1215 | - 'page' => $this->request->getRequestParam('page'), |
|
1216 | - 'action' => $action, |
|
1217 | - $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() => $post->ID, |
|
1218 | - ], |
|
1219 | - admin_url() |
|
1220 | - ); |
|
1221 | - } |
|
1222 | - |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1226 | - * so that we can hijack the default redirect locations for wp custom post types |
|
1227 | - * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1228 | - * |
|
1229 | - * @param string $location This is the incoming currently set redirect location |
|
1230 | - * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1231 | - * @return string the new location to redirect to |
|
1232 | - * @throws EE_Error |
|
1233 | - */ |
|
1234 | - public function cpt_post_location_redirect(string $location, string $post_id): string |
|
1235 | - { |
|
1236 | - // we DO have a match so let's setup the url |
|
1237 | - // we have to get the post to determine our route |
|
1238 | - $post = get_post($post_id); |
|
1239 | - $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
1240 | - // shared query_args |
|
1241 | - $query_args = ['action' => $edit_route, 'post' => $post_id]; |
|
1242 | - |
|
1243 | - $save = $this->request->getRequestParam('save'); |
|
1244 | - $publish = $this->request->getRequestParam('publish'); |
|
1245 | - $add_meta = $this->request->getRequestParam('addmeta'); |
|
1246 | - $delete_meta = $this->request->getRequestParam('deletemeta'); |
|
1247 | - if ($save || $publish) { |
|
1248 | - $status = get_post_status($post_id); |
|
1249 | - if ($publish) { |
|
1250 | - switch ($status) { |
|
1251 | - case 'pending': |
|
1252 | - $message = 8; |
|
1253 | - break; |
|
1254 | - case 'future': |
|
1255 | - $message = 9; |
|
1256 | - break; |
|
1257 | - default: |
|
1258 | - $message = 6; |
|
1259 | - } |
|
1260 | - } else { |
|
1261 | - $message = 'draft' === $status ? 10 : 1; |
|
1262 | - } |
|
1263 | - } elseif ($add_meta) { |
|
1264 | - $message = 2; |
|
1265 | - } elseif ($delete_meta) { |
|
1266 | - $message = 3; |
|
1267 | - } elseif ($this->request->getRequestParam('action') === 'post-quickpress-save-cont') { |
|
1268 | - $message = 7; |
|
1269 | - } else { |
|
1270 | - $message = 4; |
|
1271 | - } |
|
1272 | - // change the message if the post type is not viewable on the frontend |
|
1273 | - $this->_cpt_object = get_post_type_object($post->post_type); |
|
1274 | - |
|
1275 | - $query_args['message'] = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1276 | - $this->_process_notices($query_args, true); |
|
1277 | - return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1278 | - } |
|
1279 | - |
|
1280 | - |
|
1281 | - /** |
|
1282 | - * This method is called to inject nav tabs on core WP cpt pages |
|
1283 | - * |
|
1284 | - * @return void |
|
1285 | - * @throws EE_Error |
|
1286 | - */ |
|
1287 | - public function inject_nav_tabs() |
|
1288 | - { |
|
1289 | - echo wp_kses($this->_get_main_nav_tabs(), AllowedTags::getWithFormTags()); |
|
1290 | - } |
|
1291 | - |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * This just sets up the post update messages when an update form is loaded |
|
1295 | - * |
|
1296 | - * @param array $messages the original messages array |
|
1297 | - * @return array the new messages array |
|
1298 | - */ |
|
1299 | - public function post_update_messages(array $messages): array |
|
1300 | - { |
|
1301 | - global $post; |
|
1302 | - $id = $this->request->getRequestParam('post'); |
|
1303 | - $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1304 | - $revision = $this->request->getRequestParam('revision', 0, 'int'); |
|
1305 | - |
|
1306 | - $messages[ $post->post_type ] = [ |
|
1307 | - 0 => '', // Unused. Messages start at index 1. |
|
1308 | - 1 => sprintf( |
|
1309 | - esc_html__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1310 | - $this->_cpt_object->labels->singular_name, |
|
1311 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1312 | - '</a>' |
|
1313 | - ), |
|
1314 | - 2 => esc_html__('Custom field updated', 'event_espresso'), |
|
1315 | - 3 => esc_html__('Custom field deleted.', 'event_espresso'), |
|
1316 | - 4 => sprintf(esc_html__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1317 | - 5 => $revision |
|
1318 | - ? sprintf( |
|
1319 | - esc_html__('%s restored to revision from %s', 'event_espresso'), |
|
1320 | - $this->_cpt_object->labels->singular_name, |
|
1321 | - wp_post_revision_title($revision, false) |
|
1322 | - ) |
|
1323 | - : false, |
|
1324 | - 6 => sprintf( |
|
1325 | - esc_html__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1326 | - $this->_cpt_object->labels->singular_name, |
|
1327 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1328 | - '</a>' |
|
1329 | - ), |
|
1330 | - 7 => sprintf(esc_html__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1331 | - 8 => sprintf( |
|
1332 | - esc_html__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1333 | - $this->_cpt_object->labels->singular_name, |
|
1334 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1335 | - '</a>' |
|
1336 | - ), |
|
1337 | - 9 => sprintf( |
|
1338 | - esc_html__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1339 | - $this->_cpt_object->labels->singular_name, |
|
1340 | - '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
1341 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1342 | - '</a>' |
|
1343 | - ), |
|
1344 | - 10 => sprintf( |
|
1345 | - esc_html__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1346 | - $this->_cpt_object->labels->singular_name, |
|
1347 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1348 | - '</a>' |
|
1349 | - ), |
|
1350 | - ]; |
|
1351 | - return $messages; |
|
1352 | - } |
|
1353 | - |
|
1354 | - |
|
1355 | - /** |
|
1356 | - * default method for the 'create_new' route for cpt admin pages. |
|
1357 | - * For reference what to include in here, see wp-admin/post-new.php |
|
1358 | - * |
|
1359 | - * @return void |
|
1360 | - */ |
|
1361 | - protected function _create_new_cpt_item() |
|
1362 | - { |
|
1363 | - // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1364 | - global $post, $title, $post_type, $post_type_object; |
|
1365 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1366 | - $post_type_object = $this->_cpt_object; |
|
1367 | - $title = $post_type_object->labels->add_new_item; |
|
1368 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
1369 | - add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
1370 | - // modify the default editor title field with default title. |
|
1371 | - add_filter('enter_title_here', [$this, 'add_custom_editor_default_title']); |
|
1372 | - $this->loadEditorTemplate(); |
|
1373 | - } |
|
1374 | - |
|
1375 | - |
|
1376 | - /** |
|
1377 | - * Enqueues auto-save and loads the editor template |
|
1378 | - * |
|
1379 | - * @param bool $creating |
|
1380 | - */ |
|
1381 | - private function loadEditorTemplate(bool $creating = true) |
|
1382 | - { |
|
1383 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1384 | - // these vars are used by the template |
|
1385 | - $editing = true; |
|
1386 | - $post_ID = $post->ID; |
|
1387 | - if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
1388 | - // only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
1389 | - // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
1390 | - $action = $this->request->getRequestParam('action'); |
|
1391 | - if ($creating) { |
|
1392 | - wp_enqueue_script('autosave'); |
|
1393 | - } elseif ( |
|
1394 | - isset($this->_cpt_routes[ $action ]) |
|
1395 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $action ]) |
|
1396 | - ) { |
|
1397 | - $create_new_action = apply_filters( |
|
1398 | - 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1399 | - 'create_new', |
|
1400 | - $this |
|
1401 | - ); |
|
1402 | - $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
1403 | - [ |
|
1404 | - 'action' => $create_new_action, |
|
1405 | - 'page' => $this->page_slug, |
|
1406 | - ], |
|
1407 | - 'admin.php' |
|
1408 | - ); |
|
1409 | - } |
|
1410 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1411 | - } |
|
1412 | - } |
|
1413 | - |
|
1414 | - |
|
1415 | - public function add_new_admin_page_global() |
|
1416 | - { |
|
1417 | - $admin_page = $this->request->getRequestParam('post', 0, DataType::INT) !== 0 |
|
1418 | - ? 'post-php' |
|
1419 | - : 'post-new-php'; |
|
1420 | - ?> |
|
1128 | + } |
|
1129 | + |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1133 | + * |
|
1134 | + * @param string $location Original location url |
|
1135 | + * @return string new (or original) url to redirect to. |
|
1136 | + * @throws EE_Error |
|
1137 | + */ |
|
1138 | + public function revision_redirect(string $location): string |
|
1139 | + { |
|
1140 | + // get revision |
|
1141 | + $revision = $this->request->getRequestParam('revision'); |
|
1142 | + // can't do anything without revision so let's get out if not present |
|
1143 | + if (empty($revision)) { |
|
1144 | + return $location; |
|
1145 | + } |
|
1146 | + // get rev_post_data |
|
1147 | + $rev = get_post($revision); |
|
1148 | + $admin_url = $this->_admin_base_url; |
|
1149 | + $query_args = [ |
|
1150 | + 'action' => 'edit', |
|
1151 | + 'post' => $rev->post_parent, |
|
1152 | + 'revision' => $revision, |
|
1153 | + 'message' => 5, |
|
1154 | + ]; |
|
1155 | + $this->_process_notices($query_args, true); |
|
1156 | + return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $admin_url); |
|
1157 | + } |
|
1158 | + |
|
1159 | + |
|
1160 | + /** |
|
1161 | + * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1162 | + * |
|
1163 | + * @param string $link the original generated link |
|
1164 | + * @param int $id post id |
|
1165 | + * @return string the link |
|
1166 | + */ |
|
1167 | + public function modify_edit_post_link(string $link, int $id): string |
|
1168 | + { |
|
1169 | + $post = get_post($id); |
|
1170 | + $action = $this->request->getRequestParam('action'); |
|
1171 | + if ( |
|
1172 | + empty($action) |
|
1173 | + || ! isset($this->_cpt_routes[ $action ]) |
|
1174 | + || $post->post_type !== $this->_cpt_routes[ $action ] |
|
1175 | + ) { |
|
1176 | + return $link; |
|
1177 | + } |
|
1178 | + $query_args = [ |
|
1179 | + 'action' => $this->_cpt_edit_routes[ $post->post_type ] ?? 'edit', |
|
1180 | + 'post' => $id, |
|
1181 | + ]; |
|
1182 | + return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1183 | + } |
|
1184 | + |
|
1185 | + |
|
1186 | + /** |
|
1187 | + * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1188 | + * our routes. |
|
1189 | + * |
|
1190 | + * @param string $delete_link original delete link |
|
1191 | + * @param int $post_id id of cpt object |
|
1192 | + * @return string new delete link |
|
1193 | + * @throws EE_Error |
|
1194 | + * @throws ReflectionException |
|
1195 | + */ |
|
1196 | + public function modify_delete_post_link(string $delete_link, int $post_id): string |
|
1197 | + { |
|
1198 | + $post = get_post($post_id); |
|
1199 | + $action = $this->request->getRequestParam('action'); |
|
1200 | + if ( |
|
1201 | + ! $post instanceof WP_Post |
|
1202 | + || empty($action) |
|
1203 | + || ! isset($this->_cpt_routes[ $action ]) |
|
1204 | + || $post->post_type !== $this->_cpt_routes[ $action ] |
|
1205 | + ) { |
|
1206 | + return $delete_link; |
|
1207 | + } |
|
1208 | + $this->_set_model_object($post->ID, true); |
|
1209 | + |
|
1210 | + // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1211 | + $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1212 | + |
|
1213 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
1214 | + [ |
|
1215 | + 'page' => $this->request->getRequestParam('page'), |
|
1216 | + 'action' => $action, |
|
1217 | + $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() => $post->ID, |
|
1218 | + ], |
|
1219 | + admin_url() |
|
1220 | + ); |
|
1221 | + } |
|
1222 | + |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1226 | + * so that we can hijack the default redirect locations for wp custom post types |
|
1227 | + * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1228 | + * |
|
1229 | + * @param string $location This is the incoming currently set redirect location |
|
1230 | + * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1231 | + * @return string the new location to redirect to |
|
1232 | + * @throws EE_Error |
|
1233 | + */ |
|
1234 | + public function cpt_post_location_redirect(string $location, string $post_id): string |
|
1235 | + { |
|
1236 | + // we DO have a match so let's setup the url |
|
1237 | + // we have to get the post to determine our route |
|
1238 | + $post = get_post($post_id); |
|
1239 | + $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
1240 | + // shared query_args |
|
1241 | + $query_args = ['action' => $edit_route, 'post' => $post_id]; |
|
1242 | + |
|
1243 | + $save = $this->request->getRequestParam('save'); |
|
1244 | + $publish = $this->request->getRequestParam('publish'); |
|
1245 | + $add_meta = $this->request->getRequestParam('addmeta'); |
|
1246 | + $delete_meta = $this->request->getRequestParam('deletemeta'); |
|
1247 | + if ($save || $publish) { |
|
1248 | + $status = get_post_status($post_id); |
|
1249 | + if ($publish) { |
|
1250 | + switch ($status) { |
|
1251 | + case 'pending': |
|
1252 | + $message = 8; |
|
1253 | + break; |
|
1254 | + case 'future': |
|
1255 | + $message = 9; |
|
1256 | + break; |
|
1257 | + default: |
|
1258 | + $message = 6; |
|
1259 | + } |
|
1260 | + } else { |
|
1261 | + $message = 'draft' === $status ? 10 : 1; |
|
1262 | + } |
|
1263 | + } elseif ($add_meta) { |
|
1264 | + $message = 2; |
|
1265 | + } elseif ($delete_meta) { |
|
1266 | + $message = 3; |
|
1267 | + } elseif ($this->request->getRequestParam('action') === 'post-quickpress-save-cont') { |
|
1268 | + $message = 7; |
|
1269 | + } else { |
|
1270 | + $message = 4; |
|
1271 | + } |
|
1272 | + // change the message if the post type is not viewable on the frontend |
|
1273 | + $this->_cpt_object = get_post_type_object($post->post_type); |
|
1274 | + |
|
1275 | + $query_args['message'] = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1276 | + $this->_process_notices($query_args, true); |
|
1277 | + return EE_Admin_Page_CPT::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1278 | + } |
|
1279 | + |
|
1280 | + |
|
1281 | + /** |
|
1282 | + * This method is called to inject nav tabs on core WP cpt pages |
|
1283 | + * |
|
1284 | + * @return void |
|
1285 | + * @throws EE_Error |
|
1286 | + */ |
|
1287 | + public function inject_nav_tabs() |
|
1288 | + { |
|
1289 | + echo wp_kses($this->_get_main_nav_tabs(), AllowedTags::getWithFormTags()); |
|
1290 | + } |
|
1291 | + |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * This just sets up the post update messages when an update form is loaded |
|
1295 | + * |
|
1296 | + * @param array $messages the original messages array |
|
1297 | + * @return array the new messages array |
|
1298 | + */ |
|
1299 | + public function post_update_messages(array $messages): array |
|
1300 | + { |
|
1301 | + global $post; |
|
1302 | + $id = $this->request->getRequestParam('post'); |
|
1303 | + $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1304 | + $revision = $this->request->getRequestParam('revision', 0, 'int'); |
|
1305 | + |
|
1306 | + $messages[ $post->post_type ] = [ |
|
1307 | + 0 => '', // Unused. Messages start at index 1. |
|
1308 | + 1 => sprintf( |
|
1309 | + esc_html__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1310 | + $this->_cpt_object->labels->singular_name, |
|
1311 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1312 | + '</a>' |
|
1313 | + ), |
|
1314 | + 2 => esc_html__('Custom field updated', 'event_espresso'), |
|
1315 | + 3 => esc_html__('Custom field deleted.', 'event_espresso'), |
|
1316 | + 4 => sprintf(esc_html__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1317 | + 5 => $revision |
|
1318 | + ? sprintf( |
|
1319 | + esc_html__('%s restored to revision from %s', 'event_espresso'), |
|
1320 | + $this->_cpt_object->labels->singular_name, |
|
1321 | + wp_post_revision_title($revision, false) |
|
1322 | + ) |
|
1323 | + : false, |
|
1324 | + 6 => sprintf( |
|
1325 | + esc_html__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1326 | + $this->_cpt_object->labels->singular_name, |
|
1327 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1328 | + '</a>' |
|
1329 | + ), |
|
1330 | + 7 => sprintf(esc_html__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1331 | + 8 => sprintf( |
|
1332 | + esc_html__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1333 | + $this->_cpt_object->labels->singular_name, |
|
1334 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1335 | + '</a>' |
|
1336 | + ), |
|
1337 | + 9 => sprintf( |
|
1338 | + esc_html__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1339 | + $this->_cpt_object->labels->singular_name, |
|
1340 | + '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
1341 | + '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1342 | + '</a>' |
|
1343 | + ), |
|
1344 | + 10 => sprintf( |
|
1345 | + esc_html__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1346 | + $this->_cpt_object->labels->singular_name, |
|
1347 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1348 | + '</a>' |
|
1349 | + ), |
|
1350 | + ]; |
|
1351 | + return $messages; |
|
1352 | + } |
|
1353 | + |
|
1354 | + |
|
1355 | + /** |
|
1356 | + * default method for the 'create_new' route for cpt admin pages. |
|
1357 | + * For reference what to include in here, see wp-admin/post-new.php |
|
1358 | + * |
|
1359 | + * @return void |
|
1360 | + */ |
|
1361 | + protected function _create_new_cpt_item() |
|
1362 | + { |
|
1363 | + // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1364 | + global $post, $title, $post_type, $post_type_object; |
|
1365 | + $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1366 | + $post_type_object = $this->_cpt_object; |
|
1367 | + $title = $post_type_object->labels->add_new_item; |
|
1368 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
1369 | + add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
1370 | + // modify the default editor title field with default title. |
|
1371 | + add_filter('enter_title_here', [$this, 'add_custom_editor_default_title']); |
|
1372 | + $this->loadEditorTemplate(); |
|
1373 | + } |
|
1374 | + |
|
1375 | + |
|
1376 | + /** |
|
1377 | + * Enqueues auto-save and loads the editor template |
|
1378 | + * |
|
1379 | + * @param bool $creating |
|
1380 | + */ |
|
1381 | + private function loadEditorTemplate(bool $creating = true) |
|
1382 | + { |
|
1383 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1384 | + // these vars are used by the template |
|
1385 | + $editing = true; |
|
1386 | + $post_ID = $post->ID; |
|
1387 | + if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
1388 | + // only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
1389 | + // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
1390 | + $action = $this->request->getRequestParam('action'); |
|
1391 | + if ($creating) { |
|
1392 | + wp_enqueue_script('autosave'); |
|
1393 | + } elseif ( |
|
1394 | + isset($this->_cpt_routes[ $action ]) |
|
1395 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $action ]) |
|
1396 | + ) { |
|
1397 | + $create_new_action = apply_filters( |
|
1398 | + 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1399 | + 'create_new', |
|
1400 | + $this |
|
1401 | + ); |
|
1402 | + $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
1403 | + [ |
|
1404 | + 'action' => $create_new_action, |
|
1405 | + 'page' => $this->page_slug, |
|
1406 | + ], |
|
1407 | + 'admin.php' |
|
1408 | + ); |
|
1409 | + } |
|
1410 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1411 | + } |
|
1412 | + } |
|
1413 | + |
|
1414 | + |
|
1415 | + public function add_new_admin_page_global() |
|
1416 | + { |
|
1417 | + $admin_page = $this->request->getRequestParam('post', 0, DataType::INT) !== 0 |
|
1418 | + ? 'post-php' |
|
1419 | + : 'post-new-php'; |
|
1420 | + ?> |
|
1421 | 1421 | <script type="text/javascript"> |
1422 | 1422 | adminpage = '<?php echo esc_js($admin_page); ?>'; |
1423 | 1423 | </script> |
1424 | 1424 | <?php |
1425 | - } |
|
1426 | - |
|
1427 | - |
|
1428 | - /** |
|
1429 | - * default method for the 'edit' route for cpt admin pages |
|
1430 | - * For reference on what to put in here, refer to wp-admin/post.php |
|
1431 | - * |
|
1432 | - * @return void |
|
1433 | - */ |
|
1434 | - protected function _edit_cpt_item() |
|
1435 | - { |
|
1436 | - global $post, $post_type, $post_type_object, $title; |
|
1437 | - $post_id = $this->request->getRequestParam('post', 0, DataType::INT); |
|
1438 | - $post = $post_id ? get_post($post_id, OBJECT, 'edit') : null; |
|
1439 | - if (empty($post)) { |
|
1440 | - wp_die( |
|
1441 | - esc_html__( |
|
1442 | - "You attempted to edit an item that doesn't exist. Perhaps it was deleted?", |
|
1443 | - 'event_espresso' |
|
1444 | - ) |
|
1445 | - ); |
|
1446 | - } |
|
1447 | - |
|
1448 | - $post_lock = $this->request->getRequestParam('get-post-lock'); |
|
1449 | - if ($post_lock) { |
|
1450 | - wp_set_post_lock($post_id); |
|
1451 | - EEH_URL::safeRedirectAndExit(get_edit_post_link($post_id, 'url')); |
|
1452 | - } |
|
1453 | - |
|
1454 | - // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1455 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1456 | - $post_type_object = $this->_cpt_object; |
|
1457 | - $title = $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
1458 | - ?? $post_type_object->labels->edit_item; |
|
1459 | - |
|
1460 | - if (! wp_check_post_lock($post->ID)) { |
|
1461 | - wp_set_post_lock($post->ID); |
|
1462 | - } |
|
1463 | - add_action('admin_footer', '_admin_notice_post_locked'); |
|
1464 | - if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
1465 | - wp_enqueue_script('admin-comments'); |
|
1466 | - enqueue_comment_hotkeys_js(); |
|
1467 | - } |
|
1468 | - add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
1469 | - // modify the default editor title field with default title. |
|
1470 | - add_filter('enter_title_here', [$this, 'add_custom_editor_default_title']); |
|
1471 | - $this->loadEditorTemplate(false); |
|
1472 | - } |
|
1473 | - |
|
1474 | - |
|
1475 | - |
|
1476 | - /** |
|
1477 | - * some getters |
|
1478 | - */ |
|
1479 | - /** |
|
1480 | - * This returns the protected _cpt_model_obj property |
|
1481 | - * |
|
1482 | - * @return EE_CPT_Base |
|
1483 | - */ |
|
1484 | - public function get_cpt_model_obj() |
|
1485 | - { |
|
1486 | - return $this->_cpt_model_obj; |
|
1487 | - } |
|
1425 | + } |
|
1426 | + |
|
1427 | + |
|
1428 | + /** |
|
1429 | + * default method for the 'edit' route for cpt admin pages |
|
1430 | + * For reference on what to put in here, refer to wp-admin/post.php |
|
1431 | + * |
|
1432 | + * @return void |
|
1433 | + */ |
|
1434 | + protected function _edit_cpt_item() |
|
1435 | + { |
|
1436 | + global $post, $post_type, $post_type_object, $title; |
|
1437 | + $post_id = $this->request->getRequestParam('post', 0, DataType::INT); |
|
1438 | + $post = $post_id ? get_post($post_id, OBJECT, 'edit') : null; |
|
1439 | + if (empty($post)) { |
|
1440 | + wp_die( |
|
1441 | + esc_html__( |
|
1442 | + "You attempted to edit an item that doesn't exist. Perhaps it was deleted?", |
|
1443 | + 'event_espresso' |
|
1444 | + ) |
|
1445 | + ); |
|
1446 | + } |
|
1447 | + |
|
1448 | + $post_lock = $this->request->getRequestParam('get-post-lock'); |
|
1449 | + if ($post_lock) { |
|
1450 | + wp_set_post_lock($post_id); |
|
1451 | + EEH_URL::safeRedirectAndExit(get_edit_post_link($post_id, 'url')); |
|
1452 | + } |
|
1453 | + |
|
1454 | + // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1455 | + $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1456 | + $post_type_object = $this->_cpt_object; |
|
1457 | + $title = $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
1458 | + ?? $post_type_object->labels->edit_item; |
|
1459 | + |
|
1460 | + if (! wp_check_post_lock($post->ID)) { |
|
1461 | + wp_set_post_lock($post->ID); |
|
1462 | + } |
|
1463 | + add_action('admin_footer', '_admin_notice_post_locked'); |
|
1464 | + if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
1465 | + wp_enqueue_script('admin-comments'); |
|
1466 | + enqueue_comment_hotkeys_js(); |
|
1467 | + } |
|
1468 | + add_action('admin_print_styles', [$this, 'add_new_admin_page_global']); |
|
1469 | + // modify the default editor title field with default title. |
|
1470 | + add_filter('enter_title_here', [$this, 'add_custom_editor_default_title']); |
|
1471 | + $this->loadEditorTemplate(false); |
|
1472 | + } |
|
1473 | + |
|
1474 | + |
|
1475 | + |
|
1476 | + /** |
|
1477 | + * some getters |
|
1478 | + */ |
|
1479 | + /** |
|
1480 | + * This returns the protected _cpt_model_obj property |
|
1481 | + * |
|
1482 | + * @return EE_CPT_Base |
|
1483 | + */ |
|
1484 | + public function get_cpt_model_obj() |
|
1485 | + { |
|
1486 | + return $this->_cpt_model_obj; |
|
1487 | + } |
|
1488 | 1488 | } |