@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use EventEspresso\core\services\database\TableAnalysis; |
7 | 7 | |
8 | 8 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
9 | - exit('No direct script access allowed'); |
|
9 | + exit('No direct script access allowed'); |
|
10 | 10 | } |
11 | 11 | /** |
12 | 12 | * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE |
@@ -31,289 +31,289 @@ discard block |
||
31 | 31 | class EE_Brewing_Regular extends EE_BASE implements InterminableInterface |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
36 | - */ |
|
37 | - protected $_table_analysis; |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * EE_Brewing_Regular constructor. |
|
42 | - * @throws \DomainException |
|
43 | - * @throws \EE_Error |
|
44 | - * @throws InvalidDataTypeException |
|
45 | - * @throws InvalidInterfaceException |
|
46 | - * @throws \InvalidArgumentException |
|
47 | - */ |
|
48 | - public function __construct(TableAnalysis $table_analysis) |
|
49 | - { |
|
50 | - $this->_table_analysis = $table_analysis; |
|
51 | - if (defined('EE_CAFF_PATH')) { |
|
52 | - // activation |
|
53 | - add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
54 | - // load caff init |
|
55 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
56 | - // remove the "powered by" credit link from receipts and invoices |
|
57 | - add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
58 | - // add caffeinated modules |
|
59 | - add_filter( |
|
60 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
61 | - array($this, 'caffeinated_modules_to_register') |
|
62 | - ); |
|
63 | - // load caff scripts |
|
64 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
65 | - add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
66 | - //add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
67 | - EE_Register_Payment_Method::register( |
|
68 | - 'caffeinated_payment_methods', |
|
69 | - array( |
|
70 | - 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR) |
|
71 | - ) |
|
72 | - ); |
|
73 | - // caffeinated constructed |
|
74 | - do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
75 | - //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
76 | - add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
84 | - * |
|
85 | - * @param array $paths original helper paths array |
|
86 | - * @return array new array of paths |
|
87 | - */ |
|
88 | - public function caf_helper_paths($paths) |
|
89 | - { |
|
90 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
91 | - return $paths; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
98 | - * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
99 | - * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
100 | - * This action should only be called when EE 4.x.0.P is initially activated. |
|
101 | - * Right now the only CAF content are these global prices. If there's more in the future, then |
|
102 | - * we should probably create a caf file to contain it all instead just a function like this. |
|
103 | - * Right now, we ASSUME the only price types in the system are default ones |
|
104 | - * |
|
105 | - * @global wpdb $wpdb |
|
106 | - */ |
|
107 | - public function initialize_caf_db_content() |
|
108 | - { |
|
109 | - global $wpdb; |
|
110 | - //use same method of getting creator id as the version introducing the change |
|
111 | - $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
112 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
113 | - $price_table = $wpdb->prefix . "esp_price"; |
|
114 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
115 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
116 | - $tax_price_type_count = $wpdb->get_var($SQL); |
|
117 | - if ($tax_price_type_count <= 1) { |
|
118 | - $wpdb->insert( |
|
119 | - $price_type_table, |
|
120 | - array( |
|
121 | - 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
122 | - 'PBT_ID' => 4, |
|
123 | - 'PRT_is_percent' => true, |
|
124 | - 'PRT_order' => 60, |
|
125 | - 'PRT_deleted' => false, |
|
126 | - 'PRT_wp_user' => $default_creator_id, |
|
127 | - ), |
|
128 | - array( |
|
129 | - '%s',//PRT_name |
|
130 | - '%d',//PBT_id |
|
131 | - '%d',//PRT_is_percent |
|
132 | - '%d',//PRT_order |
|
133 | - '%d',//PRT_deleted |
|
134 | - '%d', //PRT_wp_user |
|
135 | - ) |
|
136 | - ); |
|
137 | - //federal tax |
|
138 | - $result = $wpdb->insert( |
|
139 | - $price_type_table, |
|
140 | - array( |
|
141 | - 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
142 | - 'PBT_ID' => 4, |
|
143 | - 'PRT_is_percent' => true, |
|
144 | - 'PRT_order' => 70, |
|
145 | - 'PRT_deleted' => false, |
|
146 | - 'PRT_wp_user' => $default_creator_id, |
|
147 | - ), |
|
148 | - array( |
|
149 | - '%s',//PRT_name |
|
150 | - '%d',//PBT_id |
|
151 | - '%d',//PRT_is_percent |
|
152 | - '%d',//PRT_order |
|
153 | - '%d',//PRT_deleted |
|
154 | - '%d' //PRT_wp_user |
|
155 | - ) |
|
156 | - ); |
|
157 | - if ($result) { |
|
158 | - $wpdb->insert( |
|
159 | - $price_table, |
|
160 | - array( |
|
161 | - 'PRT_ID' => $wpdb->insert_id, |
|
162 | - 'PRC_amount' => 15.00, |
|
163 | - 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
164 | - 'PRC_desc' => '', |
|
165 | - 'PRC_is_default' => true, |
|
166 | - 'PRC_overrides' => null, |
|
167 | - 'PRC_deleted' => false, |
|
168 | - 'PRC_order' => 50, |
|
169 | - 'PRC_parent' => null, |
|
170 | - 'PRC_wp_user' => $default_creator_id, |
|
171 | - ), |
|
172 | - array( |
|
173 | - '%d',//PRT_id |
|
174 | - '%f',//PRC_amount |
|
175 | - '%s',//PRC_name |
|
176 | - '%s',//PRC_desc |
|
177 | - '%d',//PRC_is_default |
|
178 | - '%d',//PRC_overrides |
|
179 | - '%d',//PRC_deleted |
|
180 | - '%d',//PRC_order |
|
181 | - '%d',//PRC_parent |
|
182 | - '%d' //PRC_wp_user |
|
183 | - ) |
|
184 | - ); |
|
185 | - } |
|
186 | - } |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * caffeinated_modules_to_register |
|
194 | - * |
|
195 | - * @access public |
|
196 | - * @param array $modules_to_register |
|
197 | - * @return array |
|
198 | - */ |
|
199 | - public function caffeinated_modules_to_register($modules_to_register = array()) |
|
200 | - { |
|
201 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
202 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
203 | - if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
204 | - $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
205 | - } |
|
206 | - } |
|
207 | - return $modules_to_register; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @throws EE_Error |
|
213 | - * @throws InvalidArgumentException |
|
214 | - * @throws ReflectionException |
|
215 | - * @throws InvalidDataTypeException |
|
216 | - * @throws InvalidInterfaceException |
|
217 | - */ |
|
218 | - public function caffeinated_init() |
|
219 | - { |
|
220 | - // Custom Post Type hooks |
|
221 | - add_filter( |
|
222 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
223 | - array($this, 'filter_taxonomies') |
|
224 | - ); |
|
225 | - add_filter( |
|
226 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
227 | - array($this, 'filter_cpts') |
|
228 | - ); |
|
229 | - add_filter( |
|
230 | - 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', |
|
231 | - array($this, 'nav_metabox_items') |
|
232 | - ); |
|
233 | - EE_Registry::instance()->load_file( |
|
234 | - EE_CAFF_PATH, |
|
235 | - 'EE_Caf_Messages', |
|
236 | - 'class', |
|
237 | - array(), |
|
238 | - false |
|
239 | - ); |
|
240 | - // caffeinated_init__complete hook |
|
241 | - do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - |
|
246 | - public function enqueue_caffeinated_scripts() |
|
247 | - { |
|
248 | - // sound of crickets... |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * callbacks below here |
|
255 | - * |
|
256 | - * @param array $taxonomy_array |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - public function filter_taxonomies(array $taxonomy_array) |
|
260 | - { |
|
261 | - $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
262 | - return $taxonomy_array; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * @param array $cpt_array |
|
269 | - * @return mixed |
|
270 | - */ |
|
271 | - public function filter_cpts(array $cpt_array) |
|
272 | - { |
|
273 | - $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
274 | - return $cpt_array; |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * @param array $menuitems |
|
281 | - * @return array |
|
282 | - */ |
|
283 | - public function nav_metabox_items(array $menuitems) |
|
284 | - { |
|
285 | - $menuitems[] = array( |
|
286 | - 'title' => __('Venue List', 'event_espresso'), |
|
287 | - 'url' => get_post_type_archive_link('espresso_venues'), |
|
288 | - 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
289 | - ); |
|
290 | - return $menuitems; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * Gets the injected table analyzer, or throws an exception |
|
296 | - * |
|
297 | - * @return TableAnalysis |
|
298 | - * @throws \EE_Error |
|
299 | - */ |
|
300 | - protected function _get_table_analysis() |
|
301 | - { |
|
302 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
303 | - return $this->_table_analysis; |
|
304 | - } else { |
|
305 | - throw new \EE_Error( |
|
306 | - sprintf( |
|
307 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
308 | - get_class($this) |
|
309 | - ) |
|
310 | - ); |
|
311 | - } |
|
312 | - } |
|
34 | + /** |
|
35 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
36 | + */ |
|
37 | + protected $_table_analysis; |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * EE_Brewing_Regular constructor. |
|
42 | + * @throws \DomainException |
|
43 | + * @throws \EE_Error |
|
44 | + * @throws InvalidDataTypeException |
|
45 | + * @throws InvalidInterfaceException |
|
46 | + * @throws \InvalidArgumentException |
|
47 | + */ |
|
48 | + public function __construct(TableAnalysis $table_analysis) |
|
49 | + { |
|
50 | + $this->_table_analysis = $table_analysis; |
|
51 | + if (defined('EE_CAFF_PATH')) { |
|
52 | + // activation |
|
53 | + add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
54 | + // load caff init |
|
55 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
56 | + // remove the "powered by" credit link from receipts and invoices |
|
57 | + add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
58 | + // add caffeinated modules |
|
59 | + add_filter( |
|
60 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
61 | + array($this, 'caffeinated_modules_to_register') |
|
62 | + ); |
|
63 | + // load caff scripts |
|
64 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
65 | + add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
66 | + //add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
67 | + EE_Register_Payment_Method::register( |
|
68 | + 'caffeinated_payment_methods', |
|
69 | + array( |
|
70 | + 'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR) |
|
71 | + ) |
|
72 | + ); |
|
73 | + // caffeinated constructed |
|
74 | + do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
75 | + //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
76 | + add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
84 | + * |
|
85 | + * @param array $paths original helper paths array |
|
86 | + * @return array new array of paths |
|
87 | + */ |
|
88 | + public function caf_helper_paths($paths) |
|
89 | + { |
|
90 | + $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
91 | + return $paths; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
98 | + * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
99 | + * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
100 | + * This action should only be called when EE 4.x.0.P is initially activated. |
|
101 | + * Right now the only CAF content are these global prices. If there's more in the future, then |
|
102 | + * we should probably create a caf file to contain it all instead just a function like this. |
|
103 | + * Right now, we ASSUME the only price types in the system are default ones |
|
104 | + * |
|
105 | + * @global wpdb $wpdb |
|
106 | + */ |
|
107 | + public function initialize_caf_db_content() |
|
108 | + { |
|
109 | + global $wpdb; |
|
110 | + //use same method of getting creator id as the version introducing the change |
|
111 | + $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
112 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
113 | + $price_table = $wpdb->prefix . "esp_price"; |
|
114 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
115 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
116 | + $tax_price_type_count = $wpdb->get_var($SQL); |
|
117 | + if ($tax_price_type_count <= 1) { |
|
118 | + $wpdb->insert( |
|
119 | + $price_type_table, |
|
120 | + array( |
|
121 | + 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
122 | + 'PBT_ID' => 4, |
|
123 | + 'PRT_is_percent' => true, |
|
124 | + 'PRT_order' => 60, |
|
125 | + 'PRT_deleted' => false, |
|
126 | + 'PRT_wp_user' => $default_creator_id, |
|
127 | + ), |
|
128 | + array( |
|
129 | + '%s',//PRT_name |
|
130 | + '%d',//PBT_id |
|
131 | + '%d',//PRT_is_percent |
|
132 | + '%d',//PRT_order |
|
133 | + '%d',//PRT_deleted |
|
134 | + '%d', //PRT_wp_user |
|
135 | + ) |
|
136 | + ); |
|
137 | + //federal tax |
|
138 | + $result = $wpdb->insert( |
|
139 | + $price_type_table, |
|
140 | + array( |
|
141 | + 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
142 | + 'PBT_ID' => 4, |
|
143 | + 'PRT_is_percent' => true, |
|
144 | + 'PRT_order' => 70, |
|
145 | + 'PRT_deleted' => false, |
|
146 | + 'PRT_wp_user' => $default_creator_id, |
|
147 | + ), |
|
148 | + array( |
|
149 | + '%s',//PRT_name |
|
150 | + '%d',//PBT_id |
|
151 | + '%d',//PRT_is_percent |
|
152 | + '%d',//PRT_order |
|
153 | + '%d',//PRT_deleted |
|
154 | + '%d' //PRT_wp_user |
|
155 | + ) |
|
156 | + ); |
|
157 | + if ($result) { |
|
158 | + $wpdb->insert( |
|
159 | + $price_table, |
|
160 | + array( |
|
161 | + 'PRT_ID' => $wpdb->insert_id, |
|
162 | + 'PRC_amount' => 15.00, |
|
163 | + 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
164 | + 'PRC_desc' => '', |
|
165 | + 'PRC_is_default' => true, |
|
166 | + 'PRC_overrides' => null, |
|
167 | + 'PRC_deleted' => false, |
|
168 | + 'PRC_order' => 50, |
|
169 | + 'PRC_parent' => null, |
|
170 | + 'PRC_wp_user' => $default_creator_id, |
|
171 | + ), |
|
172 | + array( |
|
173 | + '%d',//PRT_id |
|
174 | + '%f',//PRC_amount |
|
175 | + '%s',//PRC_name |
|
176 | + '%s',//PRC_desc |
|
177 | + '%d',//PRC_is_default |
|
178 | + '%d',//PRC_overrides |
|
179 | + '%d',//PRC_deleted |
|
180 | + '%d',//PRC_order |
|
181 | + '%d',//PRC_parent |
|
182 | + '%d' //PRC_wp_user |
|
183 | + ) |
|
184 | + ); |
|
185 | + } |
|
186 | + } |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * caffeinated_modules_to_register |
|
194 | + * |
|
195 | + * @access public |
|
196 | + * @param array $modules_to_register |
|
197 | + * @return array |
|
198 | + */ |
|
199 | + public function caffeinated_modules_to_register($modules_to_register = array()) |
|
200 | + { |
|
201 | + if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
202 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
203 | + if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
204 | + $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
205 | + } |
|
206 | + } |
|
207 | + return $modules_to_register; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @throws EE_Error |
|
213 | + * @throws InvalidArgumentException |
|
214 | + * @throws ReflectionException |
|
215 | + * @throws InvalidDataTypeException |
|
216 | + * @throws InvalidInterfaceException |
|
217 | + */ |
|
218 | + public function caffeinated_init() |
|
219 | + { |
|
220 | + // Custom Post Type hooks |
|
221 | + add_filter( |
|
222 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies', |
|
223 | + array($this, 'filter_taxonomies') |
|
224 | + ); |
|
225 | + add_filter( |
|
226 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes', |
|
227 | + array($this, 'filter_cpts') |
|
228 | + ); |
|
229 | + add_filter( |
|
230 | + 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', |
|
231 | + array($this, 'nav_metabox_items') |
|
232 | + ); |
|
233 | + EE_Registry::instance()->load_file( |
|
234 | + EE_CAFF_PATH, |
|
235 | + 'EE_Caf_Messages', |
|
236 | + 'class', |
|
237 | + array(), |
|
238 | + false |
|
239 | + ); |
|
240 | + // caffeinated_init__complete hook |
|
241 | + do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + |
|
246 | + public function enqueue_caffeinated_scripts() |
|
247 | + { |
|
248 | + // sound of crickets... |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * callbacks below here |
|
255 | + * |
|
256 | + * @param array $taxonomy_array |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + public function filter_taxonomies(array $taxonomy_array) |
|
260 | + { |
|
261 | + $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
262 | + return $taxonomy_array; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * @param array $cpt_array |
|
269 | + * @return mixed |
|
270 | + */ |
|
271 | + public function filter_cpts(array $cpt_array) |
|
272 | + { |
|
273 | + $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
274 | + return $cpt_array; |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * @param array $menuitems |
|
281 | + * @return array |
|
282 | + */ |
|
283 | + public function nav_metabox_items(array $menuitems) |
|
284 | + { |
|
285 | + $menuitems[] = array( |
|
286 | + 'title' => __('Venue List', 'event_espresso'), |
|
287 | + 'url' => get_post_type_archive_link('espresso_venues'), |
|
288 | + 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
289 | + ); |
|
290 | + return $menuitems; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * Gets the injected table analyzer, or throws an exception |
|
296 | + * |
|
297 | + * @return TableAnalysis |
|
298 | + * @throws \EE_Error |
|
299 | + */ |
|
300 | + protected function _get_table_analysis() |
|
301 | + { |
|
302 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
303 | + return $this->_table_analysis; |
|
304 | + } else { |
|
305 | + throw new \EE_Error( |
|
306 | + sprintf( |
|
307 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
308 | + get_class($this) |
|
309 | + ) |
|
310 | + ); |
|
311 | + } |
|
312 | + } |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
316 | 316 | |
317 | 317 | $brewing = new EE_Brewing_Regular( |
318 | - EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
318 | + EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
319 | 319 | ); |
320 | 320 | \ No newline at end of file |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use EventEspresso\core\services\request\middleware\RecommendedVersions; |
7 | 7 | |
8 | 8 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
9 | - exit('No direct script access allowed'); |
|
9 | + exit('No direct script access allowed'); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -31,475 +31,475 @@ discard block |
||
31 | 31 | { |
32 | 32 | |
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 | - /** |
|
45 | - * a boolean flag to set whether the current route is a cpt route or not. |
|
46 | - * |
|
47 | - * @var bool |
|
48 | - */ |
|
49 | - protected $_cpt_route = false; |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * This property allows cpt classes to define multiple routes as cpt routes. |
|
55 | - * //in this array we define what the custom post type for this route is. |
|
56 | - * array( |
|
57 | - * 'route_name' => 'custom_post_type_slug' |
|
58 | - * ) |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - protected $_cpt_routes = array(); |
|
63 | - |
|
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 | + /** |
|
45 | + * a boolean flag to set whether the current route is a cpt route or not. |
|
46 | + * |
|
47 | + * @var bool |
|
48 | + */ |
|
49 | + protected $_cpt_route = false; |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * This property allows cpt classes to define multiple routes as cpt routes. |
|
55 | + * //in this array we define what the custom post type for this route is. |
|
56 | + * array( |
|
57 | + * 'route_name' => 'custom_post_type_slug' |
|
58 | + * ) |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + protected $_cpt_routes = array(); |
|
63 | + |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
68 | - * in this format: |
|
69 | - * array( |
|
70 | - * 'post_type_slug' => 'edit_route' |
|
71 | - * ) |
|
72 | - * |
|
73 | - * @var array |
|
74 | - */ |
|
75 | - protected $_cpt_edit_routes = array(); |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
81 | - * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
82 | - * _cpt_model_names property should be in the following format: array( |
|
83 | - * 'route_defined_by_action_param' => 'Model_Name') |
|
84 | - * |
|
85 | - * @var array $_cpt_model_names |
|
86 | - */ |
|
87 | - protected $_cpt_model_names = array(); |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @var EE_CPT_Base |
|
92 | - */ |
|
93 | - protected $_cpt_model_obj = false; |
|
94 | - |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
99 | - * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
100 | - * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
101 | - * Registration of containers should be done before load_page_dependencies() is run. |
|
102 | - * |
|
103 | - * @var array() |
|
104 | - */ |
|
105 | - protected $_autosave_containers = array(); |
|
106 | - protected $_autosave_fields = array(); |
|
107 | - |
|
108 | - /** |
|
109 | - * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
110 | - * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
111 | - * |
|
112 | - * @var array |
|
113 | - */ |
|
114 | - protected $_pagenow_map; |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
120 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
121 | - * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
122 | - * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
123 | - * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
124 | - * |
|
125 | - * @access protected |
|
126 | - * @abstract |
|
127 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
128 | - * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
129 | - * @return void |
|
130 | - */ |
|
131 | - abstract protected function _insert_update_cpt_item($post_id, $post); |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
137 | - * |
|
138 | - * @abstract |
|
139 | - * @access public |
|
140 | - * @param string $post_id The ID of the cpt that was trashed |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - abstract public function trash_cpt_item($post_id); |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
149 | - * |
|
150 | - * @param string $post_id theID of the cpt that was untrashed |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - abstract public function restore_cpt_item($post_id); |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
159 | - * from the db |
|
160 | - * |
|
161 | - * @param string $post_id the ID of the cpt that was deleted |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - abstract public function delete_cpt_item($post_id); |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
170 | - * |
|
171 | - * @access protected |
|
172 | - * @return void |
|
173 | - */ |
|
174 | - protected function _before_page_setup() |
|
175 | - { |
|
176 | - $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
177 | - $this->_cpt_routes = array_merge(array( |
|
178 | - 'create_new' => $this->page_slug, |
|
179 | - 'edit' => $this->page_slug, |
|
180 | - 'trash' => $this->page_slug, |
|
181 | - ), $this->_cpt_routes); |
|
182 | - //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
183 | - $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
184 | - ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
185 | - : get_post_type_object($page); |
|
186 | - //tweak pagenow for page loading. |
|
187 | - if ( ! $this->_pagenow_map) { |
|
188 | - $this->_pagenow_map = array( |
|
189 | - 'create_new' => 'post-new.php', |
|
190 | - 'edit' => 'post.php', |
|
191 | - 'trash' => 'post.php', |
|
192 | - ); |
|
193 | - } |
|
194 | - add_action('current_screen', array($this, 'modify_pagenow')); |
|
195 | - //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
196 | - //get current page from autosave |
|
197 | - $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
198 | - ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
199 | - : null; |
|
200 | - $this->_current_page = isset($this->_req_data['current_page']) |
|
201 | - ? $this->_req_data['current_page'] |
|
202 | - : $current_page; |
|
203 | - //autosave... make sure its only for the correct page |
|
204 | - //if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
205 | - //setup autosave ajax hook |
|
206 | - //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
207 | - //} |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * Simply ensure that we simulate the correct post route for cpt screens |
|
214 | - * |
|
215 | - * @param WP_Screen $current_screen |
|
216 | - * @return void |
|
217 | - */ |
|
218 | - public function modify_pagenow($current_screen) |
|
219 | - { |
|
220 | - global $pagenow, $hook_suffix; |
|
221 | - //possibly reset pagenow. |
|
222 | - if ( ! empty($this->_req_data['page']) |
|
223 | - && $this->_req_data['page'] == $this->page_slug |
|
224 | - && ! empty($this->_req_data['action']) |
|
225 | - && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
226 | - ) { |
|
227 | - $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
228 | - $hook_suffix = $pagenow; |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * This method is used to register additional autosave containers to the _autosave_containers property. |
|
236 | - * |
|
237 | - * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
238 | - * automatically register the id for the post metabox as a container. |
|
239 | - * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
240 | - * you would send along the id of a metabox container. |
|
241 | - * @return void |
|
242 | - */ |
|
243 | - protected function _register_autosave_containers($ids) |
|
244 | - { |
|
245 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
252 | - * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
253 | - */ |
|
254 | - protected function _set_autosave_containers() |
|
255 | - { |
|
256 | - global $wp_meta_boxes; |
|
257 | - $containers = array(); |
|
258 | - if (empty($wp_meta_boxes)) { |
|
259 | - return; |
|
260 | - } |
|
261 | - $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
262 | - foreach ($current_metaboxes as $box_context) { |
|
263 | - foreach ($box_context as $box_details) { |
|
264 | - foreach ($box_details as $box) { |
|
265 | - if ( |
|
266 | - is_array($box['callback']) |
|
267 | - && ( |
|
268 | - $box['callback'][0] instanceof EE_Admin_Page |
|
269 | - || $box['callback'][0] instanceof EE_Admin_Hooks |
|
270 | - ) |
|
271 | - ) { |
|
272 | - $containers[] = $box['id']; |
|
273 | - } |
|
274 | - } |
|
275 | - } |
|
276 | - } |
|
277 | - $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
278 | - //add hidden inputs container |
|
279 | - $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - |
|
284 | - protected function _load_autosave_scripts_styles() |
|
285 | - { |
|
286 | - /*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 ); |
|
66 | + /** |
|
67 | + * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
68 | + * in this format: |
|
69 | + * array( |
|
70 | + * 'post_type_slug' => 'edit_route' |
|
71 | + * ) |
|
72 | + * |
|
73 | + * @var array |
|
74 | + */ |
|
75 | + protected $_cpt_edit_routes = array(); |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
81 | + * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
82 | + * _cpt_model_names property should be in the following format: array( |
|
83 | + * 'route_defined_by_action_param' => 'Model_Name') |
|
84 | + * |
|
85 | + * @var array $_cpt_model_names |
|
86 | + */ |
|
87 | + protected $_cpt_model_names = array(); |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @var EE_CPT_Base |
|
92 | + */ |
|
93 | + protected $_cpt_model_obj = false; |
|
94 | + |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
99 | + * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
100 | + * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
101 | + * Registration of containers should be done before load_page_dependencies() is run. |
|
102 | + * |
|
103 | + * @var array() |
|
104 | + */ |
|
105 | + protected $_autosave_containers = array(); |
|
106 | + protected $_autosave_fields = array(); |
|
107 | + |
|
108 | + /** |
|
109 | + * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
110 | + * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
111 | + * |
|
112 | + * @var array |
|
113 | + */ |
|
114 | + protected $_pagenow_map; |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
120 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
121 | + * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
122 | + * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
123 | + * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
124 | + * |
|
125 | + * @access protected |
|
126 | + * @abstract |
|
127 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
128 | + * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
129 | + * @return void |
|
130 | + */ |
|
131 | + abstract protected function _insert_update_cpt_item($post_id, $post); |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
137 | + * |
|
138 | + * @abstract |
|
139 | + * @access public |
|
140 | + * @param string $post_id The ID of the cpt that was trashed |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + abstract public function trash_cpt_item($post_id); |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
149 | + * |
|
150 | + * @param string $post_id theID of the cpt that was untrashed |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + abstract public function restore_cpt_item($post_id); |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
159 | + * from the db |
|
160 | + * |
|
161 | + * @param string $post_id the ID of the cpt that was deleted |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + abstract public function delete_cpt_item($post_id); |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
170 | + * |
|
171 | + * @access protected |
|
172 | + * @return void |
|
173 | + */ |
|
174 | + protected function _before_page_setup() |
|
175 | + { |
|
176 | + $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
177 | + $this->_cpt_routes = array_merge(array( |
|
178 | + 'create_new' => $this->page_slug, |
|
179 | + 'edit' => $this->page_slug, |
|
180 | + 'trash' => $this->page_slug, |
|
181 | + ), $this->_cpt_routes); |
|
182 | + //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
183 | + $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
184 | + ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
185 | + : get_post_type_object($page); |
|
186 | + //tweak pagenow for page loading. |
|
187 | + if ( ! $this->_pagenow_map) { |
|
188 | + $this->_pagenow_map = array( |
|
189 | + 'create_new' => 'post-new.php', |
|
190 | + 'edit' => 'post.php', |
|
191 | + 'trash' => 'post.php', |
|
192 | + ); |
|
193 | + } |
|
194 | + add_action('current_screen', array($this, 'modify_pagenow')); |
|
195 | + //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
196 | + //get current page from autosave |
|
197 | + $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
198 | + ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
199 | + : null; |
|
200 | + $this->_current_page = isset($this->_req_data['current_page']) |
|
201 | + ? $this->_req_data['current_page'] |
|
202 | + : $current_page; |
|
203 | + //autosave... make sure its only for the correct page |
|
204 | + //if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
205 | + //setup autosave ajax hook |
|
206 | + //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
207 | + //} |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * Simply ensure that we simulate the correct post route for cpt screens |
|
214 | + * |
|
215 | + * @param WP_Screen $current_screen |
|
216 | + * @return void |
|
217 | + */ |
|
218 | + public function modify_pagenow($current_screen) |
|
219 | + { |
|
220 | + global $pagenow, $hook_suffix; |
|
221 | + //possibly reset pagenow. |
|
222 | + if ( ! empty($this->_req_data['page']) |
|
223 | + && $this->_req_data['page'] == $this->page_slug |
|
224 | + && ! empty($this->_req_data['action']) |
|
225 | + && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
226 | + ) { |
|
227 | + $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
228 | + $hook_suffix = $pagenow; |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * This method is used to register additional autosave containers to the _autosave_containers property. |
|
236 | + * |
|
237 | + * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
238 | + * automatically register the id for the post metabox as a container. |
|
239 | + * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
240 | + * you would send along the id of a metabox container. |
|
241 | + * @return void |
|
242 | + */ |
|
243 | + protected function _register_autosave_containers($ids) |
|
244 | + { |
|
245 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
252 | + * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
253 | + */ |
|
254 | + protected function _set_autosave_containers() |
|
255 | + { |
|
256 | + global $wp_meta_boxes; |
|
257 | + $containers = array(); |
|
258 | + if (empty($wp_meta_boxes)) { |
|
259 | + return; |
|
260 | + } |
|
261 | + $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
262 | + foreach ($current_metaboxes as $box_context) { |
|
263 | + foreach ($box_context as $box_details) { |
|
264 | + foreach ($box_details as $box) { |
|
265 | + if ( |
|
266 | + is_array($box['callback']) |
|
267 | + && ( |
|
268 | + $box['callback'][0] instanceof EE_Admin_Page |
|
269 | + || $box['callback'][0] instanceof EE_Admin_Hooks |
|
270 | + ) |
|
271 | + ) { |
|
272 | + $containers[] = $box['id']; |
|
273 | + } |
|
274 | + } |
|
275 | + } |
|
276 | + } |
|
277 | + $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
278 | + //add hidden inputs container |
|
279 | + $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + |
|
284 | + protected function _load_autosave_scripts_styles() |
|
285 | + { |
|
286 | + /*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 ); |
|
287 | 287 | wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2 |
288 | 288 | |
289 | - //filter _autosave_containers |
|
290 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
291 | - $this->_autosave_containers, $this); |
|
292 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
293 | - $containers, $this); |
|
294 | - |
|
295 | - wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
|
296 | - $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
297 | - |
|
298 | - $unsaved_data_msg = array( |
|
299 | - 'eventmsg' => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.", |
|
300 | - 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
301 | - 'inputChanged' => 0, |
|
302 | - ); |
|
303 | - wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - |
|
308 | - public function load_page_dependencies() |
|
309 | - { |
|
310 | - try { |
|
311 | - $this->_load_page_dependencies(); |
|
312 | - } catch (EE_Error $e) { |
|
313 | - $e->get_error(); |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
321 | - * |
|
322 | - * @access protected |
|
323 | - * @return void |
|
324 | - */ |
|
325 | - protected function _load_page_dependencies() |
|
326 | - { |
|
327 | - //we only add stuff if this is a cpt_route! |
|
328 | - if ( ! $this->_cpt_route) { |
|
329 | - parent::_load_page_dependencies(); |
|
330 | - return; |
|
331 | - } |
|
332 | - // now let's do some automatic filters into the wp_system |
|
333 | - // and we'll check to make sure the CHILD class |
|
334 | - // automatically has the required methods in place. |
|
335 | - // the following filters are for setting all the redirects |
|
336 | - // on DEFAULT WP custom post type actions |
|
337 | - // let's add a hidden input to the post-edit form |
|
338 | - // so we know when we have to trigger our custom redirects! |
|
339 | - // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
340 | - add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
341 | - // inject our Admin page nav tabs... |
|
342 | - // let's make sure the nav tabs are set if they aren't already |
|
343 | - // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
344 | - add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
345 | - // modify the post_updated messages array |
|
346 | - add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
347 | - // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
348 | - // cpts use the same format for shortlinks as posts! |
|
349 | - add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
350 | - // This basically allows us to change the title of the "publish" metabox area |
|
351 | - // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
352 | - if ( ! empty($this->_labels['publishbox'])) { |
|
353 | - $box_label = is_array($this->_labels['publishbox']) |
|
354 | - && isset($this->_labels['publishbox'][$this->_req_action]) |
|
355 | - ? $this->_labels['publishbox'][$this->_req_action] |
|
356 | - : $this->_labels['publishbox']; |
|
357 | - add_meta_box( |
|
358 | - 'submitdiv', |
|
359 | - $box_label, |
|
360 | - 'post_submit_meta_box', |
|
361 | - $this->_cpt_routes[$this->_req_action], |
|
362 | - 'side', |
|
363 | - 'core' |
|
364 | - ); |
|
365 | - } |
|
366 | - //let's add page_templates metabox if this cpt added support for it. |
|
367 | - if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
368 | - add_meta_box( |
|
369 | - 'page_templates', |
|
370 | - __('Page Template', 'event_espresso'), |
|
371 | - array($this, 'page_template_meta_box'), |
|
372 | - $this->_cpt_routes[$this->_req_action], |
|
373 | - 'side', |
|
374 | - 'default' |
|
375 | - ); |
|
376 | - } |
|
377 | - //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
378 | - if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
379 | - add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
380 | - } |
|
381 | - //add preview button |
|
382 | - add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
383 | - //insert our own post_stati dropdown |
|
384 | - add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
385 | - //This allows adding additional information to the publish post submitbox on the wp post edit form |
|
386 | - if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
387 | - add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
388 | - } |
|
389 | - // This allows for adding additional stuff after the title field on the wp post edit form. |
|
390 | - // This is also before the wp_editor for post description field. |
|
391 | - if (method_exists($this, 'edit_form_after_title')) { |
|
392 | - add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
393 | - } |
|
394 | - /** |
|
395 | - * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
396 | - */ |
|
397 | - add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
398 | - parent::_load_page_dependencies(); |
|
399 | - // notice we are ALSO going to load the pagenow hook set for this route |
|
400 | - // (see _before_page_setup for the reset of the pagenow global ). |
|
401 | - // This is for any plugins that are doing things properly |
|
402 | - // and hooking into the load page hook for core wp cpt routes. |
|
403 | - global $pagenow; |
|
404 | - do_action('load-' . $pagenow); |
|
405 | - $this->modify_current_screen(); |
|
406 | - add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
407 | - //we route REALLY early. |
|
408 | - try { |
|
409 | - $this->_route_admin_request(); |
|
410 | - } catch (EE_Error $e) { |
|
411 | - $e->get_error(); |
|
412 | - } |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
419 | - * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
420 | - * route instead. |
|
421 | - * |
|
422 | - * @param string $good_protocol_url The escaped url. |
|
423 | - * @param string $original_url The original url. |
|
424 | - * @param string $_context The context sent to the esc_url method. |
|
425 | - * @return string possibly a new url for our route. |
|
426 | - */ |
|
427 | - public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
428 | - { |
|
429 | - $routes_to_match = array( |
|
430 | - 0 => array( |
|
431 | - 'edit.php?post_type=espresso_attendees', |
|
432 | - 'admin.php?page=espresso_registrations&action=contact_list', |
|
433 | - ), |
|
434 | - 1 => array( |
|
435 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
436 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
437 | - ), |
|
438 | - ); |
|
439 | - foreach ($routes_to_match as $route_matches) { |
|
440 | - if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
441 | - return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
442 | - } |
|
443 | - } |
|
444 | - return $good_protocol_url; |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * Determine whether the current cpt supports page templates or not. |
|
450 | - * |
|
451 | - * @since %VER% |
|
452 | - * @param string $cpt_name The cpt slug we're checking on. |
|
453 | - * @return bool True supported, false not. |
|
454 | - * @throws InvalidArgumentException |
|
455 | - * @throws InvalidDataTypeException |
|
456 | - * @throws InvalidInterfaceException |
|
457 | - */ |
|
458 | - private function _supports_page_templates($cpt_name) |
|
459 | - { |
|
460 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
461 | - $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
462 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
463 | - ); |
|
464 | - $cpt_args = $custom_post_types->getDefinitions(); |
|
465 | - $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
466 | - $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
467 | - |
|
468 | - //if the installed version of WP is > 4.7 we do some additional checks. |
|
469 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
470 | - $post_templates = wp_get_theme()->get_post_templates(); |
|
471 | - //if there are $post_templates for this cpt, then we return false for this method because |
|
472 | - //that means we aren't going to load our page template manager and leave that up to the native |
|
473 | - //cpt template manager. |
|
474 | - $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
475 | - } |
|
476 | - |
|
477 | - return $cpt_has_support; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * Callback for the page_templates metabox selector. |
|
483 | - * |
|
484 | - * @since %VER% |
|
485 | - * @return void |
|
486 | - */ |
|
487 | - public function page_template_meta_box() |
|
488 | - { |
|
489 | - global $post; |
|
490 | - $template = ''; |
|
491 | - |
|
492 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
493 | - $page_template_count = count(get_page_templates()); |
|
494 | - } else { |
|
495 | - $page_template_count = count(get_page_templates($post)); |
|
496 | - }; |
|
497 | - |
|
498 | - if ($page_template_count) { |
|
499 | - $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
500 | - $template = ! empty($page_template) ? $page_template : ''; |
|
501 | - } |
|
502 | - ?> |
|
289 | + //filter _autosave_containers |
|
290 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
291 | + $this->_autosave_containers, $this); |
|
292 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
293 | + $containers, $this); |
|
294 | + |
|
295 | + wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
|
296 | + $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
297 | + |
|
298 | + $unsaved_data_msg = array( |
|
299 | + 'eventmsg' => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.", |
|
300 | + 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
301 | + 'inputChanged' => 0, |
|
302 | + ); |
|
303 | + wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + |
|
308 | + public function load_page_dependencies() |
|
309 | + { |
|
310 | + try { |
|
311 | + $this->_load_page_dependencies(); |
|
312 | + } catch (EE_Error $e) { |
|
313 | + $e->get_error(); |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
321 | + * |
|
322 | + * @access protected |
|
323 | + * @return void |
|
324 | + */ |
|
325 | + protected function _load_page_dependencies() |
|
326 | + { |
|
327 | + //we only add stuff if this is a cpt_route! |
|
328 | + if ( ! $this->_cpt_route) { |
|
329 | + parent::_load_page_dependencies(); |
|
330 | + return; |
|
331 | + } |
|
332 | + // now let's do some automatic filters into the wp_system |
|
333 | + // and we'll check to make sure the CHILD class |
|
334 | + // automatically has the required methods in place. |
|
335 | + // the following filters are for setting all the redirects |
|
336 | + // on DEFAULT WP custom post type actions |
|
337 | + // let's add a hidden input to the post-edit form |
|
338 | + // so we know when we have to trigger our custom redirects! |
|
339 | + // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
340 | + add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
341 | + // inject our Admin page nav tabs... |
|
342 | + // let's make sure the nav tabs are set if they aren't already |
|
343 | + // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
344 | + add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
345 | + // modify the post_updated messages array |
|
346 | + add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
347 | + // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
348 | + // cpts use the same format for shortlinks as posts! |
|
349 | + add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
350 | + // This basically allows us to change the title of the "publish" metabox area |
|
351 | + // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
352 | + if ( ! empty($this->_labels['publishbox'])) { |
|
353 | + $box_label = is_array($this->_labels['publishbox']) |
|
354 | + && isset($this->_labels['publishbox'][$this->_req_action]) |
|
355 | + ? $this->_labels['publishbox'][$this->_req_action] |
|
356 | + : $this->_labels['publishbox']; |
|
357 | + add_meta_box( |
|
358 | + 'submitdiv', |
|
359 | + $box_label, |
|
360 | + 'post_submit_meta_box', |
|
361 | + $this->_cpt_routes[$this->_req_action], |
|
362 | + 'side', |
|
363 | + 'core' |
|
364 | + ); |
|
365 | + } |
|
366 | + //let's add page_templates metabox if this cpt added support for it. |
|
367 | + if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
368 | + add_meta_box( |
|
369 | + 'page_templates', |
|
370 | + __('Page Template', 'event_espresso'), |
|
371 | + array($this, 'page_template_meta_box'), |
|
372 | + $this->_cpt_routes[$this->_req_action], |
|
373 | + 'side', |
|
374 | + 'default' |
|
375 | + ); |
|
376 | + } |
|
377 | + //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
378 | + if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
379 | + add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
380 | + } |
|
381 | + //add preview button |
|
382 | + add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
383 | + //insert our own post_stati dropdown |
|
384 | + add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
385 | + //This allows adding additional information to the publish post submitbox on the wp post edit form |
|
386 | + if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
387 | + add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
388 | + } |
|
389 | + // This allows for adding additional stuff after the title field on the wp post edit form. |
|
390 | + // This is also before the wp_editor for post description field. |
|
391 | + if (method_exists($this, 'edit_form_after_title')) { |
|
392 | + add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
393 | + } |
|
394 | + /** |
|
395 | + * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
396 | + */ |
|
397 | + add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
398 | + parent::_load_page_dependencies(); |
|
399 | + // notice we are ALSO going to load the pagenow hook set for this route |
|
400 | + // (see _before_page_setup for the reset of the pagenow global ). |
|
401 | + // This is for any plugins that are doing things properly |
|
402 | + // and hooking into the load page hook for core wp cpt routes. |
|
403 | + global $pagenow; |
|
404 | + do_action('load-' . $pagenow); |
|
405 | + $this->modify_current_screen(); |
|
406 | + add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
407 | + //we route REALLY early. |
|
408 | + try { |
|
409 | + $this->_route_admin_request(); |
|
410 | + } catch (EE_Error $e) { |
|
411 | + $e->get_error(); |
|
412 | + } |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
419 | + * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
420 | + * route instead. |
|
421 | + * |
|
422 | + * @param string $good_protocol_url The escaped url. |
|
423 | + * @param string $original_url The original url. |
|
424 | + * @param string $_context The context sent to the esc_url method. |
|
425 | + * @return string possibly a new url for our route. |
|
426 | + */ |
|
427 | + public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
428 | + { |
|
429 | + $routes_to_match = array( |
|
430 | + 0 => array( |
|
431 | + 'edit.php?post_type=espresso_attendees', |
|
432 | + 'admin.php?page=espresso_registrations&action=contact_list', |
|
433 | + ), |
|
434 | + 1 => array( |
|
435 | + 'edit.php?post_type=' . $this->_cpt_object->name, |
|
436 | + 'admin.php?page=' . $this->_cpt_object->name, |
|
437 | + ), |
|
438 | + ); |
|
439 | + foreach ($routes_to_match as $route_matches) { |
|
440 | + if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
441 | + return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
442 | + } |
|
443 | + } |
|
444 | + return $good_protocol_url; |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * Determine whether the current cpt supports page templates or not. |
|
450 | + * |
|
451 | + * @since %VER% |
|
452 | + * @param string $cpt_name The cpt slug we're checking on. |
|
453 | + * @return bool True supported, false not. |
|
454 | + * @throws InvalidArgumentException |
|
455 | + * @throws InvalidDataTypeException |
|
456 | + * @throws InvalidInterfaceException |
|
457 | + */ |
|
458 | + private function _supports_page_templates($cpt_name) |
|
459 | + { |
|
460 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
461 | + $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
462 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
463 | + ); |
|
464 | + $cpt_args = $custom_post_types->getDefinitions(); |
|
465 | + $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
466 | + $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
467 | + |
|
468 | + //if the installed version of WP is > 4.7 we do some additional checks. |
|
469 | + if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
470 | + $post_templates = wp_get_theme()->get_post_templates(); |
|
471 | + //if there are $post_templates for this cpt, then we return false for this method because |
|
472 | + //that means we aren't going to load our page template manager and leave that up to the native |
|
473 | + //cpt template manager. |
|
474 | + $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
475 | + } |
|
476 | + |
|
477 | + return $cpt_has_support; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * Callback for the page_templates metabox selector. |
|
483 | + * |
|
484 | + * @since %VER% |
|
485 | + * @return void |
|
486 | + */ |
|
487 | + public function page_template_meta_box() |
|
488 | + { |
|
489 | + global $post; |
|
490 | + $template = ''; |
|
491 | + |
|
492 | + if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
493 | + $page_template_count = count(get_page_templates()); |
|
494 | + } else { |
|
495 | + $page_template_count = count(get_page_templates($post)); |
|
496 | + }; |
|
497 | + |
|
498 | + if ($page_template_count) { |
|
499 | + $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
500 | + $template = ! empty($page_template) ? $page_template : ''; |
|
501 | + } |
|
502 | + ?> |
|
503 | 503 | <p><strong><?php _e('Template') ?></strong></p> |
504 | 504 | <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select |
505 | 505 | name="page_template" id="page_template"> |
@@ -507,457 +507,457 @@ discard block |
||
507 | 507 | <?php page_template_dropdown($template); ?> |
508 | 508 | </select> |
509 | 509 | <?php |
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
516 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
517 | - * |
|
518 | - * @param string $return the current html |
|
519 | - * @param int $id the post id for the page |
|
520 | - * @param string $new_title What the title is |
|
521 | - * @param string $new_slug what the slug is |
|
522 | - * @return string The new html string for the permalink area |
|
523 | - */ |
|
524 | - public function preview_button_html($return, $id, $new_title, $new_slug) |
|
525 | - { |
|
526 | - $post = get_post($id); |
|
527 | - if ('publish' !== get_post_status($post)) { |
|
528 | - //include shims for the `get_preview_post_link` function |
|
529 | - require_once( EE_CORE . 'wordpress-shims.php' ); |
|
530 | - $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
531 | - . get_preview_post_link($id) |
|
532 | - . '" class="button button-small">' |
|
533 | - . __('Preview', 'event_espresso') |
|
534 | - . '</a></span>' |
|
535 | - . "\n"; |
|
536 | - } |
|
537 | - return $return; |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * add our custom post stati dropdown on the wp post page for this cpt |
|
544 | - * |
|
545 | - * @return void |
|
546 | - */ |
|
547 | - public function custom_post_stati_dropdown() |
|
548 | - { |
|
549 | - |
|
550 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
551 | - $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
552 | - ? $statuses[$this->_cpt_model_obj->status()] |
|
553 | - : ''; |
|
554 | - $template_args = array( |
|
555 | - 'cur_status' => $this->_cpt_model_obj->status(), |
|
556 | - 'statuses' => $statuses, |
|
557 | - 'cur_status_label' => $cur_status_label, |
|
558 | - 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
559 | - ); |
|
560 | - //we'll add a trash post status (WP doesn't add one for some reason) |
|
561 | - if ($this->_cpt_model_obj->status() === 'trash') { |
|
562 | - $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
563 | - $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
564 | - $template_args['statuses'] = $statuses; |
|
565 | - } |
|
566 | - |
|
567 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
568 | - EEH_Template::display_template($template, $template_args); |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - |
|
573 | - public function setup_autosave_hooks() |
|
574 | - { |
|
575 | - $this->_set_autosave_containers(); |
|
576 | - $this->_load_autosave_scripts_styles(); |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
583 | - * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
584 | - * for the nonce in here, but then this method looks for two things: |
|
585 | - * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
586 | - * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
587 | - * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
588 | - * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
589 | - * template args. |
|
590 | - * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
591 | - * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
592 | - * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
593 | - * $this->_template_args['data']['items'] = array( |
|
594 | - * 'event-datetime-ids' => '1,2,3'; |
|
595 | - * ); |
|
596 | - * Keep in mind the following things: |
|
597 | - * - "where" index is for the input with the id as that string. |
|
598 | - * - "what" index is what will be used for the value of that input. |
|
599 | - * |
|
600 | - * @return void |
|
601 | - */ |
|
602 | - public function do_extra_autosave_stuff() |
|
603 | - { |
|
604 | - //next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
605 | - $nonce = isset($this->_req_data['autosavenonce']) |
|
606 | - ? $this->_req_data['autosavenonce'] |
|
607 | - : null; |
|
608 | - $this->_verify_nonce($nonce, 'autosave'); |
|
609 | - //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
610 | - if ( ! defined('DOING_AUTOSAVE')) { |
|
611 | - define('DOING_AUTOSAVE', true); |
|
612 | - } |
|
613 | - //if we made it here then the nonce checked out. Let's run our methods and actions |
|
614 | - $autosave = "_ee_autosave_{$this->_current_view}"; |
|
615 | - if (method_exists($this, $autosave)) { |
|
616 | - $this->$autosave(); |
|
617 | - } else { |
|
618 | - $this->_template_args['success'] = true; |
|
619 | - } |
|
620 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
621 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
622 | - //now let's return json |
|
623 | - $this->_return_json(); |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
630 | - * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
631 | - * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
632 | - * |
|
633 | - * @access protected |
|
634 | - * @throws EE_Error |
|
635 | - * @return void |
|
636 | - */ |
|
637 | - protected function _extend_page_config_for_cpt() |
|
638 | - { |
|
639 | - //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
640 | - if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
641 | - return; |
|
642 | - } |
|
643 | - //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
644 | - if ( ! empty($this->_cpt_object)) { |
|
645 | - $this->_page_routes = array_merge(array( |
|
646 | - 'create_new' => '_create_new_cpt_item', |
|
647 | - 'edit' => '_edit_cpt_item', |
|
648 | - ), $this->_page_routes); |
|
649 | - $this->_page_config = array_merge(array( |
|
650 | - 'create_new' => array( |
|
651 | - 'nav' => array( |
|
652 | - 'label' => $this->_cpt_object->labels->add_new_item, |
|
653 | - 'order' => 5, |
|
654 | - ), |
|
655 | - 'require_nonce' => false, |
|
656 | - ), |
|
657 | - 'edit' => array( |
|
658 | - 'nav' => array( |
|
659 | - 'label' => $this->_cpt_object->labels->edit_item, |
|
660 | - 'order' => 5, |
|
661 | - 'persistent' => false, |
|
662 | - 'url' => '', |
|
663 | - ), |
|
664 | - 'require_nonce' => false, |
|
665 | - ), |
|
666 | - ), |
|
667 | - $this->_page_config |
|
668 | - ); |
|
669 | - } |
|
670 | - //load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
671 | - if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
672 | - return; |
|
673 | - } |
|
674 | - $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
675 | - //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
676 | - if (empty($this->_cpt_object)) { |
|
677 | - $msg = sprintf(__('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).'), |
|
678 | - $this->page_slug, $this->_req_action, get_class($this)); |
|
679 | - throw new EE_Error($msg); |
|
680 | - } |
|
681 | - if ($this->_cpt_route) { |
|
682 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
683 | - $this->_set_model_object($id); |
|
684 | - } |
|
685 | - } |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
690 | - * |
|
691 | - * @access protected |
|
692 | - * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
693 | - * @param bool $ignore_route_check |
|
694 | - * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
695 | - * @throws EE_Error |
|
696 | - * @throws InvalidArgumentException |
|
697 | - * @throws InvalidDataTypeException |
|
698 | - * @throws InvalidInterfaceException |
|
699 | - * @throws ReflectionException |
|
700 | - */ |
|
701 | - protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
702 | - { |
|
703 | - $model = null; |
|
704 | - if ( |
|
705 | - empty($this->_cpt_model_names) |
|
706 | - || ( |
|
707 | - ! $ignore_route_check |
|
708 | - && ! isset($this->_cpt_routes[$this->_req_action]) |
|
709 | - ) || ( |
|
710 | - $this->_cpt_model_obj instanceof EE_CPT_Base |
|
711 | - && $this->_cpt_model_obj->ID() === $id |
|
712 | - ) |
|
713 | - ) { |
|
714 | - //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. |
|
715 | - return; |
|
716 | - } |
|
717 | - // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
718 | - if ($ignore_route_check) { |
|
719 | - $post_type = get_post_type($id); |
|
720 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
721 | - $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
722 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
723 | - ); |
|
724 | - $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
725 | - if (isset($model_names[$post_type])) { |
|
726 | - $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
727 | - } |
|
728 | - } else { |
|
729 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
730 | - } |
|
731 | - if ($model instanceof EEM_Base) { |
|
732 | - $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
733 | - } |
|
734 | - do_action( |
|
735 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
736 | - $this->_cpt_model_obj, |
|
737 | - $req_type |
|
738 | - ); |
|
739 | - } |
|
740 | - |
|
741 | - |
|
742 | - |
|
743 | - /** |
|
744 | - * admin_init_global |
|
745 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
746 | - * This method executes for ALL EE Admin pages. |
|
747 | - * |
|
748 | - * @access public |
|
749 | - * @return void |
|
750 | - */ |
|
751 | - public function admin_init_global() |
|
752 | - { |
|
753 | - $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
754 | - //its possible this is a new save so let's catch that instead |
|
755 | - $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
756 | - $post_type = $post ? $post->post_type : false; |
|
757 | - $current_route = isset($this->_req_data['current_route']) |
|
758 | - ? $this->_req_data['current_route'] |
|
759 | - : 'shouldneverwork'; |
|
760 | - $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) |
|
761 | - ? $this->_cpt_routes[$current_route] |
|
762 | - : ''; |
|
763 | - add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
764 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
765 | - if ($post_type === $route_to_check) { |
|
766 | - add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
767 | - } |
|
768 | - //now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
769 | - $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
770 | - if ( ! empty($revision)) { |
|
771 | - $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
772 | - //doing a restore? |
|
773 | - if ( ! empty($action) && $action === 'restore') { |
|
774 | - //get post for revision |
|
775 | - $rev_post = get_post($revision); |
|
776 | - $rev_parent = get_post($rev_post->post_parent); |
|
777 | - //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
778 | - if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
779 | - add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
780 | - //restores of revisions |
|
781 | - add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
782 | - } |
|
783 | - } |
|
784 | - } |
|
785 | - //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! |
|
786 | - if ($post_type && $post_type === $route_to_check) { |
|
787 | - //$post_id, $post |
|
788 | - add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
789 | - //$post_id |
|
790 | - add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
791 | - add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
792 | - add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
793 | - add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
794 | - } |
|
795 | - } |
|
796 | - |
|
797 | - |
|
798 | - |
|
799 | - /** |
|
800 | - * Callback for the WordPress trashed_post hook. |
|
801 | - * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
802 | - * |
|
803 | - * @param int $post_id |
|
804 | - * @throws \EE_Error |
|
805 | - */ |
|
806 | - public function before_trash_cpt_item($post_id) |
|
807 | - { |
|
808 | - $this->_set_model_object($post_id, true, 'trash'); |
|
809 | - //if our cpt object isn't existent then get out immediately. |
|
810 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
811 | - return; |
|
812 | - } |
|
813 | - $this->trash_cpt_item($post_id); |
|
814 | - } |
|
815 | - |
|
816 | - |
|
817 | - |
|
818 | - /** |
|
819 | - * Callback for the WordPress untrashed_post hook. |
|
820 | - * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
821 | - * |
|
822 | - * @param $post_id |
|
823 | - * @throws \EE_Error |
|
824 | - */ |
|
825 | - public function before_restore_cpt_item($post_id) |
|
826 | - { |
|
827 | - $this->_set_model_object($post_id, true, 'restore'); |
|
828 | - //if our cpt object isn't existent then get out immediately. |
|
829 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
830 | - return; |
|
831 | - } |
|
832 | - $this->restore_cpt_item($post_id); |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - |
|
837 | - /** |
|
838 | - * Callback for the WordPress after_delete_post hook. |
|
839 | - * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
840 | - * |
|
841 | - * @param $post_id |
|
842 | - * @throws \EE_Error |
|
843 | - */ |
|
844 | - public function before_delete_cpt_item($post_id) |
|
845 | - { |
|
846 | - $this->_set_model_object($post_id, true, 'delete'); |
|
847 | - //if our cpt object isn't existent then get out immediately. |
|
848 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
849 | - return; |
|
850 | - } |
|
851 | - $this->delete_cpt_item($post_id); |
|
852 | - } |
|
853 | - |
|
854 | - |
|
855 | - |
|
856 | - /** |
|
857 | - * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
858 | - * accordingly. |
|
859 | - * |
|
860 | - * @access public |
|
861 | - * @throws EE_Error |
|
862 | - * @return void |
|
863 | - */ |
|
864 | - public function verify_cpt_object() |
|
865 | - { |
|
866 | - $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
867 | - // verify event object |
|
868 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
869 | - throw new EE_Error(sprintf(__('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', |
|
870 | - 'event_espresso'), $label)); |
|
871 | - } |
|
872 | - //if auto-draft then throw an error |
|
873 | - if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
874 | - EE_Error::overwrite_errors(); |
|
875 | - EE_Error::add_error(sprintf(__('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.'), |
|
876 | - $label), __FILE__, __FUNCTION__, __LINE__); |
|
877 | - } |
|
878 | - } |
|
879 | - |
|
880 | - |
|
881 | - |
|
882 | - /** |
|
883 | - * admin_footer_scripts_global |
|
884 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
885 | - * will apply on ALL EE_Admin pages. |
|
886 | - * |
|
887 | - * @access public |
|
888 | - * @return void |
|
889 | - */ |
|
890 | - public function admin_footer_scripts_global() |
|
891 | - { |
|
892 | - $this->_add_admin_page_ajax_loading_img(); |
|
893 | - $this->_add_admin_page_overlay(); |
|
894 | - } |
|
895 | - |
|
896 | - |
|
897 | - |
|
898 | - /** |
|
899 | - * add in any global scripts for cpt routes |
|
900 | - * |
|
901 | - * @return void |
|
902 | - */ |
|
903 | - public function load_global_scripts_styles() |
|
904 | - { |
|
905 | - parent::load_global_scripts_styles(); |
|
906 | - if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
907 | - //setup custom post status object for localize script but only if we've got a cpt object |
|
908 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
909 | - if ( ! empty($statuses)) { |
|
910 | - //get ALL statuses! |
|
911 | - $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
912 | - //setup object |
|
913 | - $ee_cpt_statuses = array(); |
|
914 | - foreach ($statuses as $status => $label) { |
|
915 | - $ee_cpt_statuses[$status] = array( |
|
916 | - 'label' => $label, |
|
917 | - 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
918 | - ); |
|
919 | - } |
|
920 | - wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
921 | - } |
|
922 | - } |
|
923 | - } |
|
924 | - |
|
925 | - |
|
926 | - |
|
927 | - /** |
|
928 | - * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
929 | - * insert/updates |
|
930 | - * |
|
931 | - * @param int $post_id ID of post being updated |
|
932 | - * @param WP_Post $post Post object from WP |
|
933 | - * @param bool $update Whether this is an update or a new save. |
|
934 | - * @return void |
|
935 | - * @throws \EE_Error |
|
936 | - */ |
|
937 | - public function insert_update($post_id, $post, $update) |
|
938 | - { |
|
939 | - //make sure that if this is a revision OR trash action that we don't do any updates! |
|
940 | - if ( |
|
941 | - isset($this->_req_data['action']) |
|
942 | - && ( |
|
943 | - $this->_req_data['action'] === 'restore' |
|
944 | - || $this->_req_data['action'] === 'trash' |
|
945 | - ) |
|
946 | - ) { |
|
947 | - return; |
|
948 | - } |
|
949 | - $this->_set_model_object($post_id, true, 'insert_update'); |
|
950 | - //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
951 | - if ($update |
|
952 | - && ( |
|
953 | - ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
954 | - || $this->_cpt_model_obj->ID() !== $post_id |
|
955 | - ) |
|
956 | - ) { |
|
957 | - return; |
|
958 | - } |
|
959 | - //check for autosave and update our req_data property accordingly. |
|
960 | - /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
516 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
517 | + * |
|
518 | + * @param string $return the current html |
|
519 | + * @param int $id the post id for the page |
|
520 | + * @param string $new_title What the title is |
|
521 | + * @param string $new_slug what the slug is |
|
522 | + * @return string The new html string for the permalink area |
|
523 | + */ |
|
524 | + public function preview_button_html($return, $id, $new_title, $new_slug) |
|
525 | + { |
|
526 | + $post = get_post($id); |
|
527 | + if ('publish' !== get_post_status($post)) { |
|
528 | + //include shims for the `get_preview_post_link` function |
|
529 | + require_once( EE_CORE . 'wordpress-shims.php' ); |
|
530 | + $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
531 | + . get_preview_post_link($id) |
|
532 | + . '" class="button button-small">' |
|
533 | + . __('Preview', 'event_espresso') |
|
534 | + . '</a></span>' |
|
535 | + . "\n"; |
|
536 | + } |
|
537 | + return $return; |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * add our custom post stati dropdown on the wp post page for this cpt |
|
544 | + * |
|
545 | + * @return void |
|
546 | + */ |
|
547 | + public function custom_post_stati_dropdown() |
|
548 | + { |
|
549 | + |
|
550 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
551 | + $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
552 | + ? $statuses[$this->_cpt_model_obj->status()] |
|
553 | + : ''; |
|
554 | + $template_args = array( |
|
555 | + 'cur_status' => $this->_cpt_model_obj->status(), |
|
556 | + 'statuses' => $statuses, |
|
557 | + 'cur_status_label' => $cur_status_label, |
|
558 | + 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
559 | + ); |
|
560 | + //we'll add a trash post status (WP doesn't add one for some reason) |
|
561 | + if ($this->_cpt_model_obj->status() === 'trash') { |
|
562 | + $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
563 | + $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
564 | + $template_args['statuses'] = $statuses; |
|
565 | + } |
|
566 | + |
|
567 | + $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
568 | + EEH_Template::display_template($template, $template_args); |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + |
|
573 | + public function setup_autosave_hooks() |
|
574 | + { |
|
575 | + $this->_set_autosave_containers(); |
|
576 | + $this->_load_autosave_scripts_styles(); |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
583 | + * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
584 | + * for the nonce in here, but then this method looks for two things: |
|
585 | + * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
586 | + * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
587 | + * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
588 | + * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
589 | + * template args. |
|
590 | + * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
591 | + * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
592 | + * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
593 | + * $this->_template_args['data']['items'] = array( |
|
594 | + * 'event-datetime-ids' => '1,2,3'; |
|
595 | + * ); |
|
596 | + * Keep in mind the following things: |
|
597 | + * - "where" index is for the input with the id as that string. |
|
598 | + * - "what" index is what will be used for the value of that input. |
|
599 | + * |
|
600 | + * @return void |
|
601 | + */ |
|
602 | + public function do_extra_autosave_stuff() |
|
603 | + { |
|
604 | + //next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
605 | + $nonce = isset($this->_req_data['autosavenonce']) |
|
606 | + ? $this->_req_data['autosavenonce'] |
|
607 | + : null; |
|
608 | + $this->_verify_nonce($nonce, 'autosave'); |
|
609 | + //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
610 | + if ( ! defined('DOING_AUTOSAVE')) { |
|
611 | + define('DOING_AUTOSAVE', true); |
|
612 | + } |
|
613 | + //if we made it here then the nonce checked out. Let's run our methods and actions |
|
614 | + $autosave = "_ee_autosave_{$this->_current_view}"; |
|
615 | + if (method_exists($this, $autosave)) { |
|
616 | + $this->$autosave(); |
|
617 | + } else { |
|
618 | + $this->_template_args['success'] = true; |
|
619 | + } |
|
620 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
621 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
622 | + //now let's return json |
|
623 | + $this->_return_json(); |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
630 | + * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
631 | + * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
632 | + * |
|
633 | + * @access protected |
|
634 | + * @throws EE_Error |
|
635 | + * @return void |
|
636 | + */ |
|
637 | + protected function _extend_page_config_for_cpt() |
|
638 | + { |
|
639 | + //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
640 | + if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
641 | + return; |
|
642 | + } |
|
643 | + //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
644 | + if ( ! empty($this->_cpt_object)) { |
|
645 | + $this->_page_routes = array_merge(array( |
|
646 | + 'create_new' => '_create_new_cpt_item', |
|
647 | + 'edit' => '_edit_cpt_item', |
|
648 | + ), $this->_page_routes); |
|
649 | + $this->_page_config = array_merge(array( |
|
650 | + 'create_new' => array( |
|
651 | + 'nav' => array( |
|
652 | + 'label' => $this->_cpt_object->labels->add_new_item, |
|
653 | + 'order' => 5, |
|
654 | + ), |
|
655 | + 'require_nonce' => false, |
|
656 | + ), |
|
657 | + 'edit' => array( |
|
658 | + 'nav' => array( |
|
659 | + 'label' => $this->_cpt_object->labels->edit_item, |
|
660 | + 'order' => 5, |
|
661 | + 'persistent' => false, |
|
662 | + 'url' => '', |
|
663 | + ), |
|
664 | + 'require_nonce' => false, |
|
665 | + ), |
|
666 | + ), |
|
667 | + $this->_page_config |
|
668 | + ); |
|
669 | + } |
|
670 | + //load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
671 | + if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
672 | + return; |
|
673 | + } |
|
674 | + $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
675 | + //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
676 | + if (empty($this->_cpt_object)) { |
|
677 | + $msg = sprintf(__('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).'), |
|
678 | + $this->page_slug, $this->_req_action, get_class($this)); |
|
679 | + throw new EE_Error($msg); |
|
680 | + } |
|
681 | + if ($this->_cpt_route) { |
|
682 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
683 | + $this->_set_model_object($id); |
|
684 | + } |
|
685 | + } |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
690 | + * |
|
691 | + * @access protected |
|
692 | + * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
693 | + * @param bool $ignore_route_check |
|
694 | + * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
695 | + * @throws EE_Error |
|
696 | + * @throws InvalidArgumentException |
|
697 | + * @throws InvalidDataTypeException |
|
698 | + * @throws InvalidInterfaceException |
|
699 | + * @throws ReflectionException |
|
700 | + */ |
|
701 | + protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
702 | + { |
|
703 | + $model = null; |
|
704 | + if ( |
|
705 | + empty($this->_cpt_model_names) |
|
706 | + || ( |
|
707 | + ! $ignore_route_check |
|
708 | + && ! isset($this->_cpt_routes[$this->_req_action]) |
|
709 | + ) || ( |
|
710 | + $this->_cpt_model_obj instanceof EE_CPT_Base |
|
711 | + && $this->_cpt_model_obj->ID() === $id |
|
712 | + ) |
|
713 | + ) { |
|
714 | + //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. |
|
715 | + return; |
|
716 | + } |
|
717 | + // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
718 | + if ($ignore_route_check) { |
|
719 | + $post_type = get_post_type($id); |
|
720 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
721 | + $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
722 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
723 | + ); |
|
724 | + $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
725 | + if (isset($model_names[$post_type])) { |
|
726 | + $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
727 | + } |
|
728 | + } else { |
|
729 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
730 | + } |
|
731 | + if ($model instanceof EEM_Base) { |
|
732 | + $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
733 | + } |
|
734 | + do_action( |
|
735 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
736 | + $this->_cpt_model_obj, |
|
737 | + $req_type |
|
738 | + ); |
|
739 | + } |
|
740 | + |
|
741 | + |
|
742 | + |
|
743 | + /** |
|
744 | + * admin_init_global |
|
745 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
746 | + * This method executes for ALL EE Admin pages. |
|
747 | + * |
|
748 | + * @access public |
|
749 | + * @return void |
|
750 | + */ |
|
751 | + public function admin_init_global() |
|
752 | + { |
|
753 | + $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
754 | + //its possible this is a new save so let's catch that instead |
|
755 | + $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
756 | + $post_type = $post ? $post->post_type : false; |
|
757 | + $current_route = isset($this->_req_data['current_route']) |
|
758 | + ? $this->_req_data['current_route'] |
|
759 | + : 'shouldneverwork'; |
|
760 | + $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) |
|
761 | + ? $this->_cpt_routes[$current_route] |
|
762 | + : ''; |
|
763 | + add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
764 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
765 | + if ($post_type === $route_to_check) { |
|
766 | + add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
767 | + } |
|
768 | + //now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
769 | + $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
770 | + if ( ! empty($revision)) { |
|
771 | + $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
772 | + //doing a restore? |
|
773 | + if ( ! empty($action) && $action === 'restore') { |
|
774 | + //get post for revision |
|
775 | + $rev_post = get_post($revision); |
|
776 | + $rev_parent = get_post($rev_post->post_parent); |
|
777 | + //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
778 | + if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
779 | + add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
780 | + //restores of revisions |
|
781 | + add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
782 | + } |
|
783 | + } |
|
784 | + } |
|
785 | + //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! |
|
786 | + if ($post_type && $post_type === $route_to_check) { |
|
787 | + //$post_id, $post |
|
788 | + add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
789 | + //$post_id |
|
790 | + add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
791 | + add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
792 | + add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
793 | + add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
794 | + } |
|
795 | + } |
|
796 | + |
|
797 | + |
|
798 | + |
|
799 | + /** |
|
800 | + * Callback for the WordPress trashed_post hook. |
|
801 | + * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
802 | + * |
|
803 | + * @param int $post_id |
|
804 | + * @throws \EE_Error |
|
805 | + */ |
|
806 | + public function before_trash_cpt_item($post_id) |
|
807 | + { |
|
808 | + $this->_set_model_object($post_id, true, 'trash'); |
|
809 | + //if our cpt object isn't existent then get out immediately. |
|
810 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
811 | + return; |
|
812 | + } |
|
813 | + $this->trash_cpt_item($post_id); |
|
814 | + } |
|
815 | + |
|
816 | + |
|
817 | + |
|
818 | + /** |
|
819 | + * Callback for the WordPress untrashed_post hook. |
|
820 | + * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
821 | + * |
|
822 | + * @param $post_id |
|
823 | + * @throws \EE_Error |
|
824 | + */ |
|
825 | + public function before_restore_cpt_item($post_id) |
|
826 | + { |
|
827 | + $this->_set_model_object($post_id, true, 'restore'); |
|
828 | + //if our cpt object isn't existent then get out immediately. |
|
829 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
830 | + return; |
|
831 | + } |
|
832 | + $this->restore_cpt_item($post_id); |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + |
|
837 | + /** |
|
838 | + * Callback for the WordPress after_delete_post hook. |
|
839 | + * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
840 | + * |
|
841 | + * @param $post_id |
|
842 | + * @throws \EE_Error |
|
843 | + */ |
|
844 | + public function before_delete_cpt_item($post_id) |
|
845 | + { |
|
846 | + $this->_set_model_object($post_id, true, 'delete'); |
|
847 | + //if our cpt object isn't existent then get out immediately. |
|
848 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
849 | + return; |
|
850 | + } |
|
851 | + $this->delete_cpt_item($post_id); |
|
852 | + } |
|
853 | + |
|
854 | + |
|
855 | + |
|
856 | + /** |
|
857 | + * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
858 | + * accordingly. |
|
859 | + * |
|
860 | + * @access public |
|
861 | + * @throws EE_Error |
|
862 | + * @return void |
|
863 | + */ |
|
864 | + public function verify_cpt_object() |
|
865 | + { |
|
866 | + $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
867 | + // verify event object |
|
868 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
869 | + throw new EE_Error(sprintf(__('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', |
|
870 | + 'event_espresso'), $label)); |
|
871 | + } |
|
872 | + //if auto-draft then throw an error |
|
873 | + if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
874 | + EE_Error::overwrite_errors(); |
|
875 | + EE_Error::add_error(sprintf(__('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.'), |
|
876 | + $label), __FILE__, __FUNCTION__, __LINE__); |
|
877 | + } |
|
878 | + } |
|
879 | + |
|
880 | + |
|
881 | + |
|
882 | + /** |
|
883 | + * admin_footer_scripts_global |
|
884 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
885 | + * will apply on ALL EE_Admin pages. |
|
886 | + * |
|
887 | + * @access public |
|
888 | + * @return void |
|
889 | + */ |
|
890 | + public function admin_footer_scripts_global() |
|
891 | + { |
|
892 | + $this->_add_admin_page_ajax_loading_img(); |
|
893 | + $this->_add_admin_page_overlay(); |
|
894 | + } |
|
895 | + |
|
896 | + |
|
897 | + |
|
898 | + /** |
|
899 | + * add in any global scripts for cpt routes |
|
900 | + * |
|
901 | + * @return void |
|
902 | + */ |
|
903 | + public function load_global_scripts_styles() |
|
904 | + { |
|
905 | + parent::load_global_scripts_styles(); |
|
906 | + if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
907 | + //setup custom post status object for localize script but only if we've got a cpt object |
|
908 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
909 | + if ( ! empty($statuses)) { |
|
910 | + //get ALL statuses! |
|
911 | + $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
912 | + //setup object |
|
913 | + $ee_cpt_statuses = array(); |
|
914 | + foreach ($statuses as $status => $label) { |
|
915 | + $ee_cpt_statuses[$status] = array( |
|
916 | + 'label' => $label, |
|
917 | + 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
918 | + ); |
|
919 | + } |
|
920 | + wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
921 | + } |
|
922 | + } |
|
923 | + } |
|
924 | + |
|
925 | + |
|
926 | + |
|
927 | + /** |
|
928 | + * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
929 | + * insert/updates |
|
930 | + * |
|
931 | + * @param int $post_id ID of post being updated |
|
932 | + * @param WP_Post $post Post object from WP |
|
933 | + * @param bool $update Whether this is an update or a new save. |
|
934 | + * @return void |
|
935 | + * @throws \EE_Error |
|
936 | + */ |
|
937 | + public function insert_update($post_id, $post, $update) |
|
938 | + { |
|
939 | + //make sure that if this is a revision OR trash action that we don't do any updates! |
|
940 | + if ( |
|
941 | + isset($this->_req_data['action']) |
|
942 | + && ( |
|
943 | + $this->_req_data['action'] === 'restore' |
|
944 | + || $this->_req_data['action'] === 'trash' |
|
945 | + ) |
|
946 | + ) { |
|
947 | + return; |
|
948 | + } |
|
949 | + $this->_set_model_object($post_id, true, 'insert_update'); |
|
950 | + //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
951 | + if ($update |
|
952 | + && ( |
|
953 | + ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
954 | + || $this->_cpt_model_obj->ID() !== $post_id |
|
955 | + ) |
|
956 | + ) { |
|
957 | + return; |
|
958 | + } |
|
959 | + //check for autosave and update our req_data property accordingly. |
|
960 | + /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
961 | 961 | foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) { |
962 | 962 | |
963 | 963 | foreach ( (array) $values as $key => $value ) { |
@@ -967,542 +967,542 @@ discard block |
||
967 | 967 | |
968 | 968 | }/**/ //TODO reactivate after autosave is implemented in 4.2 |
969 | 969 | |
970 | - //take care of updating any selected page_template IF this cpt supports it. |
|
971 | - if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
972 | - //wp version aware. |
|
973 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
974 | - $page_templates = wp_get_theme()->get_page_templates(); |
|
975 | - } else { |
|
976 | - $post->page_template = $this->_req_data['page_template']; |
|
977 | - $page_templates = wp_get_theme()->get_page_templates($post); |
|
978 | - } |
|
979 | - if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
980 | - EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
981 | - } else { |
|
982 | - update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
983 | - } |
|
984 | - } |
|
985 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
986 | - return; |
|
987 | - } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
988 | - $this->_insert_update_cpt_item($post_id, $post); |
|
989 | - } |
|
990 | - |
|
991 | - |
|
992 | - |
|
993 | - /** |
|
994 | - * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
995 | - * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
996 | - * so we don't have to check for our CPT. |
|
997 | - * |
|
998 | - * @param int $post_id ID of the post |
|
999 | - * @return void |
|
1000 | - */ |
|
1001 | - public function dont_permanently_delete_ee_cpts($post_id) |
|
1002 | - { |
|
1003 | - //only do this if we're actually processing one of our CPTs |
|
1004 | - //if our cpt object isn't existent then get out immediately. |
|
1005 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
1006 | - return; |
|
1007 | - } |
|
1008 | - delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
1009 | - delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
1010 | - //our cpts may have comments so let's take care of that too |
|
1011 | - delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
1012 | - } |
|
1013 | - |
|
1014 | - |
|
1015 | - |
|
1016 | - /** |
|
1017 | - * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1018 | - * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1019 | - * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1020 | - * |
|
1021 | - * @param int $post_id ID of cpt item |
|
1022 | - * @param int $revision_id ID of revision being restored |
|
1023 | - * @return void |
|
1024 | - */ |
|
1025 | - public function restore_revision($post_id, $revision_id) |
|
1026 | - { |
|
1027 | - $this->_restore_cpt_item($post_id, $revision_id); |
|
1028 | - //global action |
|
1029 | - do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1030 | - //class specific action so you can limit hooking into a specific page. |
|
1031 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1032 | - } |
|
1033 | - |
|
1034 | - |
|
1035 | - |
|
1036 | - /** |
|
1037 | - * @see restore_revision() for details |
|
1038 | - * @param int $post_id ID of cpt item |
|
1039 | - * @param int $revision_id ID of revision for item |
|
1040 | - * @return void |
|
1041 | - */ |
|
1042 | - abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1043 | - |
|
1044 | - |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1048 | - * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1049 | - * To fix we have to reset the current_screen using the page_slug |
|
1050 | - * (which is identical - or should be - to our registered_post_type id.) |
|
1051 | - * Also, since the core WP file loads the admin_header.php for WP |
|
1052 | - * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1053 | - * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1054 | - * |
|
1055 | - * @return void |
|
1056 | - */ |
|
1057 | - public function modify_current_screen() |
|
1058 | - { |
|
1059 | - //ONLY do this if the current page_route IS a cpt route |
|
1060 | - if ( ! $this->_cpt_route) { |
|
1061 | - return; |
|
1062 | - } |
|
1063 | - //routing things REALLY early b/c this is a cpt admin page |
|
1064 | - set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
1065 | - $this->_current_screen = get_current_screen(); |
|
1066 | - $this->_current_screen->base = 'event-espresso'; |
|
1067 | - $this->_add_help_tabs(); //we make sure we add any help tabs back in! |
|
1068 | - /*try { |
|
970 | + //take care of updating any selected page_template IF this cpt supports it. |
|
971 | + if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
972 | + //wp version aware. |
|
973 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
974 | + $page_templates = wp_get_theme()->get_page_templates(); |
|
975 | + } else { |
|
976 | + $post->page_template = $this->_req_data['page_template']; |
|
977 | + $page_templates = wp_get_theme()->get_page_templates($post); |
|
978 | + } |
|
979 | + if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
980 | + EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
981 | + } else { |
|
982 | + update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
983 | + } |
|
984 | + } |
|
985 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
986 | + return; |
|
987 | + } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
988 | + $this->_insert_update_cpt_item($post_id, $post); |
|
989 | + } |
|
990 | + |
|
991 | + |
|
992 | + |
|
993 | + /** |
|
994 | + * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
995 | + * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
996 | + * so we don't have to check for our CPT. |
|
997 | + * |
|
998 | + * @param int $post_id ID of the post |
|
999 | + * @return void |
|
1000 | + */ |
|
1001 | + public function dont_permanently_delete_ee_cpts($post_id) |
|
1002 | + { |
|
1003 | + //only do this if we're actually processing one of our CPTs |
|
1004 | + //if our cpt object isn't existent then get out immediately. |
|
1005 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
1006 | + return; |
|
1007 | + } |
|
1008 | + delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
1009 | + delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
1010 | + //our cpts may have comments so let's take care of that too |
|
1011 | + delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
1012 | + } |
|
1013 | + |
|
1014 | + |
|
1015 | + |
|
1016 | + /** |
|
1017 | + * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1018 | + * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1019 | + * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1020 | + * |
|
1021 | + * @param int $post_id ID of cpt item |
|
1022 | + * @param int $revision_id ID of revision being restored |
|
1023 | + * @return void |
|
1024 | + */ |
|
1025 | + public function restore_revision($post_id, $revision_id) |
|
1026 | + { |
|
1027 | + $this->_restore_cpt_item($post_id, $revision_id); |
|
1028 | + //global action |
|
1029 | + do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1030 | + //class specific action so you can limit hooking into a specific page. |
|
1031 | + do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1032 | + } |
|
1033 | + |
|
1034 | + |
|
1035 | + |
|
1036 | + /** |
|
1037 | + * @see restore_revision() for details |
|
1038 | + * @param int $post_id ID of cpt item |
|
1039 | + * @param int $revision_id ID of revision for item |
|
1040 | + * @return void |
|
1041 | + */ |
|
1042 | + abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1043 | + |
|
1044 | + |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1048 | + * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1049 | + * To fix we have to reset the current_screen using the page_slug |
|
1050 | + * (which is identical - or should be - to our registered_post_type id.) |
|
1051 | + * Also, since the core WP file loads the admin_header.php for WP |
|
1052 | + * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1053 | + * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1054 | + * |
|
1055 | + * @return void |
|
1056 | + */ |
|
1057 | + public function modify_current_screen() |
|
1058 | + { |
|
1059 | + //ONLY do this if the current page_route IS a cpt route |
|
1060 | + if ( ! $this->_cpt_route) { |
|
1061 | + return; |
|
1062 | + } |
|
1063 | + //routing things REALLY early b/c this is a cpt admin page |
|
1064 | + set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
1065 | + $this->_current_screen = get_current_screen(); |
|
1066 | + $this->_current_screen->base = 'event-espresso'; |
|
1067 | + $this->_add_help_tabs(); //we make sure we add any help tabs back in! |
|
1068 | + /*try { |
|
1069 | 1069 | $this->_route_admin_request(); |
1070 | 1070 | } catch ( EE_Error $e ) { |
1071 | 1071 | $e->get_error(); |
1072 | 1072 | }/**/ |
1073 | - } |
|
1074 | - |
|
1075 | - |
|
1076 | - |
|
1077 | - /** |
|
1078 | - * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1079 | - * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1080 | - * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1081 | - * default to be. |
|
1082 | - * |
|
1083 | - * @param string $title The new title (or existing if there is no editor_title defined) |
|
1084 | - * @return string |
|
1085 | - */ |
|
1086 | - public function add_custom_editor_default_title($title) |
|
1087 | - { |
|
1088 | - return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
1089 | - ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
1090 | - : $title; |
|
1091 | - } |
|
1092 | - |
|
1093 | - |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1097 | - * |
|
1098 | - * @param string $shortlink The already generated shortlink |
|
1099 | - * @param int $id Post ID for this item |
|
1100 | - * @param string $context The context for the link |
|
1101 | - * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1102 | - * @return string |
|
1103 | - */ |
|
1104 | - public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1105 | - { |
|
1106 | - if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
1107 | - $post = get_post($id); |
|
1108 | - if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1109 | - $shortlink = home_url('?p=' . $post->ID); |
|
1110 | - } |
|
1111 | - } |
|
1112 | - return $shortlink; |
|
1113 | - } |
|
1114 | - |
|
1115 | - |
|
1116 | - |
|
1117 | - /** |
|
1118 | - * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1119 | - * already run in modify_current_screen()) |
|
1120 | - * |
|
1121 | - * @return void |
|
1122 | - */ |
|
1123 | - public function route_admin_request() |
|
1124 | - { |
|
1125 | - if ($this->_cpt_route) { |
|
1126 | - return; |
|
1127 | - } |
|
1128 | - try { |
|
1129 | - $this->_route_admin_request(); |
|
1130 | - } catch (EE_Error $e) { |
|
1131 | - $e->get_error(); |
|
1132 | - } |
|
1133 | - } |
|
1134 | - |
|
1135 | - |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1139 | - * |
|
1140 | - * @return void |
|
1141 | - */ |
|
1142 | - public function cpt_post_form_hidden_input() |
|
1143 | - { |
|
1144 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1145 | - //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1146 | - echo '<div id="ee-cpt-hidden-inputs">'; |
|
1147 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1148 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1149 | - echo '</div>'; |
|
1150 | - } |
|
1151 | - |
|
1152 | - |
|
1153 | - |
|
1154 | - /** |
|
1155 | - * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1156 | - * |
|
1157 | - * @param string $location Original location url |
|
1158 | - * @param int $status Status for http header |
|
1159 | - * @return string new (or original) url to redirect to. |
|
1160 | - */ |
|
1161 | - public function revision_redirect($location, $status) |
|
1162 | - { |
|
1163 | - //get revision |
|
1164 | - $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1165 | - //can't do anything without revision so let's get out if not present |
|
1166 | - if (empty($rev_id)) { |
|
1167 | - return $location; |
|
1168 | - } |
|
1169 | - //get rev_post_data |
|
1170 | - $rev = get_post($rev_id); |
|
1171 | - $admin_url = $this->_admin_base_url; |
|
1172 | - $query_args = array( |
|
1173 | - 'action' => 'edit', |
|
1174 | - 'post' => $rev->post_parent, |
|
1175 | - 'revision' => $rev_id, |
|
1176 | - 'message' => 5, |
|
1177 | - ); |
|
1178 | - $this->_process_notices($query_args, true); |
|
1179 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1180 | - } |
|
1181 | - |
|
1182 | - |
|
1183 | - |
|
1184 | - /** |
|
1185 | - * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1186 | - * |
|
1187 | - * @param string $link the original generated link |
|
1188 | - * @param int $id post id |
|
1189 | - * @param string $context optional, defaults to display. How to write the '&' |
|
1190 | - * @return string the link |
|
1191 | - */ |
|
1192 | - public function modify_edit_post_link($link, $id, $context) |
|
1193 | - { |
|
1194 | - $post = get_post($id); |
|
1195 | - if ( ! isset($this->_req_data['action']) |
|
1196 | - || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1197 | - || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1198 | - ) { |
|
1199 | - return $link; |
|
1200 | - } |
|
1201 | - $query_args = array( |
|
1202 | - 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
1203 | - ? $this->_cpt_edit_routes[$post->post_type] |
|
1204 | - : 'edit', |
|
1205 | - 'post' => $id, |
|
1206 | - ); |
|
1207 | - return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1208 | - } |
|
1209 | - |
|
1210 | - |
|
1211 | - /** |
|
1212 | - * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1213 | - * our routes. |
|
1214 | - * |
|
1215 | - * @param string $delete_link original delete link |
|
1216 | - * @param int $post_id id of cpt object |
|
1217 | - * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1218 | - * @return string new delete link |
|
1219 | - * @throws EE_Error |
|
1220 | - */ |
|
1221 | - public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1222 | - { |
|
1223 | - $post = get_post($post_id); |
|
1224 | - |
|
1225 | - if (empty($this->_req_data['action']) |
|
1226 | - || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1227 | - || ! $post instanceof WP_Post |
|
1228 | - || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1229 | - ) { |
|
1230 | - return $delete_link; |
|
1231 | - } |
|
1232 | - $this->_set_model_object($post->ID, true); |
|
1233 | - |
|
1234 | - //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1235 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1236 | - |
|
1237 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
1238 | - array( |
|
1239 | - 'page' => $this->_req_data['page'], |
|
1240 | - 'action' => $action, |
|
1241 | - $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1242 | - => $post->ID |
|
1243 | - ), |
|
1244 | - admin_url() |
|
1245 | - ); |
|
1246 | - } |
|
1247 | - |
|
1248 | - |
|
1249 | - |
|
1250 | - /** |
|
1251 | - * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1252 | - * so that we can hijack the default redirect locations for wp custom post types |
|
1253 | - * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1254 | - * |
|
1255 | - * @param string $location This is the incoming currently set redirect location |
|
1256 | - * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1257 | - * @return string the new location to redirect to |
|
1258 | - */ |
|
1259 | - public function cpt_post_location_redirect($location, $post_id) |
|
1260 | - { |
|
1261 | - //we DO have a match so let's setup the url |
|
1262 | - //we have to get the post to determine our route |
|
1263 | - $post = get_post($post_id); |
|
1264 | - $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
1265 | - //shared query_args |
|
1266 | - $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1267 | - $admin_url = $this->_admin_base_url; |
|
1268 | - if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1269 | - $status = get_post_status($post_id); |
|
1270 | - if (isset($this->_req_data['publish'])) { |
|
1271 | - switch ($status) { |
|
1272 | - case 'pending': |
|
1273 | - $message = 8; |
|
1274 | - break; |
|
1275 | - case 'future': |
|
1276 | - $message = 9; |
|
1277 | - break; |
|
1278 | - default: |
|
1279 | - $message = 6; |
|
1280 | - } |
|
1281 | - } else { |
|
1282 | - $message = 'draft' === $status ? 10 : 1; |
|
1283 | - } |
|
1284 | - } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1285 | - $message = 2; |
|
1286 | - // $append = '#postcustom'; |
|
1287 | - } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1288 | - $message = 3; |
|
1289 | - // $append = '#postcustom'; |
|
1290 | - } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1291 | - $message = 7; |
|
1292 | - } else { |
|
1293 | - $message = 4; |
|
1294 | - } |
|
1295 | - //change the message if the post type is not viewable on the frontend |
|
1296 | - $this->_cpt_object = get_post_type_object($post->post_type); |
|
1297 | - $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1298 | - $query_args = array_merge(array('message' => $message), $query_args); |
|
1299 | - $this->_process_notices($query_args, true); |
|
1300 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1301 | - } |
|
1302 | - |
|
1303 | - |
|
1304 | - |
|
1305 | - /** |
|
1306 | - * This method is called to inject nav tabs on core WP cpt pages |
|
1307 | - * |
|
1308 | - * @access public |
|
1309 | - * @return void |
|
1310 | - */ |
|
1311 | - public function inject_nav_tabs() |
|
1312 | - { |
|
1313 | - //can we hijack and insert the nav_tabs? |
|
1314 | - $nav_tabs = $this->_get_main_nav_tabs(); |
|
1315 | - //first close off existing form tag |
|
1316 | - $html = '>'; |
|
1317 | - $html .= $nav_tabs; |
|
1318 | - //now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1319 | - $html .= '<span></span'; |
|
1320 | - echo $html; |
|
1321 | - } |
|
1322 | - |
|
1323 | - |
|
1324 | - |
|
1325 | - /** |
|
1326 | - * This just sets up the post update messages when an update form is loaded |
|
1327 | - * |
|
1328 | - * @access public |
|
1329 | - * @param array $messages the original messages array |
|
1330 | - * @return array the new messages array |
|
1331 | - */ |
|
1332 | - public function post_update_messages($messages) |
|
1333 | - { |
|
1334 | - global $post; |
|
1335 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1336 | - $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1337 | - // $post_type = $post ? $post->post_type : false; |
|
1338 | - /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1073 | + } |
|
1074 | + |
|
1075 | + |
|
1076 | + |
|
1077 | + /** |
|
1078 | + * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1079 | + * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1080 | + * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1081 | + * default to be. |
|
1082 | + * |
|
1083 | + * @param string $title The new title (or existing if there is no editor_title defined) |
|
1084 | + * @return string |
|
1085 | + */ |
|
1086 | + public function add_custom_editor_default_title($title) |
|
1087 | + { |
|
1088 | + return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
1089 | + ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
1090 | + : $title; |
|
1091 | + } |
|
1092 | + |
|
1093 | + |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1097 | + * |
|
1098 | + * @param string $shortlink The already generated shortlink |
|
1099 | + * @param int $id Post ID for this item |
|
1100 | + * @param string $context The context for the link |
|
1101 | + * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1102 | + * @return string |
|
1103 | + */ |
|
1104 | + public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1105 | + { |
|
1106 | + if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
1107 | + $post = get_post($id); |
|
1108 | + if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1109 | + $shortlink = home_url('?p=' . $post->ID); |
|
1110 | + } |
|
1111 | + } |
|
1112 | + return $shortlink; |
|
1113 | + } |
|
1114 | + |
|
1115 | + |
|
1116 | + |
|
1117 | + /** |
|
1118 | + * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1119 | + * already run in modify_current_screen()) |
|
1120 | + * |
|
1121 | + * @return void |
|
1122 | + */ |
|
1123 | + public function route_admin_request() |
|
1124 | + { |
|
1125 | + if ($this->_cpt_route) { |
|
1126 | + return; |
|
1127 | + } |
|
1128 | + try { |
|
1129 | + $this->_route_admin_request(); |
|
1130 | + } catch (EE_Error $e) { |
|
1131 | + $e->get_error(); |
|
1132 | + } |
|
1133 | + } |
|
1134 | + |
|
1135 | + |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1139 | + * |
|
1140 | + * @return void |
|
1141 | + */ |
|
1142 | + public function cpt_post_form_hidden_input() |
|
1143 | + { |
|
1144 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1145 | + //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1146 | + echo '<div id="ee-cpt-hidden-inputs">'; |
|
1147 | + echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1148 | + echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1149 | + echo '</div>'; |
|
1150 | + } |
|
1151 | + |
|
1152 | + |
|
1153 | + |
|
1154 | + /** |
|
1155 | + * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1156 | + * |
|
1157 | + * @param string $location Original location url |
|
1158 | + * @param int $status Status for http header |
|
1159 | + * @return string new (or original) url to redirect to. |
|
1160 | + */ |
|
1161 | + public function revision_redirect($location, $status) |
|
1162 | + { |
|
1163 | + //get revision |
|
1164 | + $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1165 | + //can't do anything without revision so let's get out if not present |
|
1166 | + if (empty($rev_id)) { |
|
1167 | + return $location; |
|
1168 | + } |
|
1169 | + //get rev_post_data |
|
1170 | + $rev = get_post($rev_id); |
|
1171 | + $admin_url = $this->_admin_base_url; |
|
1172 | + $query_args = array( |
|
1173 | + 'action' => 'edit', |
|
1174 | + 'post' => $rev->post_parent, |
|
1175 | + 'revision' => $rev_id, |
|
1176 | + 'message' => 5, |
|
1177 | + ); |
|
1178 | + $this->_process_notices($query_args, true); |
|
1179 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1180 | + } |
|
1181 | + |
|
1182 | + |
|
1183 | + |
|
1184 | + /** |
|
1185 | + * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1186 | + * |
|
1187 | + * @param string $link the original generated link |
|
1188 | + * @param int $id post id |
|
1189 | + * @param string $context optional, defaults to display. How to write the '&' |
|
1190 | + * @return string the link |
|
1191 | + */ |
|
1192 | + public function modify_edit_post_link($link, $id, $context) |
|
1193 | + { |
|
1194 | + $post = get_post($id); |
|
1195 | + if ( ! isset($this->_req_data['action']) |
|
1196 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1197 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1198 | + ) { |
|
1199 | + return $link; |
|
1200 | + } |
|
1201 | + $query_args = array( |
|
1202 | + 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
1203 | + ? $this->_cpt_edit_routes[$post->post_type] |
|
1204 | + : 'edit', |
|
1205 | + 'post' => $id, |
|
1206 | + ); |
|
1207 | + return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1208 | + } |
|
1209 | + |
|
1210 | + |
|
1211 | + /** |
|
1212 | + * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1213 | + * our routes. |
|
1214 | + * |
|
1215 | + * @param string $delete_link original delete link |
|
1216 | + * @param int $post_id id of cpt object |
|
1217 | + * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1218 | + * @return string new delete link |
|
1219 | + * @throws EE_Error |
|
1220 | + */ |
|
1221 | + public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1222 | + { |
|
1223 | + $post = get_post($post_id); |
|
1224 | + |
|
1225 | + if (empty($this->_req_data['action']) |
|
1226 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1227 | + || ! $post instanceof WP_Post |
|
1228 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1229 | + ) { |
|
1230 | + return $delete_link; |
|
1231 | + } |
|
1232 | + $this->_set_model_object($post->ID, true); |
|
1233 | + |
|
1234 | + //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1235 | + $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1236 | + |
|
1237 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
1238 | + array( |
|
1239 | + 'page' => $this->_req_data['page'], |
|
1240 | + 'action' => $action, |
|
1241 | + $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1242 | + => $post->ID |
|
1243 | + ), |
|
1244 | + admin_url() |
|
1245 | + ); |
|
1246 | + } |
|
1247 | + |
|
1248 | + |
|
1249 | + |
|
1250 | + /** |
|
1251 | + * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1252 | + * so that we can hijack the default redirect locations for wp custom post types |
|
1253 | + * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1254 | + * |
|
1255 | + * @param string $location This is the incoming currently set redirect location |
|
1256 | + * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1257 | + * @return string the new location to redirect to |
|
1258 | + */ |
|
1259 | + public function cpt_post_location_redirect($location, $post_id) |
|
1260 | + { |
|
1261 | + //we DO have a match so let's setup the url |
|
1262 | + //we have to get the post to determine our route |
|
1263 | + $post = get_post($post_id); |
|
1264 | + $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
1265 | + //shared query_args |
|
1266 | + $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1267 | + $admin_url = $this->_admin_base_url; |
|
1268 | + if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1269 | + $status = get_post_status($post_id); |
|
1270 | + if (isset($this->_req_data['publish'])) { |
|
1271 | + switch ($status) { |
|
1272 | + case 'pending': |
|
1273 | + $message = 8; |
|
1274 | + break; |
|
1275 | + case 'future': |
|
1276 | + $message = 9; |
|
1277 | + break; |
|
1278 | + default: |
|
1279 | + $message = 6; |
|
1280 | + } |
|
1281 | + } else { |
|
1282 | + $message = 'draft' === $status ? 10 : 1; |
|
1283 | + } |
|
1284 | + } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1285 | + $message = 2; |
|
1286 | + // $append = '#postcustom'; |
|
1287 | + } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1288 | + $message = 3; |
|
1289 | + // $append = '#postcustom'; |
|
1290 | + } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1291 | + $message = 7; |
|
1292 | + } else { |
|
1293 | + $message = 4; |
|
1294 | + } |
|
1295 | + //change the message if the post type is not viewable on the frontend |
|
1296 | + $this->_cpt_object = get_post_type_object($post->post_type); |
|
1297 | + $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1298 | + $query_args = array_merge(array('message' => $message), $query_args); |
|
1299 | + $this->_process_notices($query_args, true); |
|
1300 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1301 | + } |
|
1302 | + |
|
1303 | + |
|
1304 | + |
|
1305 | + /** |
|
1306 | + * This method is called to inject nav tabs on core WP cpt pages |
|
1307 | + * |
|
1308 | + * @access public |
|
1309 | + * @return void |
|
1310 | + */ |
|
1311 | + public function inject_nav_tabs() |
|
1312 | + { |
|
1313 | + //can we hijack and insert the nav_tabs? |
|
1314 | + $nav_tabs = $this->_get_main_nav_tabs(); |
|
1315 | + //first close off existing form tag |
|
1316 | + $html = '>'; |
|
1317 | + $html .= $nav_tabs; |
|
1318 | + //now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1319 | + $html .= '<span></span'; |
|
1320 | + echo $html; |
|
1321 | + } |
|
1322 | + |
|
1323 | + |
|
1324 | + |
|
1325 | + /** |
|
1326 | + * This just sets up the post update messages when an update form is loaded |
|
1327 | + * |
|
1328 | + * @access public |
|
1329 | + * @param array $messages the original messages array |
|
1330 | + * @return array the new messages array |
|
1331 | + */ |
|
1332 | + public function post_update_messages($messages) |
|
1333 | + { |
|
1334 | + global $post; |
|
1335 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1336 | + $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1337 | + // $post_type = $post ? $post->post_type : false; |
|
1338 | + /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1339 | 1339 | |
1340 | 1340 | $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/ |
1341 | - $messages[$post->post_type] = array( |
|
1342 | - 0 => '', //Unused. Messages start at index 1. |
|
1343 | - 1 => sprintf( |
|
1344 | - __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1345 | - $this->_cpt_object->labels->singular_name, |
|
1346 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1347 | - '</a>' |
|
1348 | - ), |
|
1349 | - 2 => __('Custom field updated'), |
|
1350 | - 3 => __('Custom field deleted.'), |
|
1351 | - 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1352 | - 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
|
1353 | - $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1354 | - : false, |
|
1355 | - 6 => sprintf( |
|
1356 | - __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1357 | - $this->_cpt_object->labels->singular_name, |
|
1358 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1359 | - '</a>' |
|
1360 | - ), |
|
1361 | - 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1362 | - 8 => sprintf( |
|
1363 | - __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1364 | - $this->_cpt_object->labels->singular_name, |
|
1365 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1366 | - '</a>' |
|
1367 | - ), |
|
1368 | - 9 => sprintf( |
|
1369 | - __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1370 | - $this->_cpt_object->labels->singular_name, |
|
1371 | - '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1372 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1373 | - '</a>' |
|
1374 | - ), |
|
1375 | - 10 => sprintf( |
|
1376 | - __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1377 | - $this->_cpt_object->labels->singular_name, |
|
1378 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1379 | - '</a>' |
|
1380 | - ), |
|
1381 | - ); |
|
1382 | - return $messages; |
|
1383 | - } |
|
1384 | - |
|
1385 | - |
|
1386 | - |
|
1387 | - /** |
|
1388 | - * default method for the 'create_new' route for cpt admin pages. |
|
1389 | - * For reference what to include in here, see wp-admin/post-new.php |
|
1390 | - * |
|
1391 | - * @access protected |
|
1392 | - * @return void |
|
1393 | - */ |
|
1394 | - protected function _create_new_cpt_item() |
|
1395 | - { |
|
1396 | - // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1397 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1398 | - $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1399 | - $post_type_object = $this->_cpt_object; |
|
1400 | - $title = $post_type_object->labels->add_new_item; |
|
1401 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1402 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1403 | - //modify the default editor title field with default title. |
|
1404 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1405 | - $this->loadEditorTemplate(true); |
|
1406 | - } |
|
1407 | - |
|
1408 | - |
|
1409 | - /** |
|
1410 | - * Enqueues auto-save and loads the editor template |
|
1411 | - * |
|
1412 | - * @param bool $creating |
|
1413 | - */ |
|
1414 | - private function loadEditorTemplate($creating = true) { |
|
1415 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1416 | - //these vars are used by the template |
|
1417 | - $editing = true; |
|
1418 | - $post_ID = $post->ID; |
|
1419 | - if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
1420 | - //only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
1421 | - //otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
1422 | - if ($creating) { |
|
1423 | - wp_enqueue_script('autosave'); |
|
1424 | - } else { |
|
1425 | - if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1426 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
1427 | - ) { |
|
1428 | - $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1429 | - 'create_new', $this); |
|
1430 | - $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1431 | - 'action' => $create_new_action, |
|
1432 | - 'page' => $this->page_slug, |
|
1433 | - ), 'admin.php'); |
|
1434 | - } |
|
1435 | - } |
|
1436 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1437 | - } |
|
1438 | - } |
|
1439 | - |
|
1440 | - |
|
1441 | - |
|
1442 | - public function add_new_admin_page_global() |
|
1443 | - { |
|
1444 | - $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1445 | - ?> |
|
1341 | + $messages[$post->post_type] = array( |
|
1342 | + 0 => '', //Unused. Messages start at index 1. |
|
1343 | + 1 => sprintf( |
|
1344 | + __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1345 | + $this->_cpt_object->labels->singular_name, |
|
1346 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1347 | + '</a>' |
|
1348 | + ), |
|
1349 | + 2 => __('Custom field updated'), |
|
1350 | + 3 => __('Custom field deleted.'), |
|
1351 | + 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1352 | + 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
|
1353 | + $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1354 | + : false, |
|
1355 | + 6 => sprintf( |
|
1356 | + __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1357 | + $this->_cpt_object->labels->singular_name, |
|
1358 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1359 | + '</a>' |
|
1360 | + ), |
|
1361 | + 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1362 | + 8 => sprintf( |
|
1363 | + __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1364 | + $this->_cpt_object->labels->singular_name, |
|
1365 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1366 | + '</a>' |
|
1367 | + ), |
|
1368 | + 9 => sprintf( |
|
1369 | + __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1370 | + $this->_cpt_object->labels->singular_name, |
|
1371 | + '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1372 | + '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1373 | + '</a>' |
|
1374 | + ), |
|
1375 | + 10 => sprintf( |
|
1376 | + __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1377 | + $this->_cpt_object->labels->singular_name, |
|
1378 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1379 | + '</a>' |
|
1380 | + ), |
|
1381 | + ); |
|
1382 | + return $messages; |
|
1383 | + } |
|
1384 | + |
|
1385 | + |
|
1386 | + |
|
1387 | + /** |
|
1388 | + * default method for the 'create_new' route for cpt admin pages. |
|
1389 | + * For reference what to include in here, see wp-admin/post-new.php |
|
1390 | + * |
|
1391 | + * @access protected |
|
1392 | + * @return void |
|
1393 | + */ |
|
1394 | + protected function _create_new_cpt_item() |
|
1395 | + { |
|
1396 | + // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1397 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1398 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1399 | + $post_type_object = $this->_cpt_object; |
|
1400 | + $title = $post_type_object->labels->add_new_item; |
|
1401 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1402 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1403 | + //modify the default editor title field with default title. |
|
1404 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1405 | + $this->loadEditorTemplate(true); |
|
1406 | + } |
|
1407 | + |
|
1408 | + |
|
1409 | + /** |
|
1410 | + * Enqueues auto-save and loads the editor template |
|
1411 | + * |
|
1412 | + * @param bool $creating |
|
1413 | + */ |
|
1414 | + private function loadEditorTemplate($creating = true) { |
|
1415 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1416 | + //these vars are used by the template |
|
1417 | + $editing = true; |
|
1418 | + $post_ID = $post->ID; |
|
1419 | + if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
1420 | + //only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
1421 | + //otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
1422 | + if ($creating) { |
|
1423 | + wp_enqueue_script('autosave'); |
|
1424 | + } else { |
|
1425 | + if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1426 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
1427 | + ) { |
|
1428 | + $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1429 | + 'create_new', $this); |
|
1430 | + $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1431 | + 'action' => $create_new_action, |
|
1432 | + 'page' => $this->page_slug, |
|
1433 | + ), 'admin.php'); |
|
1434 | + } |
|
1435 | + } |
|
1436 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1437 | + } |
|
1438 | + } |
|
1439 | + |
|
1440 | + |
|
1441 | + |
|
1442 | + public function add_new_admin_page_global() |
|
1443 | + { |
|
1444 | + $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1445 | + ?> |
|
1446 | 1446 | <script type="text/javascript"> |
1447 | 1447 | adminpage = '<?php echo $admin_page; ?>'; |
1448 | 1448 | </script> |
1449 | 1449 | <?php |
1450 | - } |
|
1451 | - |
|
1452 | - |
|
1453 | - |
|
1454 | - /** |
|
1455 | - * default method for the 'edit' route for cpt admin pages |
|
1456 | - * For reference on what to put in here, refer to wp-admin/post.php |
|
1457 | - * |
|
1458 | - * @access protected |
|
1459 | - * @return string template for edit cpt form |
|
1460 | - */ |
|
1461 | - protected function _edit_cpt_item() |
|
1462 | - { |
|
1463 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1464 | - $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1465 | - $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1466 | - if (empty ($post)) { |
|
1467 | - wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); |
|
1468 | - } |
|
1469 | - if ( ! empty($_GET['get-post-lock'])) { |
|
1470 | - wp_set_post_lock($post_id); |
|
1471 | - wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1472 | - exit(); |
|
1473 | - } |
|
1474 | - |
|
1475 | - // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1476 | - $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1477 | - $post_type_object = $this->_cpt_object; |
|
1478 | - |
|
1479 | - if ( ! wp_check_post_lock($post->ID)) { |
|
1480 | - wp_set_post_lock($post->ID); |
|
1481 | - } |
|
1482 | - add_action('admin_footer', '_admin_notice_post_locked'); |
|
1483 | - if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
1484 | - wp_enqueue_script('admin-comments'); |
|
1485 | - enqueue_comment_hotkeys_js(); |
|
1486 | - } |
|
1487 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1488 | - //modify the default editor title field with default title. |
|
1489 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1490 | - $this->loadEditorTemplate(false); |
|
1491 | - } |
|
1492 | - |
|
1493 | - |
|
1494 | - |
|
1495 | - /** |
|
1496 | - * some getters |
|
1497 | - */ |
|
1498 | - /** |
|
1499 | - * This returns the protected _cpt_model_obj property |
|
1500 | - * |
|
1501 | - * @return EE_CPT_Base |
|
1502 | - */ |
|
1503 | - public function get_cpt_model_obj() |
|
1504 | - { |
|
1505 | - return $this->_cpt_model_obj; |
|
1506 | - } |
|
1450 | + } |
|
1451 | + |
|
1452 | + |
|
1453 | + |
|
1454 | + /** |
|
1455 | + * default method for the 'edit' route for cpt admin pages |
|
1456 | + * For reference on what to put in here, refer to wp-admin/post.php |
|
1457 | + * |
|
1458 | + * @access protected |
|
1459 | + * @return string template for edit cpt form |
|
1460 | + */ |
|
1461 | + protected function _edit_cpt_item() |
|
1462 | + { |
|
1463 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1464 | + $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1465 | + $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1466 | + if (empty ($post)) { |
|
1467 | + wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); |
|
1468 | + } |
|
1469 | + if ( ! empty($_GET['get-post-lock'])) { |
|
1470 | + wp_set_post_lock($post_id); |
|
1471 | + wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1472 | + exit(); |
|
1473 | + } |
|
1474 | + |
|
1475 | + // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1476 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1477 | + $post_type_object = $this->_cpt_object; |
|
1478 | + |
|
1479 | + if ( ! wp_check_post_lock($post->ID)) { |
|
1480 | + wp_set_post_lock($post->ID); |
|
1481 | + } |
|
1482 | + add_action('admin_footer', '_admin_notice_post_locked'); |
|
1483 | + if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
1484 | + wp_enqueue_script('admin-comments'); |
|
1485 | + enqueue_comment_hotkeys_js(); |
|
1486 | + } |
|
1487 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1488 | + //modify the default editor title field with default title. |
|
1489 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1490 | + $this->loadEditorTemplate(false); |
|
1491 | + } |
|
1492 | + |
|
1493 | + |
|
1494 | + |
|
1495 | + /** |
|
1496 | + * some getters |
|
1497 | + */ |
|
1498 | + /** |
|
1499 | + * This returns the protected _cpt_model_obj property |
|
1500 | + * |
|
1501 | + * @return EE_CPT_Base |
|
1502 | + */ |
|
1503 | + public function get_cpt_model_obj() |
|
1504 | + { |
|
1505 | + return $this->_cpt_model_obj; |
|
1506 | + } |
|
1507 | 1507 | |
1508 | 1508 | } |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | */ |
243 | 243 | protected function _register_autosave_containers($ids) |
244 | 244 | { |
245 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
245 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | //filter _autosave_containers |
290 | 290 | $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
291 | 291 | $this->_autosave_containers, $this); |
292 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
292 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers', |
|
293 | 293 | $containers, $this); |
294 | 294 | |
295 | 295 | wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | // This is for any plugins that are doing things properly |
402 | 402 | // and hooking into the load page hook for core wp cpt routes. |
403 | 403 | global $pagenow; |
404 | - do_action('load-' . $pagenow); |
|
404 | + do_action('load-'.$pagenow); |
|
405 | 405 | $this->modify_current_screen(); |
406 | 406 | add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
407 | 407 | //we route REALLY early. |
@@ -432,8 +432,8 @@ discard block |
||
432 | 432 | 'admin.php?page=espresso_registrations&action=contact_list', |
433 | 433 | ), |
434 | 434 | 1 => array( |
435 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
436 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
435 | + 'edit.php?post_type='.$this->_cpt_object->name, |
|
436 | + 'admin.php?page='.$this->_cpt_object->name, |
|
437 | 437 | ), |
438 | 438 | ); |
439 | 439 | foreach ($routes_to_match as $route_matches) { |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | $cpt_has_support = ! empty($cpt_args['page_templates']); |
467 | 467 | |
468 | 468 | //if the installed version of WP is > 4.7 we do some additional checks. |
469 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
469 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
470 | 470 | $post_templates = wp_get_theme()->get_post_templates(); |
471 | 471 | //if there are $post_templates for this cpt, then we return false for this method because |
472 | 472 | //that means we aren't going to load our page template manager and leave that up to the native |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | global $post; |
490 | 490 | $template = ''; |
491 | 491 | |
492 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
492 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
493 | 493 | $page_template_count = count(get_page_templates()); |
494 | 494 | } else { |
495 | 495 | $page_template_count = count(get_page_templates($post)); |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | $post = get_post($id); |
527 | 527 | if ('publish' !== get_post_status($post)) { |
528 | 528 | //include shims for the `get_preview_post_link` function |
529 | - require_once( EE_CORE . 'wordpress-shims.php' ); |
|
529 | + require_once(EE_CORE.'wordpress-shims.php'); |
|
530 | 530 | $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
531 | 531 | . get_preview_post_link($id) |
532 | 532 | . '" class="button button-small">' |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | $template_args['statuses'] = $statuses; |
565 | 565 | } |
566 | 566 | |
567 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
567 | + $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php'; |
|
568 | 568 | EEH_Template::display_template($template, $template_args); |
569 | 569 | } |
570 | 570 | |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | $this->_template_args['success'] = true; |
619 | 619 | } |
620 | 620 | do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
621 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
621 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this); |
|
622 | 622 | //now let's return json |
623 | 623 | $this->_return_json(); |
624 | 624 | } |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | } |
717 | 717 | // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
718 | 718 | if ($ignore_route_check) { |
719 | - $post_type = get_post_type($id); |
|
719 | + $post_type = get_post_type($id); |
|
720 | 720 | /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
721 | 721 | $custom_post_types = LoaderFactory::getLoader()->getShared( |
722 | 722 | 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
@@ -1028,7 +1028,7 @@ discard block |
||
1028 | 1028 | //global action |
1029 | 1029 | do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
1030 | 1030 | //class specific action so you can limit hooking into a specific page. |
1031 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1031 | + do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | |
@@ -1106,7 +1106,7 @@ discard block |
||
1106 | 1106 | if ( ! empty($id) && get_option('permalink_structure') !== '') { |
1107 | 1107 | $post = get_post($id); |
1108 | 1108 | if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
1109 | - $shortlink = home_url('?p=' . $post->ID); |
|
1109 | + $shortlink = home_url('?p='.$post->ID); |
|
1110 | 1110 | } |
1111 | 1111 | } |
1112 | 1112 | return $shortlink; |
@@ -1141,11 +1141,11 @@ discard block |
||
1141 | 1141 | */ |
1142 | 1142 | public function cpt_post_form_hidden_input() |
1143 | 1143 | { |
1144 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1144 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />'; |
|
1145 | 1145 | //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
1146 | 1146 | echo '<div id="ee-cpt-hidden-inputs">'; |
1147 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1148 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1147 | + echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />'; |
|
1148 | + echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />'; |
|
1149 | 1149 | echo '</div>'; |
1150 | 1150 | } |
1151 | 1151 | |
@@ -1232,7 +1232,7 @@ discard block |
||
1232 | 1232 | $this->_set_model_object($post->ID, true); |
1233 | 1233 | |
1234 | 1234 | //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
1235 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1235 | + $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1236 | 1236 | |
1237 | 1237 | return EE_Admin_Page::add_query_args_and_nonce( |
1238 | 1238 | array( |
@@ -1343,39 +1343,39 @@ discard block |
||
1343 | 1343 | 1 => sprintf( |
1344 | 1344 | __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
1345 | 1345 | $this->_cpt_object->labels->singular_name, |
1346 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1346 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1347 | 1347 | '</a>' |
1348 | 1348 | ), |
1349 | 1349 | 2 => __('Custom field updated'), |
1350 | 1350 | 3 => __('Custom field deleted.'), |
1351 | 1351 | 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
1352 | 1352 | 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
1353 | - $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1353 | + $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false)) |
|
1354 | 1354 | : false, |
1355 | 1355 | 6 => sprintf( |
1356 | 1356 | __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
1357 | 1357 | $this->_cpt_object->labels->singular_name, |
1358 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1358 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1359 | 1359 | '</a>' |
1360 | 1360 | ), |
1361 | 1361 | 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
1362 | 1362 | 8 => sprintf( |
1363 | 1363 | __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
1364 | 1364 | $this->_cpt_object->labels->singular_name, |
1365 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1365 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">', |
|
1366 | 1366 | '</a>' |
1367 | 1367 | ), |
1368 | 1368 | 9 => sprintf( |
1369 | 1369 | __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
1370 | 1370 | $this->_cpt_object->labels->singular_name, |
1371 | - '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1372 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1371 | + '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>', |
|
1372 | + '<a target="_blank" href="'.esc_url(get_permalink($id)), |
|
1373 | 1373 | '</a>' |
1374 | 1374 | ), |
1375 | 1375 | 10 => sprintf( |
1376 | 1376 | __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
1377 | 1377 | $this->_cpt_object->labels->singular_name, |
1378 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1378 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1379 | 1379 | '</a>' |
1380 | 1380 | ), |
1381 | 1381 | ); |
@@ -1398,7 +1398,7 @@ discard block |
||
1398 | 1398 | $post_type = $this->_cpt_routes[$this->_req_action]; |
1399 | 1399 | $post_type_object = $this->_cpt_object; |
1400 | 1400 | $title = $post_type_object->labels->add_new_item; |
1401 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1401 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1402 | 1402 | add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
1403 | 1403 | //modify the default editor title field with default title. |
1404 | 1404 | add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
@@ -1433,7 +1433,7 @@ discard block |
||
1433 | 1433 | ), 'admin.php'); |
1434 | 1434 | } |
1435 | 1435 | } |
1436 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1436 | + include_once WP_ADMIN_PATH.'edit-form-advanced.php'; |
|
1437 | 1437 | } |
1438 | 1438 | } |
1439 | 1439 |
@@ -21,96 +21,96 @@ |
||
21 | 21 | class RegisterCustomTaxonomies |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var CustomTaxonomyDefinitions $custom_taxonomies |
|
26 | - */ |
|
27 | - public $custom_taxonomies; |
|
24 | + /** |
|
25 | + * @var CustomTaxonomyDefinitions $custom_taxonomies |
|
26 | + */ |
|
27 | + public $custom_taxonomies; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * RegisterCustomTaxonomies constructor. |
|
32 | - * |
|
33 | - * @param CustomTaxonomyDefinitions $custom_taxonomies |
|
34 | - */ |
|
35 | - public function __construct(CustomTaxonomyDefinitions $custom_taxonomies) |
|
36 | - { |
|
37 | - $this->custom_taxonomies = $custom_taxonomies; |
|
38 | - } |
|
30 | + /** |
|
31 | + * RegisterCustomTaxonomies constructor. |
|
32 | + * |
|
33 | + * @param CustomTaxonomyDefinitions $custom_taxonomies |
|
34 | + */ |
|
35 | + public function __construct(CustomTaxonomyDefinitions $custom_taxonomies) |
|
36 | + { |
|
37 | + $this->custom_taxonomies = $custom_taxonomies; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @return void |
|
43 | - * @throws DomainException |
|
44 | - */ |
|
45 | - public function registerCustomTaxonomies() |
|
46 | - { |
|
47 | - $custom_taxonomies = $this->custom_taxonomies->getCustomTaxonomyDefinitions(); |
|
48 | - foreach ($custom_taxonomies as $taxonomy => $tax) { |
|
49 | - $this->registerCustomTaxonomy( |
|
50 | - $taxonomy, |
|
51 | - $tax['singular_name'], |
|
52 | - $tax['plural_name'], |
|
53 | - $tax['args'] |
|
54 | - ); |
|
55 | - } |
|
56 | - } |
|
41 | + /** |
|
42 | + * @return void |
|
43 | + * @throws DomainException |
|
44 | + */ |
|
45 | + public function registerCustomTaxonomies() |
|
46 | + { |
|
47 | + $custom_taxonomies = $this->custom_taxonomies->getCustomTaxonomyDefinitions(); |
|
48 | + foreach ($custom_taxonomies as $taxonomy => $tax) { |
|
49 | + $this->registerCustomTaxonomy( |
|
50 | + $taxonomy, |
|
51 | + $tax['singular_name'], |
|
52 | + $tax['plural_name'], |
|
53 | + $tax['args'] |
|
54 | + ); |
|
55 | + } |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Registers a custom taxonomy. Should be called before registering custom post types, |
|
61 | - * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'. |
|
62 | - * |
|
63 | - * @param string $taxonomy_name , eg 'books' |
|
64 | - * @param string $singular_name internationalized singular name |
|
65 | - * @param string $plural_name internationalized plural name |
|
66 | - * @param array $override_arguments like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy |
|
67 | - * @throws DomainException |
|
68 | - */ |
|
69 | - public function registerCustomTaxonomy($taxonomy_name, $singular_name, $plural_name, array $override_arguments) |
|
70 | - { |
|
71 | - $result = register_taxonomy( |
|
72 | - $taxonomy_name, |
|
73 | - null, |
|
74 | - $this->prepareArguments( |
|
75 | - $singular_name, |
|
76 | - $plural_name, |
|
77 | - $override_arguments |
|
78 | - ) |
|
79 | - ); |
|
80 | - if ($result instanceof WP_Error) { |
|
81 | - throw new DomainException($result->get_error_message()); |
|
82 | - } |
|
83 | - } |
|
59 | + /** |
|
60 | + * Registers a custom taxonomy. Should be called before registering custom post types, |
|
61 | + * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'. |
|
62 | + * |
|
63 | + * @param string $taxonomy_name , eg 'books' |
|
64 | + * @param string $singular_name internationalized singular name |
|
65 | + * @param string $plural_name internationalized plural name |
|
66 | + * @param array $override_arguments like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy |
|
67 | + * @throws DomainException |
|
68 | + */ |
|
69 | + public function registerCustomTaxonomy($taxonomy_name, $singular_name, $plural_name, array $override_arguments) |
|
70 | + { |
|
71 | + $result = register_taxonomy( |
|
72 | + $taxonomy_name, |
|
73 | + null, |
|
74 | + $this->prepareArguments( |
|
75 | + $singular_name, |
|
76 | + $plural_name, |
|
77 | + $override_arguments |
|
78 | + ) |
|
79 | + ); |
|
80 | + if ($result instanceof WP_Error) { |
|
81 | + throw new DomainException($result->get_error_message()); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | |
86 | - /** |
|
87 | - * @param string $singular_name |
|
88 | - * @param string $plural_name |
|
89 | - * @param array $override_arguments |
|
90 | - * @since $VID:$ |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - protected function prepareArguments($singular_name, $plural_name, array $override_arguments){ |
|
94 | - $arguments = array( |
|
95 | - 'hierarchical' => true, |
|
96 | - 'labels' => array( |
|
97 | - 'name' => $plural_name, |
|
98 | - 'singular_name' => $singular_name, |
|
99 | - ), |
|
100 | - 'show_ui' => true, |
|
101 | - 'show_ee_ui' => true, |
|
102 | - 'show_admin_column' => true, |
|
103 | - 'query_var' => true, |
|
104 | - 'show_in_nav_menus' => false, |
|
105 | - 'map_meta_cap' => true |
|
106 | - ); |
|
107 | - if ($override_arguments) { |
|
108 | - if (isset($override_args['labels'])) { |
|
109 | - $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
110 | - $arguments['labels'] = $labels; |
|
111 | - } |
|
112 | - $arguments = array_merge($arguments, $override_arguments); |
|
113 | - } |
|
114 | - return $arguments; |
|
115 | - } |
|
86 | + /** |
|
87 | + * @param string $singular_name |
|
88 | + * @param string $plural_name |
|
89 | + * @param array $override_arguments |
|
90 | + * @since $VID:$ |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + protected function prepareArguments($singular_name, $plural_name, array $override_arguments){ |
|
94 | + $arguments = array( |
|
95 | + 'hierarchical' => true, |
|
96 | + 'labels' => array( |
|
97 | + 'name' => $plural_name, |
|
98 | + 'singular_name' => $singular_name, |
|
99 | + ), |
|
100 | + 'show_ui' => true, |
|
101 | + 'show_ee_ui' => true, |
|
102 | + 'show_admin_column' => true, |
|
103 | + 'query_var' => true, |
|
104 | + 'show_in_nav_menus' => false, |
|
105 | + 'map_meta_cap' => true |
|
106 | + ); |
|
107 | + if ($override_arguments) { |
|
108 | + if (isset($override_args['labels'])) { |
|
109 | + $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
110 | + $arguments['labels'] = $labels; |
|
111 | + } |
|
112 | + $arguments = array_merge($arguments, $override_arguments); |
|
113 | + } |
|
114 | + return $arguments; |
|
115 | + } |
|
116 | 116 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @since $VID:$ |
91 | 91 | * @return array |
92 | 92 | */ |
93 | - protected function prepareArguments($singular_name, $plural_name, array $override_arguments){ |
|
93 | + protected function prepareArguments($singular_name, $plural_name, array $override_arguments) { |
|
94 | 94 | $arguments = array( |
95 | 95 | 'hierarchical' => true, |
96 | 96 | 'labels' => array( |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | ); |
107 | 107 | if ($override_arguments) { |
108 | 108 | if (isset($override_args['labels'])) { |
109 | - $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
109 | + $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
110 | 110 | $arguments['labels'] = $labels; |
111 | 111 | } |
112 | 112 | $arguments = array_merge($arguments, $override_arguments); |
@@ -22,240 +22,240 @@ |
||
22 | 22 | class RegisterCustomPostTypes |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var CustomPostTypeDefinitions $custom_post_types |
|
27 | - */ |
|
28 | - public $custom_post_types; |
|
25 | + /** |
|
26 | + * @var CustomPostTypeDefinitions $custom_post_types |
|
27 | + */ |
|
28 | + public $custom_post_types; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var WP_Post_Type[] $wp_post_types |
|
32 | - */ |
|
33 | - public $wp_post_types = array(); |
|
30 | + /** |
|
31 | + * @var WP_Post_Type[] $wp_post_types |
|
32 | + */ |
|
33 | + public $wp_post_types = array(); |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * RegisterCustomPostTypes constructor. |
|
38 | - * |
|
39 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
40 | - */ |
|
41 | - public function __construct(CustomPostTypeDefinitions $custom_post_types) |
|
42 | - { |
|
43 | - $this->custom_post_types = $custom_post_types; |
|
44 | - } |
|
36 | + /** |
|
37 | + * RegisterCustomPostTypes constructor. |
|
38 | + * |
|
39 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
40 | + */ |
|
41 | + public function __construct(CustomPostTypeDefinitions $custom_post_types) |
|
42 | + { |
|
43 | + $this->custom_post_types = $custom_post_types; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * @return WP_Post_Type[] |
|
49 | - */ |
|
50 | - public function getRegisteredCustomPostTypes() |
|
51 | - { |
|
52 | - return $this->wp_post_types; |
|
53 | - } |
|
47 | + /** |
|
48 | + * @return WP_Post_Type[] |
|
49 | + */ |
|
50 | + public function getRegisteredCustomPostTypes() |
|
51 | + { |
|
52 | + return $this->wp_post_types; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * @return void |
|
58 | - * @throws DomainException |
|
59 | - */ |
|
60 | - public function registerCustomPostTypes() |
|
61 | - { |
|
62 | - $custom_post_types = $this->custom_post_types->getDefinitions(); |
|
63 | - foreach ($custom_post_types as $custom_post_type => $CPT) { |
|
64 | - $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType( |
|
65 | - $custom_post_type, |
|
66 | - $CPT['singular_name'], |
|
67 | - $CPT['plural_name'], |
|
68 | - $CPT['singular_slug'], |
|
69 | - $CPT['plural_slug'], |
|
70 | - $CPT['args'] |
|
71 | - ); |
|
72 | - } |
|
73 | - } |
|
56 | + /** |
|
57 | + * @return void |
|
58 | + * @throws DomainException |
|
59 | + */ |
|
60 | + public function registerCustomPostTypes() |
|
61 | + { |
|
62 | + $custom_post_types = $this->custom_post_types->getDefinitions(); |
|
63 | + foreach ($custom_post_types as $custom_post_type => $CPT) { |
|
64 | + $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType( |
|
65 | + $custom_post_type, |
|
66 | + $CPT['singular_name'], |
|
67 | + $CPT['plural_name'], |
|
68 | + $CPT['singular_slug'], |
|
69 | + $CPT['plural_slug'], |
|
70 | + $CPT['args'] |
|
71 | + ); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * Registers a new custom post type. Sets default settings given only the following params. |
|
78 | - * Returns the registered post type object, or an error object. |
|
79 | - * |
|
80 | - * @param string $post_type the actual post type name |
|
81 | - * IMPORTANT: |
|
82 | - * this must match what the slug is for admin pages related to this CPT |
|
83 | - * Also any models must use this slug as well |
|
84 | - * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
85 | - * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
86 | - * @param string $singular_slug |
|
87 | - * @param string $plural_slug |
|
88 | - * @param array $override_arguments exactly like $args as described in |
|
89 | - * http://codex.wordpress.org/Function_Reference/register_post_type |
|
90 | - * @return WP_Post_Type|WP_Error |
|
91 | - * @throws DomainException |
|
92 | - */ |
|
93 | - public function registerCustomPostType( |
|
94 | - $post_type, |
|
95 | - $singular_name, |
|
96 | - $plural_name, |
|
97 | - $singular_slug = '', |
|
98 | - $plural_slug = '', |
|
99 | - array $override_arguments = array() |
|
100 | - ) { |
|
101 | - $wp_post_type = register_post_type( |
|
102 | - $post_type, |
|
103 | - $this->prepareArguments( |
|
104 | - $post_type, |
|
105 | - $singular_name, |
|
106 | - $plural_name, |
|
107 | - $singular_slug, |
|
108 | - $plural_slug, |
|
109 | - $override_arguments |
|
110 | - ) |
|
111 | - ); |
|
112 | - if ($wp_post_type instanceof WP_Error) { |
|
113 | - throw new DomainException($wp_post_type->get_error_message()); |
|
114 | - } |
|
115 | - return $wp_post_type; |
|
116 | - } |
|
76 | + /** |
|
77 | + * Registers a new custom post type. Sets default settings given only the following params. |
|
78 | + * Returns the registered post type object, or an error object. |
|
79 | + * |
|
80 | + * @param string $post_type the actual post type name |
|
81 | + * IMPORTANT: |
|
82 | + * this must match what the slug is for admin pages related to this CPT |
|
83 | + * Also any models must use this slug as well |
|
84 | + * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
85 | + * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
86 | + * @param string $singular_slug |
|
87 | + * @param string $plural_slug |
|
88 | + * @param array $override_arguments exactly like $args as described in |
|
89 | + * http://codex.wordpress.org/Function_Reference/register_post_type |
|
90 | + * @return WP_Post_Type|WP_Error |
|
91 | + * @throws DomainException |
|
92 | + */ |
|
93 | + public function registerCustomPostType( |
|
94 | + $post_type, |
|
95 | + $singular_name, |
|
96 | + $plural_name, |
|
97 | + $singular_slug = '', |
|
98 | + $plural_slug = '', |
|
99 | + array $override_arguments = array() |
|
100 | + ) { |
|
101 | + $wp_post_type = register_post_type( |
|
102 | + $post_type, |
|
103 | + $this->prepareArguments( |
|
104 | + $post_type, |
|
105 | + $singular_name, |
|
106 | + $plural_name, |
|
107 | + $singular_slug, |
|
108 | + $plural_slug, |
|
109 | + $override_arguments |
|
110 | + ) |
|
111 | + ); |
|
112 | + if ($wp_post_type instanceof WP_Error) { |
|
113 | + throw new DomainException($wp_post_type->get_error_message()); |
|
114 | + } |
|
115 | + return $wp_post_type; |
|
116 | + } |
|
117 | 117 | |
118 | 118 | |
119 | - /** |
|
120 | - * @param string $post_type the actual post type name |
|
121 | - * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
122 | - * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
123 | - * @param string $singular_slug |
|
124 | - * @param string $plural_slug |
|
125 | - * @param array $override_arguments The default values set in this function will be overridden |
|
126 | - * by whatever you set in $override_arguments |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - protected function prepareArguments( |
|
130 | - $post_type, |
|
131 | - $singular_name, |
|
132 | - $plural_name, |
|
133 | - $singular_slug, |
|
134 | - $plural_slug, |
|
135 | - array $override_arguments = array() |
|
136 | - ) { |
|
137 | - // verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name |
|
138 | - $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name; |
|
139 | - $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name; |
|
140 | - $labels = $this->getLabels( |
|
141 | - $singular_name, |
|
142 | - $plural_name, |
|
143 | - $singular_slug, |
|
144 | - $plural_slug |
|
145 | - ); |
|
146 | - // note the page_templates arg in the supports index is something specific to EE. |
|
147 | - // WordPress doesn't actually have that in their register_post_type api. |
|
148 | - $arguments = $this->getDefaultArguments($labels, $post_type, $plural_slug); |
|
149 | - if ($override_arguments) { |
|
150 | - if (isset($override_arguments['labels'])) { |
|
151 | - $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
152 | - } |
|
153 | - $arguments = array_merge($arguments, $override_arguments); |
|
154 | - $arguments['labels'] = $labels; |
|
155 | - } |
|
156 | - return $arguments; |
|
157 | - } |
|
119 | + /** |
|
120 | + * @param string $post_type the actual post type name |
|
121 | + * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
122 | + * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
123 | + * @param string $singular_slug |
|
124 | + * @param string $plural_slug |
|
125 | + * @param array $override_arguments The default values set in this function will be overridden |
|
126 | + * by whatever you set in $override_arguments |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + protected function prepareArguments( |
|
130 | + $post_type, |
|
131 | + $singular_name, |
|
132 | + $plural_name, |
|
133 | + $singular_slug, |
|
134 | + $plural_slug, |
|
135 | + array $override_arguments = array() |
|
136 | + ) { |
|
137 | + // verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name |
|
138 | + $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name; |
|
139 | + $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name; |
|
140 | + $labels = $this->getLabels( |
|
141 | + $singular_name, |
|
142 | + $plural_name, |
|
143 | + $singular_slug, |
|
144 | + $plural_slug |
|
145 | + ); |
|
146 | + // note the page_templates arg in the supports index is something specific to EE. |
|
147 | + // WordPress doesn't actually have that in their register_post_type api. |
|
148 | + $arguments = $this->getDefaultArguments($labels, $post_type, $plural_slug); |
|
149 | + if ($override_arguments) { |
|
150 | + if (isset($override_arguments['labels'])) { |
|
151 | + $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
152 | + } |
|
153 | + $arguments = array_merge($arguments, $override_arguments); |
|
154 | + $arguments['labels'] = $labels; |
|
155 | + } |
|
156 | + return $arguments; |
|
157 | + } |
|
158 | 158 | |
159 | 159 | |
160 | - /** |
|
161 | - * @param string $singular_name |
|
162 | - * @param string $plural_name |
|
163 | - * @param string $singular_slug |
|
164 | - * @param string $plural_slug |
|
165 | - * @return array |
|
166 | - */ |
|
167 | - private function getLabels($singular_name, $plural_name, $singular_slug, $plural_slug) |
|
168 | - { |
|
169 | - return array( |
|
170 | - 'name' => $plural_name, |
|
171 | - 'singular_name' => $singular_name, |
|
172 | - 'singular_slug' => $singular_slug, |
|
173 | - 'plural_slug' => $plural_slug, |
|
174 | - 'add_new' => sprintf( |
|
175 | - esc_html_x('Add %s', 'Add Event', 'event_espresso'), |
|
176 | - $singular_name |
|
177 | - ), |
|
178 | - 'add_new_item' => sprintf( |
|
179 | - esc_html_x('Add New %s', 'Add New Event', 'event_espresso'), |
|
180 | - $singular_name |
|
181 | - ), |
|
182 | - 'edit_item' => sprintf( |
|
183 | - esc_html_x('Edit %s', 'Edit Event', 'event_espresso'), |
|
184 | - $singular_name |
|
185 | - ), |
|
186 | - 'new_item' => sprintf( |
|
187 | - esc_html_x('New %s', 'New Event', 'event_espresso'), |
|
188 | - $singular_name |
|
189 | - ), |
|
190 | - 'all_items' => sprintf( |
|
191 | - esc_html_x('All %s', 'All Events', 'event_espresso'), |
|
192 | - $plural_name |
|
193 | - ), |
|
194 | - 'view_item' => sprintf( |
|
195 | - esc_html_x('View %s', 'View Event', 'event_espresso'), |
|
196 | - $singular_name |
|
197 | - ), |
|
198 | - 'search_items' => sprintf( |
|
199 | - esc_html_x('Search %s', 'Search Events', 'event_espresso'), |
|
200 | - $plural_name |
|
201 | - ), |
|
202 | - 'not_found' => sprintf( |
|
203 | - esc_html_x('No %s found', 'No Events found', 'event_espresso'), |
|
204 | - $plural_name |
|
205 | - ), |
|
206 | - 'not_found_in_trash' => sprintf( |
|
207 | - esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'), |
|
208 | - $plural_name |
|
209 | - ), |
|
210 | - 'parent_item_colon' => '', |
|
211 | - 'menu_name' => $plural_name, |
|
212 | - ); |
|
213 | - } |
|
160 | + /** |
|
161 | + * @param string $singular_name |
|
162 | + * @param string $plural_name |
|
163 | + * @param string $singular_slug |
|
164 | + * @param string $plural_slug |
|
165 | + * @return array |
|
166 | + */ |
|
167 | + private function getLabels($singular_name, $plural_name, $singular_slug, $plural_slug) |
|
168 | + { |
|
169 | + return array( |
|
170 | + 'name' => $plural_name, |
|
171 | + 'singular_name' => $singular_name, |
|
172 | + 'singular_slug' => $singular_slug, |
|
173 | + 'plural_slug' => $plural_slug, |
|
174 | + 'add_new' => sprintf( |
|
175 | + esc_html_x('Add %s', 'Add Event', 'event_espresso'), |
|
176 | + $singular_name |
|
177 | + ), |
|
178 | + 'add_new_item' => sprintf( |
|
179 | + esc_html_x('Add New %s', 'Add New Event', 'event_espresso'), |
|
180 | + $singular_name |
|
181 | + ), |
|
182 | + 'edit_item' => sprintf( |
|
183 | + esc_html_x('Edit %s', 'Edit Event', 'event_espresso'), |
|
184 | + $singular_name |
|
185 | + ), |
|
186 | + 'new_item' => sprintf( |
|
187 | + esc_html_x('New %s', 'New Event', 'event_espresso'), |
|
188 | + $singular_name |
|
189 | + ), |
|
190 | + 'all_items' => sprintf( |
|
191 | + esc_html_x('All %s', 'All Events', 'event_espresso'), |
|
192 | + $plural_name |
|
193 | + ), |
|
194 | + 'view_item' => sprintf( |
|
195 | + esc_html_x('View %s', 'View Event', 'event_espresso'), |
|
196 | + $singular_name |
|
197 | + ), |
|
198 | + 'search_items' => sprintf( |
|
199 | + esc_html_x('Search %s', 'Search Events', 'event_espresso'), |
|
200 | + $plural_name |
|
201 | + ), |
|
202 | + 'not_found' => sprintf( |
|
203 | + esc_html_x('No %s found', 'No Events found', 'event_espresso'), |
|
204 | + $plural_name |
|
205 | + ), |
|
206 | + 'not_found_in_trash' => sprintf( |
|
207 | + esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'), |
|
208 | + $plural_name |
|
209 | + ), |
|
210 | + 'parent_item_colon' => '', |
|
211 | + 'menu_name' => $plural_name, |
|
212 | + ); |
|
213 | + } |
|
214 | 214 | |
215 | 215 | |
216 | - /** |
|
217 | - * @param array $labels |
|
218 | - * @param string $post_type |
|
219 | - * @param string $plural_slug |
|
220 | - * @return array |
|
221 | - */ |
|
222 | - private function getDefaultArguments(array $labels, $post_type, $plural_slug) |
|
223 | - { |
|
224 | - return array( |
|
225 | - 'labels' => $labels, |
|
226 | - 'public' => true, |
|
227 | - 'publicly_queryable' => true, |
|
228 | - 'show_ui' => false, |
|
229 | - 'show_ee_ui' => true, |
|
230 | - 'show_in_menu' => false, |
|
231 | - 'show_in_nav_menus' => false, |
|
232 | - 'query_var' => true, |
|
233 | - 'rewrite' => apply_filters( |
|
234 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite', |
|
235 | - // legacy filter applied for now, |
|
236 | - // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
237 | - apply_filters( |
|
238 | - 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
239 | - array('slug' => $plural_slug), |
|
240 | - $post_type |
|
241 | - ), |
|
242 | - $post_type, |
|
243 | - $plural_slug |
|
244 | - ), |
|
245 | - 'capability_type' => 'post', |
|
246 | - 'map_meta_cap' => true, |
|
247 | - 'has_archive' => true, |
|
248 | - 'hierarchical' => false, |
|
249 | - 'menu_position' => null, |
|
250 | - 'supports' => array( |
|
251 | - 'title', |
|
252 | - 'editor', |
|
253 | - 'author', |
|
254 | - 'thumbnail', |
|
255 | - 'excerpt', |
|
256 | - 'custom-fields', |
|
257 | - 'comments', |
|
258 | - ), |
|
259 | - ); |
|
260 | - } |
|
216 | + /** |
|
217 | + * @param array $labels |
|
218 | + * @param string $post_type |
|
219 | + * @param string $plural_slug |
|
220 | + * @return array |
|
221 | + */ |
|
222 | + private function getDefaultArguments(array $labels, $post_type, $plural_slug) |
|
223 | + { |
|
224 | + return array( |
|
225 | + 'labels' => $labels, |
|
226 | + 'public' => true, |
|
227 | + 'publicly_queryable' => true, |
|
228 | + 'show_ui' => false, |
|
229 | + 'show_ee_ui' => true, |
|
230 | + 'show_in_menu' => false, |
|
231 | + 'show_in_nav_menus' => false, |
|
232 | + 'query_var' => true, |
|
233 | + 'rewrite' => apply_filters( |
|
234 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite', |
|
235 | + // legacy filter applied for now, |
|
236 | + // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
237 | + apply_filters( |
|
238 | + 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
239 | + array('slug' => $plural_slug), |
|
240 | + $post_type |
|
241 | + ), |
|
242 | + $post_type, |
|
243 | + $plural_slug |
|
244 | + ), |
|
245 | + 'capability_type' => 'post', |
|
246 | + 'map_meta_cap' => true, |
|
247 | + 'has_archive' => true, |
|
248 | + 'hierarchical' => false, |
|
249 | + 'menu_position' => null, |
|
250 | + 'supports' => array( |
|
251 | + 'title', |
|
252 | + 'editor', |
|
253 | + 'author', |
|
254 | + 'thumbnail', |
|
255 | + 'excerpt', |
|
256 | + 'custom-fields', |
|
257 | + 'comments', |
|
258 | + ), |
|
259 | + ); |
|
260 | + } |
|
261 | 261 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | { |
62 | 62 | $custom_post_types = $this->custom_post_types->getDefinitions(); |
63 | 63 | foreach ($custom_post_types as $custom_post_type => $CPT) { |
64 | - $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType( |
|
64 | + $this->wp_post_types[$custom_post_type] = $this->registerCustomPostType( |
|
65 | 65 | $custom_post_type, |
66 | 66 | $CPT['singular_name'], |
67 | 67 | $CPT['plural_name'], |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - '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.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + '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.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - '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.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + '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.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.028'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.028'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | use EventEspresso\core\services\request\ResponseInterface; |
10 | 10 | |
11 | 11 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
12 | - exit('No direct script access allowed'); |
|
12 | + exit('No direct script access allowed'); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | |
@@ -26,967 +26,967 @@ discard block |
||
26 | 26 | class EE_Dependency_Map |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * This means that the requested class dependency is not present in the dependency map |
|
31 | - */ |
|
32 | - const not_registered = 0; |
|
33 | - |
|
34 | - /** |
|
35 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
36 | - */ |
|
37 | - const load_new_object = 1; |
|
38 | - |
|
39 | - /** |
|
40 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
41 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
42 | - */ |
|
43 | - const load_from_cache = 2; |
|
44 | - |
|
45 | - /** |
|
46 | - * When registering a dependency, |
|
47 | - * this indicates to keep any existing dependencies that already exist, |
|
48 | - * and simply discard any new dependencies declared in the incoming data |
|
49 | - */ |
|
50 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
51 | - |
|
52 | - /** |
|
53 | - * When registering a dependency, |
|
54 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
55 | - */ |
|
56 | - const OVERWRITE_DEPENDENCIES = 1; |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @type EE_Dependency_Map $_instance |
|
62 | - */ |
|
63 | - protected static $_instance; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var ClassInterfaceCache $class_cache |
|
67 | - */ |
|
68 | - private $class_cache; |
|
69 | - |
|
70 | - /** |
|
71 | - * @type RequestInterface $request |
|
72 | - */ |
|
73 | - protected $request; |
|
74 | - |
|
75 | - /** |
|
76 | - * @type LegacyRequestInterface $legacy_request |
|
77 | - */ |
|
78 | - protected $legacy_request; |
|
79 | - |
|
80 | - /** |
|
81 | - * @type ResponseInterface $response |
|
82 | - */ |
|
83 | - protected $response; |
|
84 | - |
|
85 | - /** |
|
86 | - * @type LoaderInterface $loader |
|
87 | - */ |
|
88 | - protected $loader; |
|
89 | - |
|
90 | - /** |
|
91 | - * @type array $_dependency_map |
|
92 | - */ |
|
93 | - protected $_dependency_map = array(); |
|
94 | - |
|
95 | - /** |
|
96 | - * @type array $_class_loaders |
|
97 | - */ |
|
98 | - protected $_class_loaders = array(); |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * EE_Dependency_Map constructor. |
|
103 | - * |
|
104 | - * @param ClassInterfaceCache $class_cache |
|
105 | - */ |
|
106 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
107 | - { |
|
108 | - $this->class_cache = $class_cache; |
|
109 | - do_action('EE_Dependency_Map____construct', $this); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - public function initialize() |
|
117 | - { |
|
118 | - $this->_register_core_dependencies(); |
|
119 | - $this->_register_core_class_loaders(); |
|
120 | - $this->_register_core_aliases(); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @singleton method used to instantiate class object |
|
126 | - * @param ClassInterfaceCache|null $class_cache |
|
127 | - * @return EE_Dependency_Map |
|
128 | - */ |
|
129 | - public static function instance(ClassInterfaceCache $class_cache = null) { |
|
130 | - // check if class object is instantiated, and instantiated properly |
|
131 | - if ( |
|
132 | - ! self::$_instance instanceof EE_Dependency_Map |
|
133 | - && $class_cache instanceof ClassInterfaceCache |
|
134 | - ) { |
|
135 | - self::$_instance = new EE_Dependency_Map($class_cache); |
|
136 | - } |
|
137 | - return self::$_instance; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param RequestInterface $request |
|
143 | - */ |
|
144 | - public function setRequest(RequestInterface $request) |
|
145 | - { |
|
146 | - $this->request = $request; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param LegacyRequestInterface $legacy_request |
|
152 | - */ |
|
153 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
154 | - { |
|
155 | - $this->legacy_request = $legacy_request; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @param ResponseInterface $response |
|
161 | - */ |
|
162 | - public function setResponse(ResponseInterface $response) |
|
163 | - { |
|
164 | - $this->response = $response; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param LoaderInterface $loader |
|
171 | - */ |
|
172 | - public function setLoader(LoaderInterface $loader) |
|
173 | - { |
|
174 | - $this->loader = $loader; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @param string $class |
|
181 | - * @param array $dependencies |
|
182 | - * @param int $overwrite |
|
183 | - * @return bool |
|
184 | - */ |
|
185 | - public static function register_dependencies( |
|
186 | - $class, |
|
187 | - array $dependencies, |
|
188 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
189 | - ) { |
|
190 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
197 | - * to the class specified by the first parameter. |
|
198 | - * IMPORTANT !!! |
|
199 | - * The order of elements in the incoming $dependencies array MUST match |
|
200 | - * the order of the constructor parameters for the class in question. |
|
201 | - * This is especially important when overriding any existing dependencies that are registered. |
|
202 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
203 | - * |
|
204 | - * @param string $class |
|
205 | - * @param array $dependencies |
|
206 | - * @param int $overwrite |
|
207 | - * @return bool |
|
208 | - */ |
|
209 | - public function registerDependencies( |
|
210 | - $class, |
|
211 | - array $dependencies, |
|
212 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
213 | - ) { |
|
214 | - $class = trim($class, '\\'); |
|
215 | - $registered = false; |
|
216 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
217 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
218 | - } |
|
219 | - // we need to make sure that any aliases used when registering a dependency |
|
220 | - // get resolved to the correct class name |
|
221 | - foreach ($dependencies as $dependency => $load_source) { |
|
222 | - $alias = self::$_instance->getFqnForAlias($dependency); |
|
223 | - if ( |
|
224 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
225 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
226 | - ) { |
|
227 | - unset($dependencies[$dependency]); |
|
228 | - $dependencies[$alias] = $load_source; |
|
229 | - $registered = true; |
|
230 | - } |
|
231 | - } |
|
232 | - // now add our two lists of dependencies together. |
|
233 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
234 | - // so $dependencies is NOT overwritten because it is listed first |
|
235 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
236 | - // Union is way faster than array_merge() but should be used with caution... |
|
237 | - // especially with numerically indexed arrays |
|
238 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
239 | - // now we need to ensure that the resulting dependencies |
|
240 | - // array only has the entries that are required for the class |
|
241 | - // so first count how many dependencies were originally registered for the class |
|
242 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
243 | - // if that count is non-zero (meaning dependencies were already registered) |
|
244 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
245 | - // then truncate the final array to match that count |
|
246 | - ? array_slice($dependencies, 0, $dependency_count) |
|
247 | - // otherwise just take the incoming array because nothing previously existed |
|
248 | - : $dependencies; |
|
249 | - return $registered; |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param string $class_name |
|
256 | - * @param string $loader |
|
257 | - * @return bool |
|
258 | - * @throws DomainException |
|
259 | - */ |
|
260 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
261 | - { |
|
262 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
263 | - throw new DomainException( |
|
264 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
265 | - ); |
|
266 | - } |
|
267 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
268 | - if ( |
|
269 | - ! is_callable($loader) |
|
270 | - && ( |
|
271 | - strpos($loader, 'load_') !== 0 |
|
272 | - || ! method_exists('EE_Registry', $loader) |
|
273 | - ) |
|
274 | - ) { |
|
275 | - throw new DomainException( |
|
276 | - sprintf( |
|
277 | - esc_html__( |
|
278 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
279 | - 'event_espresso' |
|
280 | - ), |
|
281 | - $loader |
|
282 | - ) |
|
283 | - ); |
|
284 | - } |
|
285 | - $class_name = self::$_instance->getFqnForAlias($class_name); |
|
286 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
287 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
288 | - return true; |
|
289 | - } |
|
290 | - return false; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @return array |
|
297 | - */ |
|
298 | - public function dependency_map() |
|
299 | - { |
|
300 | - return $this->_dependency_map; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
307 | - * |
|
308 | - * @param string $class_name |
|
309 | - * @return boolean |
|
310 | - */ |
|
311 | - public function has($class_name = '') |
|
312 | - { |
|
313 | - // all legacy models have the same dependencies |
|
314 | - if (strpos($class_name, 'EEM_') === 0) { |
|
315 | - $class_name = 'LEGACY_MODELS'; |
|
316 | - } |
|
317 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
324 | - * |
|
325 | - * @param string $class_name |
|
326 | - * @param string $dependency |
|
327 | - * @return bool |
|
328 | - */ |
|
329 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
330 | - { |
|
331 | - // all legacy models have the same dependencies |
|
332 | - if (strpos($class_name, 'EEM_') === 0) { |
|
333 | - $class_name = 'LEGACY_MODELS'; |
|
334 | - } |
|
335 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
336 | - return isset($this->_dependency_map[$class_name][$dependency]) |
|
337 | - ? true |
|
338 | - : false; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
345 | - * |
|
346 | - * @param string $class_name |
|
347 | - * @param string $dependency |
|
348 | - * @return int |
|
349 | - */ |
|
350 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
351 | - { |
|
352 | - // all legacy models have the same dependencies |
|
353 | - if (strpos($class_name, 'EEM_') === 0) { |
|
354 | - $class_name = 'LEGACY_MODELS'; |
|
355 | - } |
|
356 | - $dependency = $this->getFqnForAlias($dependency); |
|
357 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
358 | - ? $this->_dependency_map[$class_name][$dependency] |
|
359 | - : EE_Dependency_Map::not_registered; |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * @param string $class_name |
|
366 | - * @return string | Closure |
|
367 | - */ |
|
368 | - public function class_loader($class_name) |
|
369 | - { |
|
370 | - // all legacy models use load_model() |
|
371 | - if(strpos($class_name, 'EEM_') === 0){ |
|
372 | - return 'load_model'; |
|
373 | - } |
|
374 | - $class_name = $this->getFqnForAlias($class_name); |
|
375 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * @return array |
|
382 | - */ |
|
383 | - public function class_loaders() |
|
384 | - { |
|
385 | - return $this->_class_loaders; |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * adds an alias for a classname |
|
392 | - * |
|
393 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
394 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
395 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
396 | - */ |
|
397 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
398 | - { |
|
399 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
406 | - * WHY? |
|
407 | - * Because if a class is type hinting for a concretion, |
|
408 | - * then why would we need to find another class to supply it? |
|
409 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
410 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
411 | - * Don't go looking for some substitute. |
|
412 | - * Whereas if a class is type hinting for an interface... |
|
413 | - * then we need to find an actual class to use. |
|
414 | - * So the interface IS the alias for some other FQN, |
|
415 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
416 | - * represents some other class. |
|
417 | - * |
|
418 | - * @param string $fqn |
|
419 | - * @param string $for_class |
|
420 | - * @return bool |
|
421 | - */ |
|
422 | - public function isAlias($fqn = '', $for_class = '') |
|
423 | - { |
|
424 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
431 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
432 | - * for example: |
|
433 | - * if the following two entries were added to the _aliases array: |
|
434 | - * array( |
|
435 | - * 'interface_alias' => 'some\namespace\interface' |
|
436 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
437 | - * ) |
|
438 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
439 | - * to load an instance of 'some\namespace\classname' |
|
440 | - * |
|
441 | - * @param string $alias |
|
442 | - * @param string $for_class |
|
443 | - * @return string |
|
444 | - */ |
|
445 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
446 | - { |
|
447 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
454 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
455 | - * This is done by using the following class constants: |
|
456 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
457 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
458 | - */ |
|
459 | - protected function _register_core_dependencies() |
|
460 | - { |
|
461 | - $this->_dependency_map = array( |
|
462 | - 'EE_Request_Handler' => array( |
|
463 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
464 | - ), |
|
465 | - 'EE_System' => array( |
|
466 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
468 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
469 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
470 | - ), |
|
471 | - 'EE_Session' => array( |
|
472 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
473 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
474 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
475 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
476 | - ), |
|
477 | - 'EE_Cart' => array( |
|
478 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
479 | - ), |
|
480 | - 'EE_Front_Controller' => array( |
|
481 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
482 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
483 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
484 | - ), |
|
485 | - 'EE_Messenger_Collection_Loader' => array( |
|
486 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
487 | - ), |
|
488 | - 'EE_Message_Type_Collection_Loader' => array( |
|
489 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | - ), |
|
491 | - 'EE_Message_Resource_Manager' => array( |
|
492 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
493 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
494 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
495 | - ), |
|
496 | - 'EE_Message_Factory' => array( |
|
497 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
498 | - ), |
|
499 | - 'EE_messages' => array( |
|
500 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
501 | - ), |
|
502 | - 'EE_Messages_Generator' => array( |
|
503 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
504 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
505 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
506 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
507 | - ), |
|
508 | - 'EE_Messages_Processor' => array( |
|
509 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
510 | - ), |
|
511 | - 'EE_Messages_Queue' => array( |
|
512 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
513 | - ), |
|
514 | - 'EE_Messages_Template_Defaults' => array( |
|
515 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
516 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
517 | - ), |
|
518 | - 'EE_Message_To_Generate_From_Request' => array( |
|
519 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
520 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
521 | - ), |
|
522 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
523 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
524 | - ), |
|
525 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
526 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
527 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
528 | - ), |
|
529 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
530 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
531 | - ), |
|
532 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
533 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
534 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
535 | - ), |
|
536 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
537 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
538 | - ), |
|
539 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
540 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
541 | - ), |
|
542 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
543 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
546 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
547 | - ), |
|
548 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
549 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
550 | - ), |
|
551 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
552 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
553 | - ), |
|
554 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
555 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
558 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
559 | - ), |
|
560 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
561 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
562 | - ), |
|
563 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
564 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
565 | - ), |
|
566 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
567 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
568 | - ), |
|
569 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
570 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
571 | - ), |
|
572 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
573 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
574 | - ), |
|
575 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
576 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | - ), |
|
578 | - 'EE_Data_Migration_Class_Base' => array( |
|
579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | - ), |
|
582 | - 'EE_DMS_Core_4_1_0' => array( |
|
583 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | - ), |
|
586 | - 'EE_DMS_Core_4_2_0' => array( |
|
587 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | - ), |
|
590 | - 'EE_DMS_Core_4_3_0' => array( |
|
591 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | - ), |
|
594 | - 'EE_DMS_Core_4_4_0' => array( |
|
595 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
596 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
597 | - ), |
|
598 | - 'EE_DMS_Core_4_5_0' => array( |
|
599 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
600 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
601 | - ), |
|
602 | - 'EE_DMS_Core_4_6_0' => array( |
|
603 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
604 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
605 | - ), |
|
606 | - 'EE_DMS_Core_4_7_0' => array( |
|
607 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
608 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
609 | - ), |
|
610 | - 'EE_DMS_Core_4_8_0' => array( |
|
611 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
612 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
613 | - ), |
|
614 | - 'EE_DMS_Core_4_9_0' => array( |
|
615 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
616 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
617 | - ), |
|
618 | - 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
619 | - array(), |
|
620 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
621 | - ), |
|
622 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
623 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
624 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
625 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
626 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
627 | - ), |
|
628 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
629 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | - ), |
|
631 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
632 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | - ), |
|
634 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
635 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | - ), |
|
637 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
638 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
639 | - ), |
|
640 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
641 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
642 | - ), |
|
643 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
644 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
645 | - ), |
|
646 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
647 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
648 | - ), |
|
649 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
650 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
651 | - ), |
|
652 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
653 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
654 | - ), |
|
655 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
656 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
657 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
658 | - ), |
|
659 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
660 | - null, |
|
661 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
662 | - ), |
|
663 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
664 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
665 | - ), |
|
666 | - 'LEGACY_MODELS' => array( |
|
667 | - null, |
|
668 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
669 | - ), |
|
670 | - 'EE_Module_Request_Router' => array( |
|
671 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
672 | - ), |
|
673 | - 'EE_Registration_Processor' => array( |
|
674 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
675 | - ), |
|
676 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
677 | - null, |
|
678 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
679 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
680 | - ), |
|
681 | - 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
682 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
683 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache |
|
684 | - ), |
|
29 | + /** |
|
30 | + * This means that the requested class dependency is not present in the dependency map |
|
31 | + */ |
|
32 | + const not_registered = 0; |
|
33 | + |
|
34 | + /** |
|
35 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
36 | + */ |
|
37 | + const load_new_object = 1; |
|
38 | + |
|
39 | + /** |
|
40 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
41 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
42 | + */ |
|
43 | + const load_from_cache = 2; |
|
44 | + |
|
45 | + /** |
|
46 | + * When registering a dependency, |
|
47 | + * this indicates to keep any existing dependencies that already exist, |
|
48 | + * and simply discard any new dependencies declared in the incoming data |
|
49 | + */ |
|
50 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
51 | + |
|
52 | + /** |
|
53 | + * When registering a dependency, |
|
54 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
55 | + */ |
|
56 | + const OVERWRITE_DEPENDENCIES = 1; |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @type EE_Dependency_Map $_instance |
|
62 | + */ |
|
63 | + protected static $_instance; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var ClassInterfaceCache $class_cache |
|
67 | + */ |
|
68 | + private $class_cache; |
|
69 | + |
|
70 | + /** |
|
71 | + * @type RequestInterface $request |
|
72 | + */ |
|
73 | + protected $request; |
|
74 | + |
|
75 | + /** |
|
76 | + * @type LegacyRequestInterface $legacy_request |
|
77 | + */ |
|
78 | + protected $legacy_request; |
|
79 | + |
|
80 | + /** |
|
81 | + * @type ResponseInterface $response |
|
82 | + */ |
|
83 | + protected $response; |
|
84 | + |
|
85 | + /** |
|
86 | + * @type LoaderInterface $loader |
|
87 | + */ |
|
88 | + protected $loader; |
|
89 | + |
|
90 | + /** |
|
91 | + * @type array $_dependency_map |
|
92 | + */ |
|
93 | + protected $_dependency_map = array(); |
|
94 | + |
|
95 | + /** |
|
96 | + * @type array $_class_loaders |
|
97 | + */ |
|
98 | + protected $_class_loaders = array(); |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * EE_Dependency_Map constructor. |
|
103 | + * |
|
104 | + * @param ClassInterfaceCache $class_cache |
|
105 | + */ |
|
106 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
107 | + { |
|
108 | + $this->class_cache = $class_cache; |
|
109 | + do_action('EE_Dependency_Map____construct', $this); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + public function initialize() |
|
117 | + { |
|
118 | + $this->_register_core_dependencies(); |
|
119 | + $this->_register_core_class_loaders(); |
|
120 | + $this->_register_core_aliases(); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @singleton method used to instantiate class object |
|
126 | + * @param ClassInterfaceCache|null $class_cache |
|
127 | + * @return EE_Dependency_Map |
|
128 | + */ |
|
129 | + public static function instance(ClassInterfaceCache $class_cache = null) { |
|
130 | + // check if class object is instantiated, and instantiated properly |
|
131 | + if ( |
|
132 | + ! self::$_instance instanceof EE_Dependency_Map |
|
133 | + && $class_cache instanceof ClassInterfaceCache |
|
134 | + ) { |
|
135 | + self::$_instance = new EE_Dependency_Map($class_cache); |
|
136 | + } |
|
137 | + return self::$_instance; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param RequestInterface $request |
|
143 | + */ |
|
144 | + public function setRequest(RequestInterface $request) |
|
145 | + { |
|
146 | + $this->request = $request; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param LegacyRequestInterface $legacy_request |
|
152 | + */ |
|
153 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
154 | + { |
|
155 | + $this->legacy_request = $legacy_request; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @param ResponseInterface $response |
|
161 | + */ |
|
162 | + public function setResponse(ResponseInterface $response) |
|
163 | + { |
|
164 | + $this->response = $response; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param LoaderInterface $loader |
|
171 | + */ |
|
172 | + public function setLoader(LoaderInterface $loader) |
|
173 | + { |
|
174 | + $this->loader = $loader; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @param string $class |
|
181 | + * @param array $dependencies |
|
182 | + * @param int $overwrite |
|
183 | + * @return bool |
|
184 | + */ |
|
185 | + public static function register_dependencies( |
|
186 | + $class, |
|
187 | + array $dependencies, |
|
188 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
189 | + ) { |
|
190 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
197 | + * to the class specified by the first parameter. |
|
198 | + * IMPORTANT !!! |
|
199 | + * The order of elements in the incoming $dependencies array MUST match |
|
200 | + * the order of the constructor parameters for the class in question. |
|
201 | + * This is especially important when overriding any existing dependencies that are registered. |
|
202 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
203 | + * |
|
204 | + * @param string $class |
|
205 | + * @param array $dependencies |
|
206 | + * @param int $overwrite |
|
207 | + * @return bool |
|
208 | + */ |
|
209 | + public function registerDependencies( |
|
210 | + $class, |
|
211 | + array $dependencies, |
|
212 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
213 | + ) { |
|
214 | + $class = trim($class, '\\'); |
|
215 | + $registered = false; |
|
216 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
217 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
218 | + } |
|
219 | + // we need to make sure that any aliases used when registering a dependency |
|
220 | + // get resolved to the correct class name |
|
221 | + foreach ($dependencies as $dependency => $load_source) { |
|
222 | + $alias = self::$_instance->getFqnForAlias($dependency); |
|
223 | + if ( |
|
224 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
225 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
226 | + ) { |
|
227 | + unset($dependencies[$dependency]); |
|
228 | + $dependencies[$alias] = $load_source; |
|
229 | + $registered = true; |
|
230 | + } |
|
231 | + } |
|
232 | + // now add our two lists of dependencies together. |
|
233 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
234 | + // so $dependencies is NOT overwritten because it is listed first |
|
235 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
236 | + // Union is way faster than array_merge() but should be used with caution... |
|
237 | + // especially with numerically indexed arrays |
|
238 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
239 | + // now we need to ensure that the resulting dependencies |
|
240 | + // array only has the entries that are required for the class |
|
241 | + // so first count how many dependencies were originally registered for the class |
|
242 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
243 | + // if that count is non-zero (meaning dependencies were already registered) |
|
244 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
245 | + // then truncate the final array to match that count |
|
246 | + ? array_slice($dependencies, 0, $dependency_count) |
|
247 | + // otherwise just take the incoming array because nothing previously existed |
|
248 | + : $dependencies; |
|
249 | + return $registered; |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param string $class_name |
|
256 | + * @param string $loader |
|
257 | + * @return bool |
|
258 | + * @throws DomainException |
|
259 | + */ |
|
260 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
261 | + { |
|
262 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
263 | + throw new DomainException( |
|
264 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
265 | + ); |
|
266 | + } |
|
267 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
268 | + if ( |
|
269 | + ! is_callable($loader) |
|
270 | + && ( |
|
271 | + strpos($loader, 'load_') !== 0 |
|
272 | + || ! method_exists('EE_Registry', $loader) |
|
273 | + ) |
|
274 | + ) { |
|
275 | + throw new DomainException( |
|
276 | + sprintf( |
|
277 | + esc_html__( |
|
278 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
279 | + 'event_espresso' |
|
280 | + ), |
|
281 | + $loader |
|
282 | + ) |
|
283 | + ); |
|
284 | + } |
|
285 | + $class_name = self::$_instance->getFqnForAlias($class_name); |
|
286 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
287 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
288 | + return true; |
|
289 | + } |
|
290 | + return false; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @return array |
|
297 | + */ |
|
298 | + public function dependency_map() |
|
299 | + { |
|
300 | + return $this->_dependency_map; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
307 | + * |
|
308 | + * @param string $class_name |
|
309 | + * @return boolean |
|
310 | + */ |
|
311 | + public function has($class_name = '') |
|
312 | + { |
|
313 | + // all legacy models have the same dependencies |
|
314 | + if (strpos($class_name, 'EEM_') === 0) { |
|
315 | + $class_name = 'LEGACY_MODELS'; |
|
316 | + } |
|
317 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
324 | + * |
|
325 | + * @param string $class_name |
|
326 | + * @param string $dependency |
|
327 | + * @return bool |
|
328 | + */ |
|
329 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
330 | + { |
|
331 | + // all legacy models have the same dependencies |
|
332 | + if (strpos($class_name, 'EEM_') === 0) { |
|
333 | + $class_name = 'LEGACY_MODELS'; |
|
334 | + } |
|
335 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
336 | + return isset($this->_dependency_map[$class_name][$dependency]) |
|
337 | + ? true |
|
338 | + : false; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
345 | + * |
|
346 | + * @param string $class_name |
|
347 | + * @param string $dependency |
|
348 | + * @return int |
|
349 | + */ |
|
350 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
351 | + { |
|
352 | + // all legacy models have the same dependencies |
|
353 | + if (strpos($class_name, 'EEM_') === 0) { |
|
354 | + $class_name = 'LEGACY_MODELS'; |
|
355 | + } |
|
356 | + $dependency = $this->getFqnForAlias($dependency); |
|
357 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
358 | + ? $this->_dependency_map[$class_name][$dependency] |
|
359 | + : EE_Dependency_Map::not_registered; |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * @param string $class_name |
|
366 | + * @return string | Closure |
|
367 | + */ |
|
368 | + public function class_loader($class_name) |
|
369 | + { |
|
370 | + // all legacy models use load_model() |
|
371 | + if(strpos($class_name, 'EEM_') === 0){ |
|
372 | + return 'load_model'; |
|
373 | + } |
|
374 | + $class_name = $this->getFqnForAlias($class_name); |
|
375 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * @return array |
|
382 | + */ |
|
383 | + public function class_loaders() |
|
384 | + { |
|
385 | + return $this->_class_loaders; |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * adds an alias for a classname |
|
392 | + * |
|
393 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
394 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
395 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
396 | + */ |
|
397 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
398 | + { |
|
399 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
406 | + * WHY? |
|
407 | + * Because if a class is type hinting for a concretion, |
|
408 | + * then why would we need to find another class to supply it? |
|
409 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
410 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
411 | + * Don't go looking for some substitute. |
|
412 | + * Whereas if a class is type hinting for an interface... |
|
413 | + * then we need to find an actual class to use. |
|
414 | + * So the interface IS the alias for some other FQN, |
|
415 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
416 | + * represents some other class. |
|
417 | + * |
|
418 | + * @param string $fqn |
|
419 | + * @param string $for_class |
|
420 | + * @return bool |
|
421 | + */ |
|
422 | + public function isAlias($fqn = '', $for_class = '') |
|
423 | + { |
|
424 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
431 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
432 | + * for example: |
|
433 | + * if the following two entries were added to the _aliases array: |
|
434 | + * array( |
|
435 | + * 'interface_alias' => 'some\namespace\interface' |
|
436 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
437 | + * ) |
|
438 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
439 | + * to load an instance of 'some\namespace\classname' |
|
440 | + * |
|
441 | + * @param string $alias |
|
442 | + * @param string $for_class |
|
443 | + * @return string |
|
444 | + */ |
|
445 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
446 | + { |
|
447 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
454 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
455 | + * This is done by using the following class constants: |
|
456 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
457 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
458 | + */ |
|
459 | + protected function _register_core_dependencies() |
|
460 | + { |
|
461 | + $this->_dependency_map = array( |
|
462 | + 'EE_Request_Handler' => array( |
|
463 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
464 | + ), |
|
465 | + 'EE_System' => array( |
|
466 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
468 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
469 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
470 | + ), |
|
471 | + 'EE_Session' => array( |
|
472 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
473 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
474 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
475 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
476 | + ), |
|
477 | + 'EE_Cart' => array( |
|
478 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
479 | + ), |
|
480 | + 'EE_Front_Controller' => array( |
|
481 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
482 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
483 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
484 | + ), |
|
485 | + 'EE_Messenger_Collection_Loader' => array( |
|
486 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
487 | + ), |
|
488 | + 'EE_Message_Type_Collection_Loader' => array( |
|
489 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | + ), |
|
491 | + 'EE_Message_Resource_Manager' => array( |
|
492 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
493 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
494 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
495 | + ), |
|
496 | + 'EE_Message_Factory' => array( |
|
497 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
498 | + ), |
|
499 | + 'EE_messages' => array( |
|
500 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
501 | + ), |
|
502 | + 'EE_Messages_Generator' => array( |
|
503 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
504 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
505 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
506 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
507 | + ), |
|
508 | + 'EE_Messages_Processor' => array( |
|
509 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
510 | + ), |
|
511 | + 'EE_Messages_Queue' => array( |
|
512 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
513 | + ), |
|
514 | + 'EE_Messages_Template_Defaults' => array( |
|
515 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
516 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
517 | + ), |
|
518 | + 'EE_Message_To_Generate_From_Request' => array( |
|
519 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
520 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
521 | + ), |
|
522 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
523 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
524 | + ), |
|
525 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
526 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
527 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
528 | + ), |
|
529 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
530 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
531 | + ), |
|
532 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
533 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
534 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
535 | + ), |
|
536 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
537 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
538 | + ), |
|
539 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
540 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
541 | + ), |
|
542 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
543 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
546 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
547 | + ), |
|
548 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
549 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
550 | + ), |
|
551 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
552 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
553 | + ), |
|
554 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
555 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
558 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
559 | + ), |
|
560 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
561 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
562 | + ), |
|
563 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
564 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
565 | + ), |
|
566 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
567 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
568 | + ), |
|
569 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
570 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
571 | + ), |
|
572 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
573 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
574 | + ), |
|
575 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
576 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | + ), |
|
578 | + 'EE_Data_Migration_Class_Base' => array( |
|
579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | + ), |
|
582 | + 'EE_DMS_Core_4_1_0' => array( |
|
583 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | + ), |
|
586 | + 'EE_DMS_Core_4_2_0' => array( |
|
587 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | + ), |
|
590 | + 'EE_DMS_Core_4_3_0' => array( |
|
591 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | + ), |
|
594 | + 'EE_DMS_Core_4_4_0' => array( |
|
595 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
596 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
597 | + ), |
|
598 | + 'EE_DMS_Core_4_5_0' => array( |
|
599 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
600 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
601 | + ), |
|
602 | + 'EE_DMS_Core_4_6_0' => array( |
|
603 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
604 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
605 | + ), |
|
606 | + 'EE_DMS_Core_4_7_0' => array( |
|
607 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
608 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
609 | + ), |
|
610 | + 'EE_DMS_Core_4_8_0' => array( |
|
611 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
612 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
613 | + ), |
|
614 | + 'EE_DMS_Core_4_9_0' => array( |
|
615 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
616 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
617 | + ), |
|
618 | + 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
619 | + array(), |
|
620 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
621 | + ), |
|
622 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
623 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
624 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
625 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
626 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
627 | + ), |
|
628 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
629 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | + ), |
|
631 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
632 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | + ), |
|
634 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
635 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | + ), |
|
637 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
638 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
639 | + ), |
|
640 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
641 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
642 | + ), |
|
643 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
644 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
645 | + ), |
|
646 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
647 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
648 | + ), |
|
649 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
650 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
651 | + ), |
|
652 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
653 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
654 | + ), |
|
655 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
656 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
657 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
658 | + ), |
|
659 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
660 | + null, |
|
661 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
662 | + ), |
|
663 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
664 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
665 | + ), |
|
666 | + 'LEGACY_MODELS' => array( |
|
667 | + null, |
|
668 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
669 | + ), |
|
670 | + 'EE_Module_Request_Router' => array( |
|
671 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
672 | + ), |
|
673 | + 'EE_Registration_Processor' => array( |
|
674 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
675 | + ), |
|
676 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
677 | + null, |
|
678 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
679 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
680 | + ), |
|
681 | + 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
682 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
683 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache |
|
684 | + ), |
|
685 | 685 | 'EE_Admin_Transactions_List_Table' => array( |
686 | - null, |
|
687 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
688 | - ), |
|
689 | - 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
690 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
691 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
692 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache |
|
693 | - ), |
|
694 | - 'EventEspresso\core\domain\services\pue\Config' => array( |
|
695 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
696 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
697 | - ), |
|
698 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
699 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
700 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
701 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
702 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
703 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
704 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
705 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
706 | - ), |
|
707 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
708 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
709 | - ), |
|
710 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
711 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
712 | - ), |
|
713 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
714 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
715 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
716 | - ), |
|
717 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
718 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
719 | - ), |
|
720 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
721 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
722 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
723 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
724 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
725 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
726 | - ), |
|
727 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
728 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
729 | - ), |
|
730 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
731 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
732 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
733 | - ), |
|
734 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
735 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
736 | - ), |
|
737 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
738 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
739 | - ), |
|
740 | - 'EE_CPT_Strategy' => array( |
|
741 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
742 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
743 | - ), |
|
744 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
745 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
746 | - ), |
|
747 | - ); |
|
748 | - } |
|
749 | - |
|
750 | - |
|
751 | - /** |
|
752 | - * Registers how core classes are loaded. |
|
753 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
754 | - * 'EE_Request_Handler' => 'load_core' |
|
755 | - * 'EE_Messages_Queue' => 'load_lib' |
|
756 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
757 | - * or, if greater control is required, by providing a custom closure. For example: |
|
758 | - * 'Some_Class' => function () { |
|
759 | - * return new Some_Class(); |
|
760 | - * }, |
|
761 | - * This is required for instantiating dependencies |
|
762 | - * where an interface has been type hinted in a class constructor. For example: |
|
763 | - * 'Required_Interface' => function () { |
|
764 | - * return new A_Class_That_Implements_Required_Interface(); |
|
765 | - * }, |
|
766 | - * |
|
767 | - */ |
|
768 | - protected function _register_core_class_loaders() |
|
769 | - { |
|
770 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
771 | - //be used in a closure. |
|
772 | - $request = &$this->request; |
|
773 | - $response = &$this->response; |
|
774 | - $legacy_request = &$this->legacy_request; |
|
775 | - // $loader = &$this->loader; |
|
776 | - $this->_class_loaders = array( |
|
777 | - //load_core |
|
778 | - 'EE_Capabilities' => 'load_core', |
|
779 | - 'EE_Encryption' => 'load_core', |
|
780 | - 'EE_Front_Controller' => 'load_core', |
|
781 | - 'EE_Module_Request_Router' => 'load_core', |
|
782 | - 'EE_Registry' => 'load_core', |
|
783 | - 'EE_Request' => function () use (&$legacy_request) { |
|
784 | - return $legacy_request; |
|
785 | - }, |
|
786 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
787 | - return $request; |
|
788 | - }, |
|
789 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
790 | - return $response; |
|
791 | - }, |
|
792 | - 'EE_Base' => 'load_core', |
|
793 | - 'EE_Request_Handler' => 'load_core', |
|
794 | - 'EE_Session' => 'load_core', |
|
795 | - 'EE_Cron_Tasks' => 'load_core', |
|
796 | - 'EE_System' => 'load_core', |
|
797 | - 'EE_Maintenance_Mode' => 'load_core', |
|
798 | - 'EE_Register_CPTs' => 'load_core', |
|
799 | - 'EE_Admin' => 'load_core', |
|
800 | - 'EE_CPT_Strategy' => 'load_core', |
|
801 | - //load_lib |
|
802 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
803 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
804 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
805 | - 'EE_Messenger_Collection' => 'load_lib', |
|
806 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
807 | - 'EE_Messages_Processor' => 'load_lib', |
|
808 | - 'EE_Message_Repository' => 'load_lib', |
|
809 | - 'EE_Messages_Queue' => 'load_lib', |
|
810 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
811 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
812 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
813 | - 'EE_Messages_Generator' => function () { |
|
814 | - return EE_Registry::instance()->load_lib( |
|
815 | - 'Messages_Generator', |
|
816 | - array(), |
|
817 | - false, |
|
818 | - false |
|
819 | - ); |
|
820 | - }, |
|
821 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
822 | - return EE_Registry::instance()->load_lib( |
|
823 | - 'Messages_Template_Defaults', |
|
824 | - $arguments, |
|
825 | - false, |
|
826 | - false |
|
827 | - ); |
|
828 | - }, |
|
829 | - //load_helper |
|
830 | - 'EEH_Parse_Shortcodes' => function () { |
|
831 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
832 | - return new EEH_Parse_Shortcodes(); |
|
833 | - } |
|
834 | - return null; |
|
835 | - }, |
|
836 | - 'EE_Template_Config' => function () { |
|
837 | - return EE_Config::instance()->template_settings; |
|
838 | - }, |
|
839 | - 'EE_Currency_Config' => function () { |
|
840 | - return EE_Config::instance()->currency; |
|
841 | - }, |
|
842 | - 'EE_Registration_Config' => function () { |
|
843 | - return EE_Config::instance()->registration; |
|
844 | - }, |
|
845 | - 'EE_Core_Config' => function () { |
|
846 | - return EE_Config::instance()->core; |
|
847 | - }, |
|
848 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
849 | - return LoaderFactory::getLoader(); |
|
850 | - }, |
|
851 | - 'EE_Network_Config' => function() { |
|
852 | - return EE_Network_Config::instance(); |
|
853 | - }, |
|
854 | - 'EE_Config' => function () { |
|
855 | - return EE_Config::instance(); |
|
856 | - }, |
|
857 | - 'EventEspresso\core\domain\Domain' => function () { |
|
858 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
859 | - }, |
|
860 | - ); |
|
861 | - } |
|
862 | - |
|
863 | - |
|
864 | - |
|
865 | - |
|
866 | - /** |
|
867 | - * can be used for supplying alternate names for classes, |
|
868 | - * or for connecting interface names to instantiable classes |
|
869 | - */ |
|
870 | - protected function _register_core_aliases() |
|
871 | - { |
|
872 | - $aliases = array( |
|
873 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
874 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
875 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
876 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
877 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
878 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
879 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
880 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
881 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
882 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
883 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
884 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
885 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
886 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
887 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
888 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
889 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
890 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
891 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
892 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
893 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
894 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
895 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
896 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
897 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
898 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
899 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
900 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
901 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
902 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
903 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
904 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
905 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
906 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
907 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
908 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
909 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
910 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
911 | - ); |
|
912 | - foreach ($aliases as $alias => $fqn) { |
|
913 | - if(is_array($fqn)) { |
|
914 | - foreach ($fqn as $class => $for_class) { |
|
915 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
916 | - } |
|
917 | - continue; |
|
918 | - } |
|
919 | - $this->class_cache->addAlias($fqn, $alias); |
|
920 | - } |
|
921 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
922 | - $this->class_cache->addAlias( |
|
923 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
924 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
925 | - ); |
|
926 | - } |
|
927 | - } |
|
928 | - |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
933 | - * request Primarily used by unit tests. |
|
934 | - */ |
|
935 | - public function reset() |
|
936 | - { |
|
937 | - $this->_register_core_class_loaders(); |
|
938 | - $this->_register_core_dependencies(); |
|
939 | - } |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
944 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
945 | - * WHY? |
|
946 | - * Because if a class is type hinting for a concretion, |
|
947 | - * then why would we need to find another class to supply it? |
|
948 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
949 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
950 | - * Don't go looking for some substitute. |
|
951 | - * Whereas if a class is type hinting for an interface... |
|
952 | - * then we need to find an actual class to use. |
|
953 | - * So the interface IS the alias for some other FQN, |
|
954 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
955 | - * represents some other class. |
|
956 | - * |
|
957 | - * @deprecated $VID:$ |
|
958 | - * @param string $fqn |
|
959 | - * @param string $for_class |
|
960 | - * @return bool |
|
961 | - */ |
|
962 | - public function has_alias($fqn = '', $for_class = '') |
|
963 | - { |
|
964 | - return $this->isAlias($fqn, $for_class); |
|
965 | - } |
|
966 | - |
|
967 | - |
|
968 | - /** |
|
969 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
970 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
971 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
972 | - * for example: |
|
973 | - * if the following two entries were added to the _aliases array: |
|
974 | - * array( |
|
975 | - * 'interface_alias' => 'some\namespace\interface' |
|
976 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
977 | - * ) |
|
978 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
979 | - * to load an instance of 'some\namespace\classname' |
|
980 | - * |
|
981 | - * @deprecated $VID:$ |
|
982 | - * @param string $alias |
|
983 | - * @param string $for_class |
|
984 | - * @return string |
|
985 | - */ |
|
986 | - public function get_alias($alias = '', $for_class = '') |
|
987 | - { |
|
988 | - return $this->getFqnForAlias($alias, $for_class); |
|
989 | - } |
|
686 | + null, |
|
687 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
688 | + ), |
|
689 | + 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
690 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
691 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
692 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache |
|
693 | + ), |
|
694 | + 'EventEspresso\core\domain\services\pue\Config' => array( |
|
695 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
696 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
697 | + ), |
|
698 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
699 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
700 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
701 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
702 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
703 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
704 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
705 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
706 | + ), |
|
707 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
708 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
709 | + ), |
|
710 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
711 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
712 | + ), |
|
713 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
714 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
715 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
716 | + ), |
|
717 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
718 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
719 | + ), |
|
720 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
721 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
722 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
723 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
724 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
725 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
726 | + ), |
|
727 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
728 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
729 | + ), |
|
730 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
731 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
732 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
733 | + ), |
|
734 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
735 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
736 | + ), |
|
737 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
738 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
739 | + ), |
|
740 | + 'EE_CPT_Strategy' => array( |
|
741 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
742 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
743 | + ), |
|
744 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
745 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
746 | + ), |
|
747 | + ); |
|
748 | + } |
|
749 | + |
|
750 | + |
|
751 | + /** |
|
752 | + * Registers how core classes are loaded. |
|
753 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
754 | + * 'EE_Request_Handler' => 'load_core' |
|
755 | + * 'EE_Messages_Queue' => 'load_lib' |
|
756 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
757 | + * or, if greater control is required, by providing a custom closure. For example: |
|
758 | + * 'Some_Class' => function () { |
|
759 | + * return new Some_Class(); |
|
760 | + * }, |
|
761 | + * This is required for instantiating dependencies |
|
762 | + * where an interface has been type hinted in a class constructor. For example: |
|
763 | + * 'Required_Interface' => function () { |
|
764 | + * return new A_Class_That_Implements_Required_Interface(); |
|
765 | + * }, |
|
766 | + * |
|
767 | + */ |
|
768 | + protected function _register_core_class_loaders() |
|
769 | + { |
|
770 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
771 | + //be used in a closure. |
|
772 | + $request = &$this->request; |
|
773 | + $response = &$this->response; |
|
774 | + $legacy_request = &$this->legacy_request; |
|
775 | + // $loader = &$this->loader; |
|
776 | + $this->_class_loaders = array( |
|
777 | + //load_core |
|
778 | + 'EE_Capabilities' => 'load_core', |
|
779 | + 'EE_Encryption' => 'load_core', |
|
780 | + 'EE_Front_Controller' => 'load_core', |
|
781 | + 'EE_Module_Request_Router' => 'load_core', |
|
782 | + 'EE_Registry' => 'load_core', |
|
783 | + 'EE_Request' => function () use (&$legacy_request) { |
|
784 | + return $legacy_request; |
|
785 | + }, |
|
786 | + 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
787 | + return $request; |
|
788 | + }, |
|
789 | + 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
790 | + return $response; |
|
791 | + }, |
|
792 | + 'EE_Base' => 'load_core', |
|
793 | + 'EE_Request_Handler' => 'load_core', |
|
794 | + 'EE_Session' => 'load_core', |
|
795 | + 'EE_Cron_Tasks' => 'load_core', |
|
796 | + 'EE_System' => 'load_core', |
|
797 | + 'EE_Maintenance_Mode' => 'load_core', |
|
798 | + 'EE_Register_CPTs' => 'load_core', |
|
799 | + 'EE_Admin' => 'load_core', |
|
800 | + 'EE_CPT_Strategy' => 'load_core', |
|
801 | + //load_lib |
|
802 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
803 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
804 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
805 | + 'EE_Messenger_Collection' => 'load_lib', |
|
806 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
807 | + 'EE_Messages_Processor' => 'load_lib', |
|
808 | + 'EE_Message_Repository' => 'load_lib', |
|
809 | + 'EE_Messages_Queue' => 'load_lib', |
|
810 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
811 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
812 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
813 | + 'EE_Messages_Generator' => function () { |
|
814 | + return EE_Registry::instance()->load_lib( |
|
815 | + 'Messages_Generator', |
|
816 | + array(), |
|
817 | + false, |
|
818 | + false |
|
819 | + ); |
|
820 | + }, |
|
821 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
822 | + return EE_Registry::instance()->load_lib( |
|
823 | + 'Messages_Template_Defaults', |
|
824 | + $arguments, |
|
825 | + false, |
|
826 | + false |
|
827 | + ); |
|
828 | + }, |
|
829 | + //load_helper |
|
830 | + 'EEH_Parse_Shortcodes' => function () { |
|
831 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
832 | + return new EEH_Parse_Shortcodes(); |
|
833 | + } |
|
834 | + return null; |
|
835 | + }, |
|
836 | + 'EE_Template_Config' => function () { |
|
837 | + return EE_Config::instance()->template_settings; |
|
838 | + }, |
|
839 | + 'EE_Currency_Config' => function () { |
|
840 | + return EE_Config::instance()->currency; |
|
841 | + }, |
|
842 | + 'EE_Registration_Config' => function () { |
|
843 | + return EE_Config::instance()->registration; |
|
844 | + }, |
|
845 | + 'EE_Core_Config' => function () { |
|
846 | + return EE_Config::instance()->core; |
|
847 | + }, |
|
848 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
849 | + return LoaderFactory::getLoader(); |
|
850 | + }, |
|
851 | + 'EE_Network_Config' => function() { |
|
852 | + return EE_Network_Config::instance(); |
|
853 | + }, |
|
854 | + 'EE_Config' => function () { |
|
855 | + return EE_Config::instance(); |
|
856 | + }, |
|
857 | + 'EventEspresso\core\domain\Domain' => function () { |
|
858 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
859 | + }, |
|
860 | + ); |
|
861 | + } |
|
862 | + |
|
863 | + |
|
864 | + |
|
865 | + |
|
866 | + /** |
|
867 | + * can be used for supplying alternate names for classes, |
|
868 | + * or for connecting interface names to instantiable classes |
|
869 | + */ |
|
870 | + protected function _register_core_aliases() |
|
871 | + { |
|
872 | + $aliases = array( |
|
873 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
874 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
875 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
876 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
877 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
878 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
879 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
880 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
881 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
882 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
883 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
884 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
885 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
886 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
887 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
888 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
889 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
890 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
891 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
892 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
893 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
894 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
895 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
896 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
897 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
898 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
899 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
900 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
901 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
902 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
903 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
904 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
905 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
906 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
907 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
908 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
909 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
910 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
911 | + ); |
|
912 | + foreach ($aliases as $alias => $fqn) { |
|
913 | + if(is_array($fqn)) { |
|
914 | + foreach ($fqn as $class => $for_class) { |
|
915 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
916 | + } |
|
917 | + continue; |
|
918 | + } |
|
919 | + $this->class_cache->addAlias($fqn, $alias); |
|
920 | + } |
|
921 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
922 | + $this->class_cache->addAlias( |
|
923 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
924 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
925 | + ); |
|
926 | + } |
|
927 | + } |
|
928 | + |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
933 | + * request Primarily used by unit tests. |
|
934 | + */ |
|
935 | + public function reset() |
|
936 | + { |
|
937 | + $this->_register_core_class_loaders(); |
|
938 | + $this->_register_core_dependencies(); |
|
939 | + } |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
944 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
945 | + * WHY? |
|
946 | + * Because if a class is type hinting for a concretion, |
|
947 | + * then why would we need to find another class to supply it? |
|
948 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
949 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
950 | + * Don't go looking for some substitute. |
|
951 | + * Whereas if a class is type hinting for an interface... |
|
952 | + * then we need to find an actual class to use. |
|
953 | + * So the interface IS the alias for some other FQN, |
|
954 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
955 | + * represents some other class. |
|
956 | + * |
|
957 | + * @deprecated $VID:$ |
|
958 | + * @param string $fqn |
|
959 | + * @param string $for_class |
|
960 | + * @return bool |
|
961 | + */ |
|
962 | + public function has_alias($fqn = '', $for_class = '') |
|
963 | + { |
|
964 | + return $this->isAlias($fqn, $for_class); |
|
965 | + } |
|
966 | + |
|
967 | + |
|
968 | + /** |
|
969 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
970 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
971 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
972 | + * for example: |
|
973 | + * if the following two entries were added to the _aliases array: |
|
974 | + * array( |
|
975 | + * 'interface_alias' => 'some\namespace\interface' |
|
976 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
977 | + * ) |
|
978 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
979 | + * to load an instance of 'some\namespace\classname' |
|
980 | + * |
|
981 | + * @deprecated $VID:$ |
|
982 | + * @param string $alias |
|
983 | + * @param string $for_class |
|
984 | + * @return string |
|
985 | + */ |
|
986 | + public function get_alias($alias = '', $for_class = '') |
|
987 | + { |
|
988 | + return $this->getFqnForAlias($alias, $for_class); |
|
989 | + } |
|
990 | 990 | } |
991 | 991 | // End of file EE_Dependency_Map.core.php |
992 | 992 | // Location: /EE_Dependency_Map.core.php |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -17,664 +17,664 @@ discard block |
||
17 | 17 | class EEH_Debug_Tools |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * instance of the EEH_Autoloader object |
|
22 | - * |
|
23 | - * @var $_instance |
|
24 | - * @access private |
|
25 | - */ |
|
26 | - private static $_instance; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $_memory_usage_points = array(); |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @access public |
|
38 | - * @return EEH_Debug_Tools |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated, and instantiated properly |
|
43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - return self::$_instance; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * private class constructor |
|
53 | - */ |
|
54 | - private function __construct() |
|
55 | - { |
|
56 | - // load Kint PHP debugging library |
|
57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
58 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
59 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
60 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
61 | - // so we've moved it to our test folder so that it is not included with production releases |
|
62 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
64 | - } |
|
65 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
66 | - //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
67 | - // } |
|
68 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
69 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
71 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * show_db_name |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public static function show_db_name() |
|
82 | - { |
|
83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
85 | - . DB_NAME |
|
86 | - . '</p>'; |
|
87 | - } |
|
88 | - if (EE_DEBUG) { |
|
89 | - Benchmark::displayResults(); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * dump EE_Session object at bottom of page after everything else has happened |
|
97 | - * |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public function espresso_session_footer_dump() |
|
101 | - { |
|
102 | - if ( |
|
103 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
104 | - && ! defined('DOING_AJAX') |
|
105 | - && class_exists('Kint') |
|
106 | - && function_exists('wp_get_current_user') |
|
107 | - && current_user_can('update_core') |
|
108 | - && class_exists('EE_Registry') |
|
109 | - ) { |
|
110 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
111 | - Kint::dump(EE_Registry::instance()->SSN); |
|
112 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
113 | - $this->espresso_list_hooked_functions(); |
|
114 | - Benchmark::displayResults(); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * List All Hooked Functions |
|
122 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
123 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
124 | - * |
|
125 | - * @param string $tag |
|
126 | - * @return void |
|
127 | - */ |
|
128 | - public function espresso_list_hooked_functions($tag = '') |
|
129 | - { |
|
130 | - global $wp_filter; |
|
131 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
132 | - if ($tag) { |
|
133 | - $hook[$tag] = $wp_filter[$tag]; |
|
134 | - if (! is_array($hook[$tag])) { |
|
135 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
136 | - return; |
|
137 | - } |
|
138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
139 | - } else { |
|
140 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
141 | - ksort($hook); |
|
142 | - } |
|
143 | - foreach ($hook as $tag_name => $priorities) { |
|
144 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
145 | - ksort($priorities); |
|
146 | - foreach ($priorities as $priority => $function) { |
|
147 | - echo $priority; |
|
148 | - foreach ($function as $name => $properties) { |
|
149 | - echo "\t$name<br />"; |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * registered_filter_callbacks |
|
159 | - * |
|
160 | - * @param string $hook_name |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public static function registered_filter_callbacks($hook_name = '') |
|
164 | - { |
|
165 | - $filters = array(); |
|
166 | - global $wp_filter; |
|
167 | - if (isset($wp_filter[$hook_name])) { |
|
168 | - $filters[$hook_name] = array(); |
|
169 | - foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | - $filters[$hook_name][$priority] = array(); |
|
171 | - foreach ($callbacks as $callback) { |
|
172 | - $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - return $filters; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * captures plugin activation errors for debugging |
|
183 | - * |
|
184 | - * @return void |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public static function ee_plugin_activation_errors() |
|
188 | - { |
|
189 | - if (WP_DEBUG) { |
|
190 | - $activation_errors = ob_get_contents(); |
|
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | - } |
|
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | - if (class_exists('EEH_File')) { |
|
196 | - try { |
|
197 | - EEH_File::ensure_file_exists_and_is_writable( |
|
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
199 | - ); |
|
200 | - EEH_File::write_to_file( |
|
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
202 | - $activation_errors |
|
203 | - ); |
|
204 | - } catch (EE_Error $e) { |
|
205 | - EE_Error::add_error( |
|
206 | - sprintf( |
|
207 | - __( |
|
208 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | - 'event_espresso' |
|
210 | - ), |
|
211 | - $e->getMessage() |
|
212 | - ), |
|
213 | - __FILE__, __FUNCTION__, __LINE__ |
|
214 | - ); |
|
215 | - } |
|
216 | - } else { |
|
217 | - // old school attempt |
|
218 | - file_put_contents( |
|
219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
220 | - $activation_errors |
|
221 | - ); |
|
222 | - } |
|
223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
224 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
232 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
233 | - * or we want to make sure they use something the right way. |
|
234 | - * |
|
235 | - * @access public |
|
236 | - * @param string $function The function that was called |
|
237 | - * @param string $message A message explaining what has been done incorrectly |
|
238 | - * @param string $version The version of Event Espresso where the error was added |
|
239 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
240 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
241 | - * but not have any notices appear until a later version. This allows developers |
|
242 | - * extra time to update their code before notices appear. |
|
243 | - * @param int $error_type |
|
244 | - * @uses trigger_error() |
|
245 | - */ |
|
246 | - public function doing_it_wrong( |
|
247 | - $function, |
|
248 | - $message, |
|
249 | - $version, |
|
250 | - $applies_when = '', |
|
251 | - $error_type = null |
|
252 | - ) { |
|
253 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
254 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
255 | - // because we swapped the parameter order around for the last two params, |
|
256 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
257 | - if (is_int($applies_when)) { |
|
258 | - $error_type = $applies_when; |
|
259 | - $applies_when = espresso_version(); |
|
260 | - } |
|
261 | - // if not displaying notices yet, then just leave |
|
262 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
263 | - return; |
|
264 | - } |
|
265 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
266 | - $version = $version === null |
|
267 | - ? '' |
|
268 | - : sprintf( |
|
269 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
270 | - $version |
|
271 | - ); |
|
272 | - $error_message = sprintf( |
|
273 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
274 | - $function, |
|
275 | - '<strong>', |
|
276 | - '</strong>', |
|
277 | - $message, |
|
278 | - $version |
|
279 | - ); |
|
280 | - // don't trigger error if doing ajax, |
|
281 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
282 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
283 | - $error_message .= ' ' . esc_html__( |
|
284 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
285 | - 'event_espresso' |
|
286 | - ); |
|
287 | - $error_message .= '<ul><li>'; |
|
288 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
289 | - $error_message .= '</ul>'; |
|
290 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
291 | - //now we set this on the transient so it shows up on the next request. |
|
292 | - EE_Error::get_notices(false, true); |
|
293 | - } else { |
|
294 | - trigger_error($error_message, $error_type); |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Logger helpers |
|
303 | - */ |
|
304 | - /** |
|
305 | - * debug |
|
306 | - * |
|
307 | - * @param string $class |
|
308 | - * @param string $func |
|
309 | - * @param string $line |
|
310 | - * @param array $info |
|
311 | - * @param bool $display_request |
|
312 | - * @param string $debug_index |
|
313 | - * @param string $debug_key |
|
314 | - * @throws EE_Error |
|
315 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
316 | - */ |
|
317 | - public static function log( |
|
318 | - $class = '', |
|
319 | - $func = '', |
|
320 | - $line = '', |
|
321 | - $info = array(), |
|
322 | - $display_request = false, |
|
323 | - $debug_index = '', |
|
324 | - $debug_key = 'EE_DEBUG_SPCO' |
|
325 | - ) { |
|
326 | - if (WP_DEBUG) { |
|
327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | - $debug_data = get_option($debug_key, array()); |
|
329 | - $default_data = array( |
|
330 | - $class => $func . '() : ' . $line, |
|
331 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
332 | - ); |
|
333 | - // don't serialize objects |
|
334 | - $info = self::strip_objects($info); |
|
335 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | - if (! isset($debug_data[$index])) { |
|
337 | - $debug_data[$index] = array(); |
|
338 | - } |
|
339 | - $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | - update_option($debug_key, $debug_data); |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * strip_objects |
|
348 | - * |
|
349 | - * @param array $info |
|
350 | - * @return array |
|
351 | - */ |
|
352 | - public static function strip_objects($info = array()) |
|
353 | - { |
|
354 | - foreach ($info as $key => $value) { |
|
355 | - if (is_array($value)) { |
|
356 | - $info[$key] = self::strip_objects($value); |
|
357 | - } else if (is_object($value)) { |
|
358 | - $object_class = get_class($value); |
|
359 | - $info[$object_class] = array(); |
|
360 | - $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | - if (method_exists($value, 'ID')) { |
|
362 | - $info[$object_class]['ID'] = $value->ID(); |
|
363 | - } |
|
364 | - if (method_exists($value, 'status')) { |
|
365 | - $info[$object_class]['status'] = $value->status(); |
|
366 | - } else if (method_exists($value, 'status_ID')) { |
|
367 | - $info[$object_class]['status'] = $value->status_ID(); |
|
368 | - } |
|
369 | - unset($info[$key]); |
|
370 | - } |
|
371 | - } |
|
372 | - return (array)$info; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @param mixed $var |
|
379 | - * @param string $var_name |
|
380 | - * @param string $file |
|
381 | - * @param int|string $line |
|
382 | - * @param int|string $heading_tag |
|
383 | - * @param bool $die |
|
384 | - * @param string $margin |
|
385 | - */ |
|
386 | - public static function printv( |
|
387 | - $var, |
|
388 | - $var_name = '', |
|
389 | - $file = '', |
|
390 | - $line = '', |
|
391 | - $heading_tag = 5, |
|
392 | - $die = false, |
|
393 | - $margin = '' |
|
394 | - ) { |
|
395 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | - $is_method = method_exists($var_name, $var); |
|
398 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
400 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
401 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
402 | - $result .= $is_method |
|
403 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
405 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
406 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
407 | - if ($die) { |
|
408 | - die($result); |
|
409 | - } |
|
410 | - echo $result; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - protected static function headingTag($heading_tag) |
|
415 | - { |
|
416 | - $heading_tag = absint($heading_tag); |
|
417 | - return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - protected static function headingSpacer($heading_tag) |
|
422 | - { |
|
423 | - return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
424 | - ? "\n" |
|
425 | - : ''; |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - protected static function plainOutput() |
|
430 | - { |
|
431 | - return defined('EE_TESTS_DIR') || (defined('DOING_AJAX') && DOING_AJAX); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * @param string $var_name |
|
437 | - * @param string $heading_tag |
|
438 | - * @param string $margin |
|
439 | - * @param int $line |
|
440 | - * @return string |
|
441 | - */ |
|
442 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
443 | - { |
|
444 | - if (EEH_Debug_Tools::plainOutput()) { |
|
445 | - $heading = ''; |
|
446 | - if($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
447 | - $heading .= "\n"; |
|
448 | - } |
|
449 | - $heading .= "\n{$line}) {$var_name}"; |
|
450 | - return $heading; |
|
451 | - } |
|
452 | - $margin = "25px 0 0 {$margin}"; |
|
453 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * @param string $heading_tag |
|
460 | - * @return string |
|
461 | - */ |
|
462 | - protected static function headingX($heading_tag = 'h5') |
|
463 | - { |
|
464 | - if (EEH_Debug_Tools::plainOutput()) { |
|
465 | - return ''; |
|
466 | - } |
|
467 | - return '</' . $heading_tag . '>'; |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * @param string $content |
|
474 | - * @return string |
|
475 | - */ |
|
476 | - protected static function grey_span($content = '') |
|
477 | - { |
|
478 | - if (EEH_Debug_Tools::plainOutput()) { |
|
479 | - return $content; |
|
480 | - } |
|
481 | - return '<span style="color:#999">' . $content . '</span>'; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * @param string $file |
|
488 | - * @param int $line |
|
489 | - * @return string |
|
490 | - */ |
|
491 | - protected static function file_and_line($file, $line, $heading_tag) |
|
492 | - { |
|
493 | - if ($file === '' || $line === '') { |
|
494 | - return ''; |
|
495 | - } |
|
496 | - $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
497 | - if (EEH_Debug_Tools::plainOutput()) { |
|
498 | - if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
499 | - return " ({$file})"; |
|
500 | - } |
|
501 | - return ''; |
|
502 | - } |
|
503 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
504 | - . $file |
|
505 | - . '<br />line no: ' |
|
506 | - . $line |
|
507 | - . '</span>'; |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * @param string $content |
|
514 | - * @return string |
|
515 | - */ |
|
516 | - protected static function orange_span($content = '') |
|
517 | - { |
|
518 | - if (EEH_Debug_Tools::plainOutput()) { |
|
519 | - return $content; |
|
520 | - } |
|
521 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * @param mixed $var |
|
528 | - * @return string |
|
529 | - */ |
|
530 | - protected static function pre_span($var) |
|
531 | - { |
|
532 | - ob_start(); |
|
533 | - var_dump($var); |
|
534 | - $var = ob_get_clean(); |
|
535 | - if (EEH_Debug_Tools::plainOutput()) { |
|
536 | - return $var; |
|
537 | - } |
|
538 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * @param mixed $var |
|
545 | - * @param string $var_name |
|
546 | - * @param string $file |
|
547 | - * @param int|string $line |
|
548 | - * @param int|string $heading_tag |
|
549 | - * @param bool $die |
|
550 | - */ |
|
551 | - public static function printr( |
|
552 | - $var, |
|
553 | - $var_name = '', |
|
554 | - $file = '', |
|
555 | - $line = '', |
|
556 | - $heading_tag = 5, |
|
557 | - $die = false |
|
558 | - ) { |
|
559 | - // return; |
|
560 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
561 | - $margin = is_admin() ? ' 180px' : '0'; |
|
562 | - //$print_r = false; |
|
563 | - if (is_string($var)) { |
|
564 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
565 | - return; |
|
566 | - } |
|
567 | - if (is_object($var)) { |
|
568 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
569 | - //$print_r = true; |
|
570 | - } else if (is_array($var)) { |
|
571 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
572 | - //$print_r = true; |
|
573 | - } else if (is_numeric($var)) { |
|
574 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
575 | - } else if ($var === null) { |
|
576 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
577 | - } |
|
578 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
579 | - $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
580 | - $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
581 | - $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
582 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
583 | - EEH_Debug_Tools::pre_span($var) |
|
584 | - ); |
|
585 | - $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
586 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
587 | - if ($die) { |
|
588 | - die($result); |
|
589 | - } |
|
590 | - echo $result; |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - |
|
595 | - /******************** deprecated ********************/ |
|
596 | - |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * @deprecated 4.9.39.rc.034 |
|
601 | - */ |
|
602 | - public function reset_times() |
|
603 | - { |
|
604 | - Benchmark::resetTimes(); |
|
605 | - } |
|
606 | - |
|
607 | - |
|
608 | - |
|
609 | - /** |
|
610 | - * @deprecated 4.9.39.rc.034 |
|
611 | - * @param null $timer_name |
|
612 | - */ |
|
613 | - public function start_timer($timer_name = null) |
|
614 | - { |
|
615 | - Benchmark::startTimer($timer_name); |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * @deprecated 4.9.39.rc.034 |
|
622 | - * @param string $timer_name |
|
623 | - */ |
|
624 | - public function stop_timer($timer_name = '') |
|
625 | - { |
|
626 | - Benchmark::stopTimer($timer_name); |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - |
|
631 | - /** |
|
632 | - * @deprecated 4.9.39.rc.034 |
|
633 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
634 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
635 | - * @return void |
|
636 | - */ |
|
637 | - public function measure_memory($label, $output_now = false) |
|
638 | - { |
|
639 | - Benchmark::measureMemory($label, $output_now); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * @deprecated 4.9.39.rc.034 |
|
646 | - * @param int $size |
|
647 | - * @return string |
|
648 | - */ |
|
649 | - public function convert($size) |
|
650 | - { |
|
651 | - return Benchmark::convert($size); |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * @deprecated 4.9.39.rc.034 |
|
658 | - * @param bool $output_now |
|
659 | - * @return string |
|
660 | - */ |
|
661 | - public function show_times($output_now = true) |
|
662 | - { |
|
663 | - return Benchmark::displayResults($output_now); |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * @deprecated 4.9.39.rc.034 |
|
670 | - * @param string $timer_name |
|
671 | - * @param float $total_time |
|
672 | - * @return string |
|
673 | - */ |
|
674 | - public function format_time($timer_name, $total_time) |
|
675 | - { |
|
676 | - return Benchmark::formatTime($timer_name, $total_time); |
|
677 | - } |
|
20 | + /** |
|
21 | + * instance of the EEH_Autoloader object |
|
22 | + * |
|
23 | + * @var $_instance |
|
24 | + * @access private |
|
25 | + */ |
|
26 | + private static $_instance; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $_memory_usage_points = array(); |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @access public |
|
38 | + * @return EEH_Debug_Tools |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated, and instantiated properly |
|
43 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + return self::$_instance; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * private class constructor |
|
53 | + */ |
|
54 | + private function __construct() |
|
55 | + { |
|
56 | + // load Kint PHP debugging library |
|
57 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
58 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
59 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
60 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
61 | + // so we've moved it to our test folder so that it is not included with production releases |
|
62 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
63 | + require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
64 | + } |
|
65 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
66 | + //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
67 | + // } |
|
68 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
69 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
71 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * show_db_name |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public static function show_db_name() |
|
82 | + { |
|
83 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
85 | + . DB_NAME |
|
86 | + . '</p>'; |
|
87 | + } |
|
88 | + if (EE_DEBUG) { |
|
89 | + Benchmark::displayResults(); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * dump EE_Session object at bottom of page after everything else has happened |
|
97 | + * |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public function espresso_session_footer_dump() |
|
101 | + { |
|
102 | + if ( |
|
103 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
104 | + && ! defined('DOING_AJAX') |
|
105 | + && class_exists('Kint') |
|
106 | + && function_exists('wp_get_current_user') |
|
107 | + && current_user_can('update_core') |
|
108 | + && class_exists('EE_Registry') |
|
109 | + ) { |
|
110 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
111 | + Kint::dump(EE_Registry::instance()->SSN); |
|
112 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
113 | + $this->espresso_list_hooked_functions(); |
|
114 | + Benchmark::displayResults(); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * List All Hooked Functions |
|
122 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
123 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
124 | + * |
|
125 | + * @param string $tag |
|
126 | + * @return void |
|
127 | + */ |
|
128 | + public function espresso_list_hooked_functions($tag = '') |
|
129 | + { |
|
130 | + global $wp_filter; |
|
131 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
132 | + if ($tag) { |
|
133 | + $hook[$tag] = $wp_filter[$tag]; |
|
134 | + if (! is_array($hook[$tag])) { |
|
135 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
136 | + return; |
|
137 | + } |
|
138 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
139 | + } else { |
|
140 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
141 | + ksort($hook); |
|
142 | + } |
|
143 | + foreach ($hook as $tag_name => $priorities) { |
|
144 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
145 | + ksort($priorities); |
|
146 | + foreach ($priorities as $priority => $function) { |
|
147 | + echo $priority; |
|
148 | + foreach ($function as $name => $properties) { |
|
149 | + echo "\t$name<br />"; |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * registered_filter_callbacks |
|
159 | + * |
|
160 | + * @param string $hook_name |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public static function registered_filter_callbacks($hook_name = '') |
|
164 | + { |
|
165 | + $filters = array(); |
|
166 | + global $wp_filter; |
|
167 | + if (isset($wp_filter[$hook_name])) { |
|
168 | + $filters[$hook_name] = array(); |
|
169 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | + $filters[$hook_name][$priority] = array(); |
|
171 | + foreach ($callbacks as $callback) { |
|
172 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + return $filters; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * captures plugin activation errors for debugging |
|
183 | + * |
|
184 | + * @return void |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public static function ee_plugin_activation_errors() |
|
188 | + { |
|
189 | + if (WP_DEBUG) { |
|
190 | + $activation_errors = ob_get_contents(); |
|
191 | + if (! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | + } |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | + if (class_exists('EEH_File')) { |
|
196 | + try { |
|
197 | + EEH_File::ensure_file_exists_and_is_writable( |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
199 | + ); |
|
200 | + EEH_File::write_to_file( |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
202 | + $activation_errors |
|
203 | + ); |
|
204 | + } catch (EE_Error $e) { |
|
205 | + EE_Error::add_error( |
|
206 | + sprintf( |
|
207 | + __( |
|
208 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | + 'event_espresso' |
|
210 | + ), |
|
211 | + $e->getMessage() |
|
212 | + ), |
|
213 | + __FILE__, __FUNCTION__, __LINE__ |
|
214 | + ); |
|
215 | + } |
|
216 | + } else { |
|
217 | + // old school attempt |
|
218 | + file_put_contents( |
|
219 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
220 | + $activation_errors |
|
221 | + ); |
|
222 | + } |
|
223 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
224 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
232 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
233 | + * or we want to make sure they use something the right way. |
|
234 | + * |
|
235 | + * @access public |
|
236 | + * @param string $function The function that was called |
|
237 | + * @param string $message A message explaining what has been done incorrectly |
|
238 | + * @param string $version The version of Event Espresso where the error was added |
|
239 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
240 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
241 | + * but not have any notices appear until a later version. This allows developers |
|
242 | + * extra time to update their code before notices appear. |
|
243 | + * @param int $error_type |
|
244 | + * @uses trigger_error() |
|
245 | + */ |
|
246 | + public function doing_it_wrong( |
|
247 | + $function, |
|
248 | + $message, |
|
249 | + $version, |
|
250 | + $applies_when = '', |
|
251 | + $error_type = null |
|
252 | + ) { |
|
253 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
254 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
255 | + // because we swapped the parameter order around for the last two params, |
|
256 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
257 | + if (is_int($applies_when)) { |
|
258 | + $error_type = $applies_when; |
|
259 | + $applies_when = espresso_version(); |
|
260 | + } |
|
261 | + // if not displaying notices yet, then just leave |
|
262 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
263 | + return; |
|
264 | + } |
|
265 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
266 | + $version = $version === null |
|
267 | + ? '' |
|
268 | + : sprintf( |
|
269 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
270 | + $version |
|
271 | + ); |
|
272 | + $error_message = sprintf( |
|
273 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
274 | + $function, |
|
275 | + '<strong>', |
|
276 | + '</strong>', |
|
277 | + $message, |
|
278 | + $version |
|
279 | + ); |
|
280 | + // don't trigger error if doing ajax, |
|
281 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
282 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
283 | + $error_message .= ' ' . esc_html__( |
|
284 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
285 | + 'event_espresso' |
|
286 | + ); |
|
287 | + $error_message .= '<ul><li>'; |
|
288 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
289 | + $error_message .= '</ul>'; |
|
290 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
291 | + //now we set this on the transient so it shows up on the next request. |
|
292 | + EE_Error::get_notices(false, true); |
|
293 | + } else { |
|
294 | + trigger_error($error_message, $error_type); |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Logger helpers |
|
303 | + */ |
|
304 | + /** |
|
305 | + * debug |
|
306 | + * |
|
307 | + * @param string $class |
|
308 | + * @param string $func |
|
309 | + * @param string $line |
|
310 | + * @param array $info |
|
311 | + * @param bool $display_request |
|
312 | + * @param string $debug_index |
|
313 | + * @param string $debug_key |
|
314 | + * @throws EE_Error |
|
315 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
316 | + */ |
|
317 | + public static function log( |
|
318 | + $class = '', |
|
319 | + $func = '', |
|
320 | + $line = '', |
|
321 | + $info = array(), |
|
322 | + $display_request = false, |
|
323 | + $debug_index = '', |
|
324 | + $debug_key = 'EE_DEBUG_SPCO' |
|
325 | + ) { |
|
326 | + if (WP_DEBUG) { |
|
327 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | + $debug_data = get_option($debug_key, array()); |
|
329 | + $default_data = array( |
|
330 | + $class => $func . '() : ' . $line, |
|
331 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
332 | + ); |
|
333 | + // don't serialize objects |
|
334 | + $info = self::strip_objects($info); |
|
335 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | + if (! isset($debug_data[$index])) { |
|
337 | + $debug_data[$index] = array(); |
|
338 | + } |
|
339 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | + update_option($debug_key, $debug_data); |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * strip_objects |
|
348 | + * |
|
349 | + * @param array $info |
|
350 | + * @return array |
|
351 | + */ |
|
352 | + public static function strip_objects($info = array()) |
|
353 | + { |
|
354 | + foreach ($info as $key => $value) { |
|
355 | + if (is_array($value)) { |
|
356 | + $info[$key] = self::strip_objects($value); |
|
357 | + } else if (is_object($value)) { |
|
358 | + $object_class = get_class($value); |
|
359 | + $info[$object_class] = array(); |
|
360 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | + if (method_exists($value, 'ID')) { |
|
362 | + $info[$object_class]['ID'] = $value->ID(); |
|
363 | + } |
|
364 | + if (method_exists($value, 'status')) { |
|
365 | + $info[$object_class]['status'] = $value->status(); |
|
366 | + } else if (method_exists($value, 'status_ID')) { |
|
367 | + $info[$object_class]['status'] = $value->status_ID(); |
|
368 | + } |
|
369 | + unset($info[$key]); |
|
370 | + } |
|
371 | + } |
|
372 | + return (array)$info; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @param mixed $var |
|
379 | + * @param string $var_name |
|
380 | + * @param string $file |
|
381 | + * @param int|string $line |
|
382 | + * @param int|string $heading_tag |
|
383 | + * @param bool $die |
|
384 | + * @param string $margin |
|
385 | + */ |
|
386 | + public static function printv( |
|
387 | + $var, |
|
388 | + $var_name = '', |
|
389 | + $file = '', |
|
390 | + $line = '', |
|
391 | + $heading_tag = 5, |
|
392 | + $die = false, |
|
393 | + $margin = '' |
|
394 | + ) { |
|
395 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | + $is_method = method_exists($var_name, $var); |
|
398 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
400 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
401 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
402 | + $result .= $is_method |
|
403 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
405 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
406 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
407 | + if ($die) { |
|
408 | + die($result); |
|
409 | + } |
|
410 | + echo $result; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + protected static function headingTag($heading_tag) |
|
415 | + { |
|
416 | + $heading_tag = absint($heading_tag); |
|
417 | + return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5'; |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + protected static function headingSpacer($heading_tag) |
|
422 | + { |
|
423 | + return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2') |
|
424 | + ? "\n" |
|
425 | + : ''; |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + protected static function plainOutput() |
|
430 | + { |
|
431 | + return defined('EE_TESTS_DIR') || (defined('DOING_AJAX') && DOING_AJAX); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * @param string $var_name |
|
437 | + * @param string $heading_tag |
|
438 | + * @param string $margin |
|
439 | + * @param int $line |
|
440 | + * @return string |
|
441 | + */ |
|
442 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0) |
|
443 | + { |
|
444 | + if (EEH_Debug_Tools::plainOutput()) { |
|
445 | + $heading = ''; |
|
446 | + if($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
447 | + $heading .= "\n"; |
|
448 | + } |
|
449 | + $heading .= "\n{$line}) {$var_name}"; |
|
450 | + return $heading; |
|
451 | + } |
|
452 | + $margin = "25px 0 0 {$margin}"; |
|
453 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * @param string $heading_tag |
|
460 | + * @return string |
|
461 | + */ |
|
462 | + protected static function headingX($heading_tag = 'h5') |
|
463 | + { |
|
464 | + if (EEH_Debug_Tools::plainOutput()) { |
|
465 | + return ''; |
|
466 | + } |
|
467 | + return '</' . $heading_tag . '>'; |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * @param string $content |
|
474 | + * @return string |
|
475 | + */ |
|
476 | + protected static function grey_span($content = '') |
|
477 | + { |
|
478 | + if (EEH_Debug_Tools::plainOutput()) { |
|
479 | + return $content; |
|
480 | + } |
|
481 | + return '<span style="color:#999">' . $content . '</span>'; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * @param string $file |
|
488 | + * @param int $line |
|
489 | + * @return string |
|
490 | + */ |
|
491 | + protected static function file_and_line($file, $line, $heading_tag) |
|
492 | + { |
|
493 | + if ($file === '' || $line === '') { |
|
494 | + return ''; |
|
495 | + } |
|
496 | + $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file); |
|
497 | + if (EEH_Debug_Tools::plainOutput()) { |
|
498 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
499 | + return " ({$file})"; |
|
500 | + } |
|
501 | + return ''; |
|
502 | + } |
|
503 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
504 | + . $file |
|
505 | + . '<br />line no: ' |
|
506 | + . $line |
|
507 | + . '</span>'; |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * @param string $content |
|
514 | + * @return string |
|
515 | + */ |
|
516 | + protected static function orange_span($content = '') |
|
517 | + { |
|
518 | + if (EEH_Debug_Tools::plainOutput()) { |
|
519 | + return $content; |
|
520 | + } |
|
521 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * @param mixed $var |
|
528 | + * @return string |
|
529 | + */ |
|
530 | + protected static function pre_span($var) |
|
531 | + { |
|
532 | + ob_start(); |
|
533 | + var_dump($var); |
|
534 | + $var = ob_get_clean(); |
|
535 | + if (EEH_Debug_Tools::plainOutput()) { |
|
536 | + return $var; |
|
537 | + } |
|
538 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * @param mixed $var |
|
545 | + * @param string $var_name |
|
546 | + * @param string $file |
|
547 | + * @param int|string $line |
|
548 | + * @param int|string $heading_tag |
|
549 | + * @param bool $die |
|
550 | + */ |
|
551 | + public static function printr( |
|
552 | + $var, |
|
553 | + $var_name = '', |
|
554 | + $file = '', |
|
555 | + $line = '', |
|
556 | + $heading_tag = 5, |
|
557 | + $die = false |
|
558 | + ) { |
|
559 | + // return; |
|
560 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
561 | + $margin = is_admin() ? ' 180px' : '0'; |
|
562 | + //$print_r = false; |
|
563 | + if (is_string($var)) { |
|
564 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
565 | + return; |
|
566 | + } |
|
567 | + if (is_object($var)) { |
|
568 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
569 | + //$print_r = true; |
|
570 | + } else if (is_array($var)) { |
|
571 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
572 | + //$print_r = true; |
|
573 | + } else if (is_numeric($var)) { |
|
574 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
575 | + } else if ($var === null) { |
|
576 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
577 | + } |
|
578 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
579 | + $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
|
580 | + $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
|
581 | + $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
|
582 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
583 | + EEH_Debug_Tools::pre_span($var) |
|
584 | + ); |
|
585 | + $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
|
586 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
587 | + if ($die) { |
|
588 | + die($result); |
|
589 | + } |
|
590 | + echo $result; |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + |
|
595 | + /******************** deprecated ********************/ |
|
596 | + |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * @deprecated 4.9.39.rc.034 |
|
601 | + */ |
|
602 | + public function reset_times() |
|
603 | + { |
|
604 | + Benchmark::resetTimes(); |
|
605 | + } |
|
606 | + |
|
607 | + |
|
608 | + |
|
609 | + /** |
|
610 | + * @deprecated 4.9.39.rc.034 |
|
611 | + * @param null $timer_name |
|
612 | + */ |
|
613 | + public function start_timer($timer_name = null) |
|
614 | + { |
|
615 | + Benchmark::startTimer($timer_name); |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * @deprecated 4.9.39.rc.034 |
|
622 | + * @param string $timer_name |
|
623 | + */ |
|
624 | + public function stop_timer($timer_name = '') |
|
625 | + { |
|
626 | + Benchmark::stopTimer($timer_name); |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + |
|
631 | + /** |
|
632 | + * @deprecated 4.9.39.rc.034 |
|
633 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
634 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
635 | + * @return void |
|
636 | + */ |
|
637 | + public function measure_memory($label, $output_now = false) |
|
638 | + { |
|
639 | + Benchmark::measureMemory($label, $output_now); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * @deprecated 4.9.39.rc.034 |
|
646 | + * @param int $size |
|
647 | + * @return string |
|
648 | + */ |
|
649 | + public function convert($size) |
|
650 | + { |
|
651 | + return Benchmark::convert($size); |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * @deprecated 4.9.39.rc.034 |
|
658 | + * @param bool $output_now |
|
659 | + * @return string |
|
660 | + */ |
|
661 | + public function show_times($output_now = true) |
|
662 | + { |
|
663 | + return Benchmark::displayResults($output_now); |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * @deprecated 4.9.39.rc.034 |
|
670 | + * @param string $timer_name |
|
671 | + * @param float $total_time |
|
672 | + * @return string |
|
673 | + */ |
|
674 | + public function format_time($timer_name, $total_time) |
|
675 | + { |
|
676 | + return Benchmark::formatTime($timer_name, $total_time); |
|
677 | + } |
|
678 | 678 | |
679 | 679 | |
680 | 680 | |
@@ -687,31 +687,31 @@ discard block |
||
687 | 687 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
688 | 688 | */ |
689 | 689 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
690 | - function dump_wp_query() |
|
691 | - { |
|
692 | - global $wp_query; |
|
693 | - d($wp_query); |
|
694 | - } |
|
690 | + function dump_wp_query() |
|
691 | + { |
|
692 | + global $wp_query; |
|
693 | + d($wp_query); |
|
694 | + } |
|
695 | 695 | } |
696 | 696 | /** |
697 | 697 | * borrowed from Kint Debugger |
698 | 698 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
699 | 699 | */ |
700 | 700 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
701 | - function dump_wp() |
|
702 | - { |
|
703 | - global $wp; |
|
704 | - d($wp); |
|
705 | - } |
|
701 | + function dump_wp() |
|
702 | + { |
|
703 | + global $wp; |
|
704 | + d($wp); |
|
705 | + } |
|
706 | 706 | } |
707 | 707 | /** |
708 | 708 | * borrowed from Kint Debugger |
709 | 709 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
710 | 710 | */ |
711 | 711 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
712 | - function dump_post() |
|
713 | - { |
|
714 | - global $post; |
|
715 | - d($post); |
|
716 | - } |
|
712 | + function dump_post() |
|
713 | + { |
|
714 | + global $post; |
|
715 | + d($post); |
|
716 | + } |
|
717 | 717 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public static function instance() |
41 | 41 | { |
42 | 42 | // check if class object is instantiated, and instantiated properly |
43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
43 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | 44 | self::$_instance = new self(); |
45 | 45 | } |
46 | 46 | return self::$_instance; |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | private function __construct() |
55 | 55 | { |
56 | 56 | // load Kint PHP debugging library |
57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
57 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
58 | 58 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
59 | 59 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
60 | 60 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
61 | 61 | // so we've moved it to our test folder so that it is not included with production releases |
62 | 62 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
63 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
64 | 64 | } |
65 | 65 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
66 | 66 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public static function show_db_name() |
82 | 82 | { |
83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
83 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | 84 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
85 | 85 | . DB_NAME |
86 | 86 | . '</p>'; |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
132 | 132 | if ($tag) { |
133 | 133 | $hook[$tag] = $wp_filter[$tag]; |
134 | - if (! is_array($hook[$tag])) { |
|
134 | + if ( ! is_array($hook[$tag])) { |
|
135 | 135 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
136 | 136 | return; |
137 | 137 | } |
138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
138 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
139 | 139 | } else { |
140 | 140 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
141 | 141 | ksort($hook); |
@@ -188,17 +188,17 @@ discard block |
||
188 | 188 | { |
189 | 189 | if (WP_DEBUG) { |
190 | 190 | $activation_errors = ob_get_contents(); |
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
191 | + if ( ! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
193 | 193 | } |
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
195 | 195 | if (class_exists('EEH_File')) { |
196 | 196 | try { |
197 | 197 | EEH_File::ensure_file_exists_and_is_writable( |
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html' |
|
199 | 199 | ); |
200 | 200 | EEH_File::write_to_file( |
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
202 | 202 | $activation_errors |
203 | 203 | ); |
204 | 204 | } catch (EE_Error $e) { |
@@ -216,11 +216,11 @@ discard block |
||
216 | 216 | } else { |
217 | 217 | // old school attempt |
218 | 218 | file_put_contents( |
219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
219 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
220 | 220 | $activation_errors |
221 | 221 | ); |
222 | 222 | } |
223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
223 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
224 | 224 | update_option('ee_plugin_activation_errors', $activation_errors); |
225 | 225 | } |
226 | 226 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | // don't trigger error if doing ajax, |
281 | 281 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
282 | 282 | if (defined('DOING_AJAX') && DOING_AJAX) { |
283 | - $error_message .= ' ' . esc_html__( |
|
283 | + $error_message .= ' '.esc_html__( |
|
284 | 284 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
285 | 285 | 'event_espresso' |
286 | 286 | ); |
@@ -324,16 +324,16 @@ discard block |
||
324 | 324 | $debug_key = 'EE_DEBUG_SPCO' |
325 | 325 | ) { |
326 | 326 | if (WP_DEBUG) { |
327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
327 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
328 | 328 | $debug_data = get_option($debug_key, array()); |
329 | 329 | $default_data = array( |
330 | - $class => $func . '() : ' . $line, |
|
330 | + $class => $func.'() : '.$line, |
|
331 | 331 | 'REQ' => $display_request ? $_REQUEST : '', |
332 | 332 | ); |
333 | 333 | // don't serialize objects |
334 | 334 | $info = self::strip_objects($info); |
335 | 335 | $index = ! empty($debug_index) ? $debug_index : 0; |
336 | - if (! isset($debug_data[$index])) { |
|
336 | + if ( ! isset($debug_data[$index])) { |
|
337 | 337 | $debug_data[$index] = array(); |
338 | 338 | } |
339 | 339 | $debug_data[$index][microtime()] = array_merge($default_data, $info); |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | unset($info[$key]); |
370 | 370 | } |
371 | 371 | } |
372 | - return (array)$info; |
|
372 | + return (array) $info; |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
@@ -400,8 +400,8 @@ discard block |
||
400 | 400 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
401 | 401 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
402 | 402 | $result .= $is_method |
403 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
404 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
403 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
404 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
405 | 405 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |
406 | 406 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
407 | 407 | if ($die) { |
@@ -443,14 +443,14 @@ discard block |
||
443 | 443 | { |
444 | 444 | if (EEH_Debug_Tools::plainOutput()) { |
445 | 445 | $heading = ''; |
446 | - if($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
446 | + if ($heading_tag === 'h1' || $heading_tag === 'h2') { |
|
447 | 447 | $heading .= "\n"; |
448 | 448 | } |
449 | 449 | $heading .= "\n{$line}) {$var_name}"; |
450 | 450 | return $heading; |
451 | 451 | } |
452 | 452 | $margin = "25px 0 0 {$margin}"; |
453 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
453 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | if (EEH_Debug_Tools::plainOutput()) { |
465 | 465 | return ''; |
466 | 466 | } |
467 | - return '</' . $heading_tag . '>'; |
|
467 | + return '</'.$heading_tag.'>'; |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | if (EEH_Debug_Tools::plainOutput()) { |
479 | 479 | return $content; |
480 | 480 | } |
481 | - return '<span style="color:#999">' . $content . '</span>'; |
|
481 | + return '<span style="color:#999">'.$content.'</span>'; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | if (EEH_Debug_Tools::plainOutput()) { |
519 | 519 | return $content; |
520 | 520 | } |
521 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
521 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | if (EEH_Debug_Tools::plainOutput()) { |
536 | 536 | return $var; |
537 | 537 | } |
538 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
538 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | $heading_tag = EEH_Debug_Tools::headingTag($heading_tag); |
580 | 580 | $result = EEH_Debug_Tools::headingSpacer($heading_tag); |
581 | 581 | $result .= EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line); |
582 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
582 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
583 | 583 | EEH_Debug_Tools::pre_span($var) |
584 | 584 | ); |
585 | 585 | $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag); |