@@ -22,457 +22,457 @@ discard block |
||
22 | 22 | final class EE_Admin implements InterminableInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var EE_Admin $_instance |
|
27 | - */ |
|
28 | - private static $_instance; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var PersistentAdminNoticeManager $persistent_admin_notice_manager |
|
32 | - */ |
|
33 | - private $persistent_admin_notice_manager; |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @return EE_Admin |
|
38 | - * @throws EE_Error |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated |
|
43 | - if (! self::$_instance instanceof EE_Admin) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - return self::$_instance; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * @return EE_Admin |
|
52 | - * @throws EE_Error |
|
53 | - */ |
|
54 | - public static function reset() |
|
55 | - { |
|
56 | - self::$_instance = null; |
|
57 | - return self::instance(); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * class constructor |
|
63 | - * |
|
64 | - * @throws EE_Error |
|
65 | - * @throws InvalidDataTypeException |
|
66 | - * @throws InvalidInterfaceException |
|
67 | - * @throws InvalidArgumentException |
|
68 | - */ |
|
69 | - protected function __construct() |
|
70 | - { |
|
71 | - // define global EE_Admin constants |
|
72 | - $this->_define_all_constants(); |
|
73 | - // set autoloaders for our admin page classes based on included path information |
|
74 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
75 | - // admin hooks |
|
76 | - add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
77 | - // load EE_Request_Handler early |
|
78 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
79 | - add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
80 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
81 | - add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
82 | - add_action('admin_init', array($this, 'admin_init'), 100); |
|
83 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
84 | - add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
85 | - add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
86 | - add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
87 | - add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
88 | - //reset Environment config (we only do this on admin page loads); |
|
89 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
90 | - do_action('AHEE__EE_Admin__loaded'); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * _define_all_constants |
|
97 | - * define constants that are set globally for all admin pages |
|
98 | - * |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - private function _define_all_constants() |
|
102 | - { |
|
103 | - if (! defined('EE_ADMIN_URL')) { |
|
104 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
105 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
106 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
107 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
108 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
115 | - * |
|
116 | - * @param array $links |
|
117 | - * @param string $plugin |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public function filter_plugin_actions($links, $plugin) |
|
121 | - { |
|
122 | - // set $main_file in stone |
|
123 | - static $main_file; |
|
124 | - // if $main_file is not set yet |
|
125 | - if (! $main_file) { |
|
126 | - $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
127 | - } |
|
128 | - if ($plugin === $main_file) { |
|
129 | - // compare current plugin to this one |
|
130 | - if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
131 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
132 | - . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
133 | - . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
134 | - . '</a>'; |
|
135 | - array_unshift($links, $maintenance_link); |
|
136 | - } else { |
|
137 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
138 | - . esc_html__('Settings', 'event_espresso') |
|
139 | - . '</a>'; |
|
140 | - $events_link = '<a href="admin.php?page=espresso_events">' |
|
141 | - . esc_html__('Events', 'event_espresso') |
|
142 | - . '</a>'; |
|
143 | - // add before other links |
|
144 | - array_unshift($links, $org_settings_link, $events_link); |
|
145 | - } |
|
146 | - } |
|
147 | - return $links; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * _get_request |
|
153 | - * |
|
154 | - * @return void |
|
155 | - * @throws EE_Error |
|
156 | - * @throws InvalidArgumentException |
|
157 | - * @throws InvalidDataTypeException |
|
158 | - * @throws InvalidInterfaceException |
|
159 | - * @throws ReflectionException |
|
160 | - */ |
|
161 | - public function get_request() |
|
162 | - { |
|
163 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
164 | - EE_Registry::instance()->load_core('CPT_Strategy'); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * hide_admin_pages_except_maintenance_mode |
|
171 | - * |
|
172 | - * @param array $admin_page_folder_names |
|
173 | - * @return array |
|
174 | - */ |
|
175 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
176 | - { |
|
177 | - return array( |
|
178 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
179 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
180 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
181 | - ); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
188 | - * EE_Front_Controller's init phases have run |
|
189 | - * |
|
190 | - * @return void |
|
191 | - * @throws EE_Error |
|
192 | - * @throws InvalidArgumentException |
|
193 | - * @throws InvalidDataTypeException |
|
194 | - * @throws InvalidInterfaceException |
|
195 | - * @throws ReflectionException |
|
196 | - * @throws ServiceNotFoundException |
|
197 | - */ |
|
198 | - public function init() |
|
199 | - { |
|
200 | - //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
201 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
202 | - //ok so we want to enable the entire admin |
|
203 | - $this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
204 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager', |
|
205 | - array( |
|
206 | - EE_Admin_Page::add_query_args_and_nonce( |
|
207 | - array( |
|
208 | - 'page' => EE_Registry::instance()->REQ->get('page', ''), |
|
209 | - 'action' => EE_Registry::instance()->REQ->get('action', ''), |
|
210 | - ), |
|
211 | - EE_ADMIN_URL |
|
212 | - ), |
|
213 | - ) |
|
214 | - ); |
|
215 | - $this->maybeSetDatetimeWarningNotice(); |
|
216 | - //at a glance dashboard widget |
|
217 | - add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
218 | - //filter for get_edit_post_link used on comments for custom post types |
|
219 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
220 | - } |
|
221 | - // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
222 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
223 | - try { |
|
224 | - //this loads the controller for the admin pages which will setup routing etc |
|
225 | - EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
226 | - } catch (EE_Error $e) { |
|
227 | - $e->get_error(); |
|
228 | - } |
|
229 | - } |
|
230 | - add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
231 | - //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
232 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
233 | - add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
234 | - //exclude EE critical pages from all nav menus and wp_list_pages |
|
235 | - add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * get_persistent_admin_notices |
|
241 | - * |
|
242 | - * @access public |
|
243 | - * @return void |
|
244 | - * @throws EE_Error |
|
245 | - * @throws InvalidArgumentException |
|
246 | - * @throws InvalidDataTypeException |
|
247 | - * @throws InvalidInterfaceException |
|
248 | - */ |
|
249 | - public function maybeSetDatetimeWarningNotice() |
|
250 | - { |
|
251 | - //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
252 | - //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
253 | - //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
254 | - //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
255 | - if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
256 | - && ! get_option('timezone_string') |
|
257 | - && EEM_Event::instance()->count() > 0 |
|
258 | - ) { |
|
259 | - new PersistentAdminNotice( |
|
260 | - 'datetime_fix_notice', |
|
261 | - sprintf( |
|
262 | - esc_html__( |
|
263 | - '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
264 | - 'event_espresso' |
|
265 | - ), |
|
266 | - '<strong>', |
|
267 | - '</strong>', |
|
268 | - '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
269 | - '</a>', |
|
270 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
271 | - array( |
|
272 | - 'page' => 'espresso_maintenance_settings', |
|
273 | - 'action' => 'datetime_tools' |
|
274 | - ), |
|
275 | - admin_url('admin.php') |
|
276 | - ) . '">' |
|
277 | - ), |
|
278 | - false, |
|
279 | - 'manage_options', |
|
280 | - 'datetime_fix_persistent_notice' |
|
281 | - ); |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
289 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
290 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
291 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
292 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
293 | - * |
|
294 | - * @param WP_Post $post_type WP post type object |
|
295 | - * @return WP_Post |
|
296 | - * @throws InvalidArgumentException |
|
297 | - * @throws InvalidDataTypeException |
|
298 | - * @throws InvalidInterfaceException |
|
299 | - */ |
|
300 | - public function remove_pages_from_nav_menu($post_type) |
|
301 | - { |
|
302 | - //if this isn't the "pages" post type let's get out |
|
303 | - if ($post_type->name !== 'page') { |
|
304 | - return $post_type; |
|
305 | - } |
|
306 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
307 | - $post_type->_default_query = array( |
|
308 | - 'post__not_in' => $critical_pages, |
|
309 | - ); |
|
310 | - return $post_type; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
317 | - * metaboxes get shown as well |
|
318 | - * |
|
319 | - * @return void |
|
320 | - */ |
|
321 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
322 | - { |
|
323 | - global $wp_meta_boxes, $pagenow; |
|
324 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
325 | - return; |
|
326 | - } |
|
327 | - $user = wp_get_current_user(); |
|
328 | - //has this been done yet? |
|
329 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
330 | - return; |
|
331 | - } |
|
332 | - |
|
333 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
334 | - $initial_meta_boxes = apply_filters( |
|
335 | - 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
336 | - array( |
|
337 | - 'nav-menu-theme-locations', |
|
338 | - 'add-page', |
|
339 | - 'add-custom-links', |
|
340 | - 'add-category', |
|
341 | - 'add-espresso_events', |
|
342 | - 'add-espresso_venues', |
|
343 | - 'add-espresso_event_categories', |
|
344 | - 'add-espresso_venue_categories', |
|
345 | - 'add-post-type-post', |
|
346 | - 'add-post-type-page', |
|
347 | - ) |
|
348 | - ); |
|
349 | - |
|
350 | - if (is_array($hidden_meta_boxes)) { |
|
351 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
352 | - if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
353 | - unset($hidden_meta_boxes[$key]); |
|
354 | - } |
|
355 | - } |
|
356 | - } |
|
357 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
358 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
365 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
366 | - * |
|
367 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
368 | - * addons etc. |
|
369 | - * @return void |
|
370 | - */ |
|
371 | - public function register_custom_nav_menu_boxes() |
|
372 | - { |
|
373 | - add_meta_box( |
|
374 | - 'add-extra-nav-menu-pages', |
|
375 | - esc_html__('Event Espresso Pages', 'event_espresso'), |
|
376 | - array($this, 'ee_cpt_archive_pages'), |
|
377 | - 'nav-menus', |
|
378 | - 'side', |
|
379 | - 'core' |
|
380 | - ); |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
387 | - * |
|
388 | - * @since 4.3.0 |
|
389 | - * @param string $link the original link generated by wp |
|
390 | - * @param int $id post id |
|
391 | - * @return string the (maybe) modified link |
|
392 | - */ |
|
393 | - public function modify_edit_post_link($link, $id) |
|
394 | - { |
|
395 | - if (! $post = get_post($id)) { |
|
396 | - return $link; |
|
397 | - } |
|
398 | - if ($post->post_type === 'espresso_attendees') { |
|
399 | - $query_args = array( |
|
400 | - 'action' => 'edit_attendee', |
|
401 | - 'post' => $id, |
|
402 | - ); |
|
403 | - return EEH_URL::add_query_args_and_nonce( |
|
404 | - $query_args, |
|
405 | - admin_url('admin.php?page=espresso_registrations') |
|
406 | - ); |
|
407 | - } |
|
408 | - return $link; |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - |
|
413 | - public function ee_cpt_archive_pages() |
|
414 | - { |
|
415 | - global $nav_menu_selected_id; |
|
416 | - $db_fields = false; |
|
417 | - $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
418 | - $current_tab = 'event-archives'; |
|
419 | - $removed_args = array( |
|
420 | - 'action', |
|
421 | - 'customlink-tab', |
|
422 | - 'edit-menu-item', |
|
423 | - 'menu-item', |
|
424 | - 'page-tab', |
|
425 | - '_wpnonce', |
|
426 | - ); |
|
427 | - ?> |
|
25 | + /** |
|
26 | + * @var EE_Admin $_instance |
|
27 | + */ |
|
28 | + private static $_instance; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var PersistentAdminNoticeManager $persistent_admin_notice_manager |
|
32 | + */ |
|
33 | + private $persistent_admin_notice_manager; |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @return EE_Admin |
|
38 | + * @throws EE_Error |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated |
|
43 | + if (! self::$_instance instanceof EE_Admin) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + return self::$_instance; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * @return EE_Admin |
|
52 | + * @throws EE_Error |
|
53 | + */ |
|
54 | + public static function reset() |
|
55 | + { |
|
56 | + self::$_instance = null; |
|
57 | + return self::instance(); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * class constructor |
|
63 | + * |
|
64 | + * @throws EE_Error |
|
65 | + * @throws InvalidDataTypeException |
|
66 | + * @throws InvalidInterfaceException |
|
67 | + * @throws InvalidArgumentException |
|
68 | + */ |
|
69 | + protected function __construct() |
|
70 | + { |
|
71 | + // define global EE_Admin constants |
|
72 | + $this->_define_all_constants(); |
|
73 | + // set autoloaders for our admin page classes based on included path information |
|
74 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
75 | + // admin hooks |
|
76 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
77 | + // load EE_Request_Handler early |
|
78 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
79 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
80 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
81 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
82 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
83 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
84 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
85 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
86 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
87 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
88 | + //reset Environment config (we only do this on admin page loads); |
|
89 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
90 | + do_action('AHEE__EE_Admin__loaded'); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * _define_all_constants |
|
97 | + * define constants that are set globally for all admin pages |
|
98 | + * |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + private function _define_all_constants() |
|
102 | + { |
|
103 | + if (! defined('EE_ADMIN_URL')) { |
|
104 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
105 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
106 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
107 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
108 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
115 | + * |
|
116 | + * @param array $links |
|
117 | + * @param string $plugin |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public function filter_plugin_actions($links, $plugin) |
|
121 | + { |
|
122 | + // set $main_file in stone |
|
123 | + static $main_file; |
|
124 | + // if $main_file is not set yet |
|
125 | + if (! $main_file) { |
|
126 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
127 | + } |
|
128 | + if ($plugin === $main_file) { |
|
129 | + // compare current plugin to this one |
|
130 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
131 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
132 | + . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
133 | + . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
134 | + . '</a>'; |
|
135 | + array_unshift($links, $maintenance_link); |
|
136 | + } else { |
|
137 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
138 | + . esc_html__('Settings', 'event_espresso') |
|
139 | + . '</a>'; |
|
140 | + $events_link = '<a href="admin.php?page=espresso_events">' |
|
141 | + . esc_html__('Events', 'event_espresso') |
|
142 | + . '</a>'; |
|
143 | + // add before other links |
|
144 | + array_unshift($links, $org_settings_link, $events_link); |
|
145 | + } |
|
146 | + } |
|
147 | + return $links; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * _get_request |
|
153 | + * |
|
154 | + * @return void |
|
155 | + * @throws EE_Error |
|
156 | + * @throws InvalidArgumentException |
|
157 | + * @throws InvalidDataTypeException |
|
158 | + * @throws InvalidInterfaceException |
|
159 | + * @throws ReflectionException |
|
160 | + */ |
|
161 | + public function get_request() |
|
162 | + { |
|
163 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
164 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * hide_admin_pages_except_maintenance_mode |
|
171 | + * |
|
172 | + * @param array $admin_page_folder_names |
|
173 | + * @return array |
|
174 | + */ |
|
175 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
176 | + { |
|
177 | + return array( |
|
178 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
179 | + 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
180 | + 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
181 | + ); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
188 | + * EE_Front_Controller's init phases have run |
|
189 | + * |
|
190 | + * @return void |
|
191 | + * @throws EE_Error |
|
192 | + * @throws InvalidArgumentException |
|
193 | + * @throws InvalidDataTypeException |
|
194 | + * @throws InvalidInterfaceException |
|
195 | + * @throws ReflectionException |
|
196 | + * @throws ServiceNotFoundException |
|
197 | + */ |
|
198 | + public function init() |
|
199 | + { |
|
200 | + //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
201 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
202 | + //ok so we want to enable the entire admin |
|
203 | + $this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
204 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager', |
|
205 | + array( |
|
206 | + EE_Admin_Page::add_query_args_and_nonce( |
|
207 | + array( |
|
208 | + 'page' => EE_Registry::instance()->REQ->get('page', ''), |
|
209 | + 'action' => EE_Registry::instance()->REQ->get('action', ''), |
|
210 | + ), |
|
211 | + EE_ADMIN_URL |
|
212 | + ), |
|
213 | + ) |
|
214 | + ); |
|
215 | + $this->maybeSetDatetimeWarningNotice(); |
|
216 | + //at a glance dashboard widget |
|
217 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
218 | + //filter for get_edit_post_link used on comments for custom post types |
|
219 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
220 | + } |
|
221 | + // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
222 | + if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
223 | + try { |
|
224 | + //this loads the controller for the admin pages which will setup routing etc |
|
225 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
226 | + } catch (EE_Error $e) { |
|
227 | + $e->get_error(); |
|
228 | + } |
|
229 | + } |
|
230 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
231 | + //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
232 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
233 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
234 | + //exclude EE critical pages from all nav menus and wp_list_pages |
|
235 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * get_persistent_admin_notices |
|
241 | + * |
|
242 | + * @access public |
|
243 | + * @return void |
|
244 | + * @throws EE_Error |
|
245 | + * @throws InvalidArgumentException |
|
246 | + * @throws InvalidDataTypeException |
|
247 | + * @throws InvalidInterfaceException |
|
248 | + */ |
|
249 | + public function maybeSetDatetimeWarningNotice() |
|
250 | + { |
|
251 | + //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
252 | + //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
253 | + //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
254 | + //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
255 | + if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true) |
|
256 | + && ! get_option('timezone_string') |
|
257 | + && EEM_Event::instance()->count() > 0 |
|
258 | + ) { |
|
259 | + new PersistentAdminNotice( |
|
260 | + 'datetime_fix_notice', |
|
261 | + sprintf( |
|
262 | + esc_html__( |
|
263 | + '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
264 | + 'event_espresso' |
|
265 | + ), |
|
266 | + '<strong>', |
|
267 | + '</strong>', |
|
268 | + '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
269 | + '</a>', |
|
270 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
271 | + array( |
|
272 | + 'page' => 'espresso_maintenance_settings', |
|
273 | + 'action' => 'datetime_tools' |
|
274 | + ), |
|
275 | + admin_url('admin.php') |
|
276 | + ) . '">' |
|
277 | + ), |
|
278 | + false, |
|
279 | + 'manage_options', |
|
280 | + 'datetime_fix_persistent_notice' |
|
281 | + ); |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
289 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
290 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
291 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
292 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
293 | + * |
|
294 | + * @param WP_Post $post_type WP post type object |
|
295 | + * @return WP_Post |
|
296 | + * @throws InvalidArgumentException |
|
297 | + * @throws InvalidDataTypeException |
|
298 | + * @throws InvalidInterfaceException |
|
299 | + */ |
|
300 | + public function remove_pages_from_nav_menu($post_type) |
|
301 | + { |
|
302 | + //if this isn't the "pages" post type let's get out |
|
303 | + if ($post_type->name !== 'page') { |
|
304 | + return $post_type; |
|
305 | + } |
|
306 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
307 | + $post_type->_default_query = array( |
|
308 | + 'post__not_in' => $critical_pages, |
|
309 | + ); |
|
310 | + return $post_type; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
317 | + * metaboxes get shown as well |
|
318 | + * |
|
319 | + * @return void |
|
320 | + */ |
|
321 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
322 | + { |
|
323 | + global $wp_meta_boxes, $pagenow; |
|
324 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
325 | + return; |
|
326 | + } |
|
327 | + $user = wp_get_current_user(); |
|
328 | + //has this been done yet? |
|
329 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
330 | + return; |
|
331 | + } |
|
332 | + |
|
333 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
334 | + $initial_meta_boxes = apply_filters( |
|
335 | + 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
336 | + array( |
|
337 | + 'nav-menu-theme-locations', |
|
338 | + 'add-page', |
|
339 | + 'add-custom-links', |
|
340 | + 'add-category', |
|
341 | + 'add-espresso_events', |
|
342 | + 'add-espresso_venues', |
|
343 | + 'add-espresso_event_categories', |
|
344 | + 'add-espresso_venue_categories', |
|
345 | + 'add-post-type-post', |
|
346 | + 'add-post-type-page', |
|
347 | + ) |
|
348 | + ); |
|
349 | + |
|
350 | + if (is_array($hidden_meta_boxes)) { |
|
351 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
352 | + if (in_array($meta_box_id, $initial_meta_boxes, true)) { |
|
353 | + unset($hidden_meta_boxes[$key]); |
|
354 | + } |
|
355 | + } |
|
356 | + } |
|
357 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
358 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
365 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
366 | + * |
|
367 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
368 | + * addons etc. |
|
369 | + * @return void |
|
370 | + */ |
|
371 | + public function register_custom_nav_menu_boxes() |
|
372 | + { |
|
373 | + add_meta_box( |
|
374 | + 'add-extra-nav-menu-pages', |
|
375 | + esc_html__('Event Espresso Pages', 'event_espresso'), |
|
376 | + array($this, 'ee_cpt_archive_pages'), |
|
377 | + 'nav-menus', |
|
378 | + 'side', |
|
379 | + 'core' |
|
380 | + ); |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
387 | + * |
|
388 | + * @since 4.3.0 |
|
389 | + * @param string $link the original link generated by wp |
|
390 | + * @param int $id post id |
|
391 | + * @return string the (maybe) modified link |
|
392 | + */ |
|
393 | + public function modify_edit_post_link($link, $id) |
|
394 | + { |
|
395 | + if (! $post = get_post($id)) { |
|
396 | + return $link; |
|
397 | + } |
|
398 | + if ($post->post_type === 'espresso_attendees') { |
|
399 | + $query_args = array( |
|
400 | + 'action' => 'edit_attendee', |
|
401 | + 'post' => $id, |
|
402 | + ); |
|
403 | + return EEH_URL::add_query_args_and_nonce( |
|
404 | + $query_args, |
|
405 | + admin_url('admin.php?page=espresso_registrations') |
|
406 | + ); |
|
407 | + } |
|
408 | + return $link; |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + |
|
413 | + public function ee_cpt_archive_pages() |
|
414 | + { |
|
415 | + global $nav_menu_selected_id; |
|
416 | + $db_fields = false; |
|
417 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
418 | + $current_tab = 'event-archives'; |
|
419 | + $removed_args = array( |
|
420 | + 'action', |
|
421 | + 'customlink-tab', |
|
422 | + 'edit-menu-item', |
|
423 | + 'menu-item', |
|
424 | + 'page-tab', |
|
425 | + '_wpnonce', |
|
426 | + ); |
|
427 | + ?> |
|
428 | 428 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
429 | 429 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
430 | 430 | <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
431 | 431 | <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
432 | 432 | href="<?php if ($nav_menu_selected_id) { |
433 | - echo esc_url( |
|
434 | - add_query_arg( |
|
435 | - 'extra-nav-menu-pages-tab', |
|
436 | - 'event-archives', |
|
437 | - remove_query_arg($removed_args) |
|
438 | - ) |
|
439 | - ); |
|
440 | - } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
433 | + echo esc_url( |
|
434 | + add_query_arg( |
|
435 | + 'extra-nav-menu-pages-tab', |
|
436 | + 'event-archives', |
|
437 | + remove_query_arg($removed_args) |
|
438 | + ) |
|
439 | + ); |
|
440 | + } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
441 | 441 | <?php _e('Event Archive Pages', 'event_espresso'); ?> |
442 | 442 | </a> |
443 | 443 | </li> |
444 | 444 | </ul><!-- .posttype-tabs --> |
445 | 445 | |
446 | 446 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
447 | - echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
448 | - ?>"> |
|
447 | + echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
448 | + ?>"> |
|
449 | 449 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
450 | 450 | <?php |
451 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
452 | - $args['walker'] = $walker; |
|
453 | - echo walk_nav_menu_tree( |
|
454 | - array_map( |
|
455 | - array($this, '_setup_extra_nav_menu_pages_items'), |
|
456 | - $pages |
|
457 | - ), |
|
458 | - 0, |
|
459 | - (object) $args |
|
460 | - ); |
|
461 | - ?> |
|
451 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
452 | + $args['walker'] = $walker; |
|
453 | + echo walk_nav_menu_tree( |
|
454 | + array_map( |
|
455 | + array($this, '_setup_extra_nav_menu_pages_items'), |
|
456 | + $pages |
|
457 | + ), |
|
458 | + 0, |
|
459 | + (object) $args |
|
460 | + ); |
|
461 | + ?> |
|
462 | 462 | </ul> |
463 | 463 | </div><!-- /.tabs-panel --> |
464 | 464 | |
465 | 465 | <p class="button-controls"> |
466 | 466 | <span class="list-controls"> |
467 | 467 | <a href="<?php |
468 | - echo esc_url(add_query_arg( |
|
469 | - array( |
|
470 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
471 | - 'selectall' => 1, |
|
472 | - ), |
|
473 | - remove_query_arg($removed_args) |
|
474 | - )); |
|
475 | - ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
468 | + echo esc_url(add_query_arg( |
|
469 | + array( |
|
470 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
471 | + 'selectall' => 1, |
|
472 | + ), |
|
473 | + remove_query_arg($removed_args) |
|
474 | + )); |
|
475 | + ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
476 | 476 | </span> |
477 | 477 | <span class="add-to-menu"> |
478 | 478 | <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> |
@@ -485,471 +485,471 @@ discard block |
||
485 | 485 | |
486 | 486 | </div><!-- /.posttypediv --> |
487 | 487 | <?php |
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * Returns an array of event archive nav items. |
|
493 | - * |
|
494 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
495 | - * method we use for getting the extra nav menu items |
|
496 | - * @return array |
|
497 | - */ |
|
498 | - private function _get_extra_nav_menu_pages_items() |
|
499 | - { |
|
500 | - $menuitems[] = array( |
|
501 | - 'title' => esc_html__('Event List', 'event_espresso'), |
|
502 | - 'url' => get_post_type_archive_link('espresso_events'), |
|
503 | - 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
504 | - ); |
|
505 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
511 | - * the properties and converts it to the menu item object. |
|
512 | - * |
|
513 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
514 | - * @param $menu_item_values |
|
515 | - * @return stdClass |
|
516 | - */ |
|
517 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
518 | - { |
|
519 | - $menu_item = new stdClass(); |
|
520 | - $keys = array( |
|
521 | - 'ID' => 0, |
|
522 | - 'db_id' => 0, |
|
523 | - 'menu_item_parent' => 0, |
|
524 | - 'object_id' => -1, |
|
525 | - 'post_parent' => 0, |
|
526 | - 'type' => 'custom', |
|
527 | - 'object' => '', |
|
528 | - 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
529 | - 'title' => '', |
|
530 | - 'url' => '', |
|
531 | - 'target' => '', |
|
532 | - 'attr_title' => '', |
|
533 | - 'description' => '', |
|
534 | - 'classes' => array(), |
|
535 | - 'xfn' => '', |
|
536 | - ); |
|
537 | - |
|
538 | - foreach ($keys as $key => $value) { |
|
539 | - $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
540 | - } |
|
541 | - return $menu_item; |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
547 | - * EE_Admin_Page route is called. |
|
548 | - * |
|
549 | - * @return void |
|
550 | - */ |
|
551 | - public function route_admin_request() |
|
552 | - { |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
558 | - * |
|
559 | - * @return void |
|
560 | - */ |
|
561 | - public function wp_loaded() |
|
562 | - { |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * admin_init |
|
568 | - * |
|
569 | - * @return void |
|
570 | - * @throws EE_Error |
|
571 | - * @throws InvalidArgumentException |
|
572 | - * @throws InvalidDataTypeException |
|
573 | - * @throws InvalidInterfaceException |
|
574 | - * @throws ReflectionException |
|
575 | - */ |
|
576 | - public function admin_init() |
|
577 | - { |
|
578 | - |
|
579 | - /** |
|
580 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
581 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
582 | - * - check if doing post processing. |
|
583 | - * - check if doing post processing of one of EE CPTs |
|
584 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
585 | - */ |
|
586 | - if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
587 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
588 | - EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
594 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
595 | - * Pages" tab in the EE General Settings Admin page. |
|
596 | - * This is for user-proofing. |
|
597 | - */ |
|
598 | - add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
604 | - * |
|
605 | - * @param string $output Current output. |
|
606 | - * @return string |
|
607 | - * @throws InvalidArgumentException |
|
608 | - * @throws InvalidDataTypeException |
|
609 | - * @throws InvalidInterfaceException |
|
610 | - */ |
|
611 | - public function modify_dropdown_pages($output) |
|
612 | - { |
|
613 | - //get critical pages |
|
614 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
615 | - |
|
616 | - //split current output by line break for easier parsing. |
|
617 | - $split_output = explode("\n", $output); |
|
618 | - |
|
619 | - //loop through to remove any critical pages from the array. |
|
620 | - foreach ($critical_pages as $page_id) { |
|
621 | - $needle = 'value="' . $page_id . '"'; |
|
622 | - foreach ($split_output as $key => $haystack) { |
|
623 | - if (strpos($haystack, $needle) !== false) { |
|
624 | - unset($split_output[$key]); |
|
625 | - } |
|
626 | - } |
|
627 | - } |
|
628 | - //replace output with the new contents |
|
629 | - return implode("\n", $split_output); |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * enqueue all admin scripts that need loaded for admin pages |
|
635 | - * |
|
636 | - * @return void |
|
637 | - */ |
|
638 | - public function enqueue_admin_scripts() |
|
639 | - { |
|
640 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
641 | - // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
642 | - // calls. |
|
643 | - wp_enqueue_script( |
|
644 | - 'ee-inject-wp', |
|
645 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
646 | - array('jquery'), |
|
647 | - EVENT_ESPRESSO_VERSION, |
|
648 | - true |
|
649 | - ); |
|
650 | - // register cookie script for future dependencies |
|
651 | - wp_register_script( |
|
652 | - 'jquery-cookie', |
|
653 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
654 | - array('jquery'), |
|
655 | - '2.1', |
|
656 | - true |
|
657 | - ); |
|
658 | - //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
659 | - // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
660 | - if (apply_filters('FHEE_load_joyride', false)) { |
|
661 | - //joyride style |
|
662 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
663 | - wp_register_style( |
|
664 | - 'ee-joyride-css', |
|
665 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
666 | - array('joyride-css'), |
|
667 | - EVENT_ESPRESSO_VERSION |
|
668 | - ); |
|
669 | - wp_register_script( |
|
670 | - 'joyride-modernizr', |
|
671 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
672 | - array(), |
|
673 | - '2.1', |
|
674 | - true |
|
675 | - ); |
|
676 | - //joyride JS |
|
677 | - wp_register_script( |
|
678 | - 'jquery-joyride', |
|
679 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
680 | - array('jquery-cookie', 'joyride-modernizr'), |
|
681 | - '2.1', |
|
682 | - true |
|
683 | - ); |
|
684 | - // wanna go for a joyride? |
|
685 | - wp_enqueue_style('ee-joyride-css'); |
|
686 | - wp_enqueue_script('jquery-joyride'); |
|
687 | - } |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * display_admin_notices |
|
693 | - * |
|
694 | - * @return void |
|
695 | - */ |
|
696 | - public function display_admin_notices() |
|
697 | - { |
|
698 | - echo EE_Error::get_notices(); |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - |
|
703 | - /** |
|
704 | - * @param array $elements |
|
705 | - * @return array |
|
706 | - * @throws EE_Error |
|
707 | - * @throws InvalidArgumentException |
|
708 | - * @throws InvalidDataTypeException |
|
709 | - * @throws InvalidInterfaceException |
|
710 | - */ |
|
711 | - public function dashboard_glance_items($elements) |
|
712 | - { |
|
713 | - $elements = is_array($elements) ? $elements : array($elements); |
|
714 | - $events = EEM_Event::instance()->count(); |
|
715 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
716 | - array('page' => 'espresso_events'), |
|
717 | - admin_url('admin.php') |
|
718 | - ); |
|
719 | - $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
720 | - $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
721 | - $registrations = EEM_Registration::instance()->count( |
|
722 | - array( |
|
723 | - array( |
|
724 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
725 | - ), |
|
726 | - ) |
|
727 | - ); |
|
728 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
729 | - array('page' => 'espresso_registrations'), |
|
730 | - admin_url('admin.php') |
|
731 | - ); |
|
732 | - $items['registrations']['text'] = sprintf( |
|
733 | - _n('%s Registration', '%s Registrations', $registrations), |
|
734 | - number_format_i18n($registrations) |
|
735 | - ); |
|
736 | - $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
737 | - |
|
738 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
739 | - |
|
740 | - foreach ($items as $type => $item_properties) { |
|
741 | - $elements[] = sprintf( |
|
742 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
743 | - $item_properties['url'], |
|
744 | - $item_properties['title'], |
|
745 | - $item_properties['text'] |
|
746 | - ); |
|
747 | - } |
|
748 | - return $elements; |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - /** |
|
753 | - * check_for_invalid_datetime_formats |
|
754 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
755 | - * their selected format can be parsed by PHP |
|
756 | - * |
|
757 | - * @param $value |
|
758 | - * @param $option |
|
759 | - * @throws EE_Error |
|
760 | - * @return string |
|
761 | - */ |
|
762 | - public function check_for_invalid_datetime_formats($value, $option) |
|
763 | - { |
|
764 | - // check for date_format or time_format |
|
765 | - switch ($option) { |
|
766 | - case 'date_format': |
|
767 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
768 | - break; |
|
769 | - case 'time_format': |
|
770 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
771 | - break; |
|
772 | - default: |
|
773 | - $date_time_format = false; |
|
774 | - } |
|
775 | - // do we have a date_time format to check ? |
|
776 | - if ($date_time_format) { |
|
777 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
778 | - |
|
779 | - if (is_array($error_msg)) { |
|
780 | - $msg = '<p>' |
|
781 | - . sprintf( |
|
782 | - esc_html__( |
|
783 | - 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
784 | - 'event_espresso' |
|
785 | - ), |
|
786 | - date($date_time_format), |
|
787 | - $date_time_format |
|
788 | - ) |
|
789 | - . '</p><p><ul>'; |
|
790 | - |
|
791 | - |
|
792 | - foreach ($error_msg as $error) { |
|
793 | - $msg .= '<li>' . $error . '</li>'; |
|
794 | - } |
|
795 | - |
|
796 | - $msg .= '</ul></p><p>' |
|
797 | - . sprintf( |
|
798 | - esc_html__( |
|
799 | - '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
800 | - 'event_espresso' |
|
801 | - ), |
|
802 | - '<span style="color:#D54E21;">', |
|
803 | - '</span>' |
|
804 | - ) |
|
805 | - . '</p>'; |
|
806 | - |
|
807 | - // trigger WP settings error |
|
808 | - add_settings_error( |
|
809 | - 'date_format', |
|
810 | - 'date_format', |
|
811 | - $msg |
|
812 | - ); |
|
813 | - |
|
814 | - // set format to something valid |
|
815 | - switch ($option) { |
|
816 | - case 'date_format': |
|
817 | - $value = 'F j, Y'; |
|
818 | - break; |
|
819 | - case 'time_format': |
|
820 | - $value = 'g:i a'; |
|
821 | - break; |
|
822 | - } |
|
823 | - } |
|
824 | - } |
|
825 | - return $value; |
|
826 | - } |
|
827 | - |
|
828 | - |
|
829 | - /** |
|
830 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
831 | - * |
|
832 | - * @param $content |
|
833 | - * @return string |
|
834 | - */ |
|
835 | - public function its_eSpresso($content) |
|
836 | - { |
|
837 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * espresso_admin_footer |
|
843 | - * |
|
844 | - * @return string |
|
845 | - */ |
|
846 | - public function espresso_admin_footer() |
|
847 | - { |
|
848 | - return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
849 | - } |
|
850 | - |
|
851 | - |
|
852 | - /** |
|
853 | - * static method for registering ee admin page. |
|
854 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
855 | - * |
|
856 | - * @since 4.3.0 |
|
857 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
858 | - * @see EE_Register_Admin_Page::register() |
|
859 | - * @param $page_basename |
|
860 | - * @param $page_path |
|
861 | - * @param array $config |
|
862 | - * @return void |
|
863 | - * @throws EE_Error |
|
864 | - */ |
|
865 | - public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
866 | - { |
|
867 | - EE_Error::doing_it_wrong( |
|
868 | - __METHOD__, |
|
869 | - sprintf( |
|
870 | - esc_html__( |
|
871 | - 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
872 | - 'event_espresso' |
|
873 | - ), |
|
874 | - $page_basename |
|
875 | - ), |
|
876 | - '4.3' |
|
877 | - ); |
|
878 | - if (class_exists('EE_Register_Admin_Page')) { |
|
879 | - $config['page_path'] = $page_path; |
|
880 | - } |
|
881 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - /** |
|
886 | - * @deprecated 4.8.41 |
|
887 | - * @param int $post_ID |
|
888 | - * @param \WP_Post $post |
|
889 | - * @return void |
|
890 | - */ |
|
891 | - public static function parse_post_content_on_save($post_ID, $post) |
|
892 | - { |
|
893 | - EE_Error::doing_it_wrong( |
|
894 | - __METHOD__, |
|
895 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
896 | - '4.8.41' |
|
897 | - ); |
|
898 | - } |
|
899 | - |
|
900 | - |
|
901 | - /** |
|
902 | - * @deprecated 4.8.41 |
|
903 | - * @param $option |
|
904 | - * @param $old_value |
|
905 | - * @param $value |
|
906 | - * @return void |
|
907 | - */ |
|
908 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
909 | - { |
|
910 | - EE_Error::doing_it_wrong( |
|
911 | - __METHOD__, |
|
912 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
913 | - '4.8.41' |
|
914 | - ); |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * @deprecated 4.9.27 |
|
921 | - * @return void |
|
922 | - */ |
|
923 | - public function get_persistent_admin_notices() |
|
924 | - { |
|
925 | - EE_Error::doing_it_wrong( |
|
926 | - __METHOD__, |
|
927 | - sprintf( |
|
928 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
929 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
930 | - ), |
|
931 | - '4.9.27' |
|
932 | - ); |
|
933 | - } |
|
934 | - |
|
935 | - |
|
936 | - |
|
937 | - /** |
|
938 | - * @deprecated 4.9.27 |
|
939 | - * @throws InvalidInterfaceException |
|
940 | - * @throws InvalidDataTypeException |
|
941 | - * @throws DomainException |
|
942 | - */ |
|
943 | - public function dismiss_ee_nag_notice_callback() |
|
944 | - { |
|
945 | - EE_Error::doing_it_wrong( |
|
946 | - __METHOD__, |
|
947 | - sprintf( |
|
948 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
949 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
950 | - ), |
|
951 | - '4.9.27' |
|
952 | - ); |
|
953 | - $this->persistent_admin_notice_manager->dismissNotice(); |
|
954 | - } |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * Returns an array of event archive nav items. |
|
493 | + * |
|
494 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
495 | + * method we use for getting the extra nav menu items |
|
496 | + * @return array |
|
497 | + */ |
|
498 | + private function _get_extra_nav_menu_pages_items() |
|
499 | + { |
|
500 | + $menuitems[] = array( |
|
501 | + 'title' => esc_html__('Event List', 'event_espresso'), |
|
502 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
503 | + 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
504 | + ); |
|
505 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
511 | + * the properties and converts it to the menu item object. |
|
512 | + * |
|
513 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
514 | + * @param $menu_item_values |
|
515 | + * @return stdClass |
|
516 | + */ |
|
517 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
518 | + { |
|
519 | + $menu_item = new stdClass(); |
|
520 | + $keys = array( |
|
521 | + 'ID' => 0, |
|
522 | + 'db_id' => 0, |
|
523 | + 'menu_item_parent' => 0, |
|
524 | + 'object_id' => -1, |
|
525 | + 'post_parent' => 0, |
|
526 | + 'type' => 'custom', |
|
527 | + 'object' => '', |
|
528 | + 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
529 | + 'title' => '', |
|
530 | + 'url' => '', |
|
531 | + 'target' => '', |
|
532 | + 'attr_title' => '', |
|
533 | + 'description' => '', |
|
534 | + 'classes' => array(), |
|
535 | + 'xfn' => '', |
|
536 | + ); |
|
537 | + |
|
538 | + foreach ($keys as $key => $value) { |
|
539 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
540 | + } |
|
541 | + return $menu_item; |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
547 | + * EE_Admin_Page route is called. |
|
548 | + * |
|
549 | + * @return void |
|
550 | + */ |
|
551 | + public function route_admin_request() |
|
552 | + { |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
558 | + * |
|
559 | + * @return void |
|
560 | + */ |
|
561 | + public function wp_loaded() |
|
562 | + { |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * admin_init |
|
568 | + * |
|
569 | + * @return void |
|
570 | + * @throws EE_Error |
|
571 | + * @throws InvalidArgumentException |
|
572 | + * @throws InvalidDataTypeException |
|
573 | + * @throws InvalidInterfaceException |
|
574 | + * @throws ReflectionException |
|
575 | + */ |
|
576 | + public function admin_init() |
|
577 | + { |
|
578 | + |
|
579 | + /** |
|
580 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
581 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
582 | + * - check if doing post processing. |
|
583 | + * - check if doing post processing of one of EE CPTs |
|
584 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
585 | + */ |
|
586 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
587 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
588 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
594 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
595 | + * Pages" tab in the EE General Settings Admin page. |
|
596 | + * This is for user-proofing. |
|
597 | + */ |
|
598 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
604 | + * |
|
605 | + * @param string $output Current output. |
|
606 | + * @return string |
|
607 | + * @throws InvalidArgumentException |
|
608 | + * @throws InvalidDataTypeException |
|
609 | + * @throws InvalidInterfaceException |
|
610 | + */ |
|
611 | + public function modify_dropdown_pages($output) |
|
612 | + { |
|
613 | + //get critical pages |
|
614 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
615 | + |
|
616 | + //split current output by line break for easier parsing. |
|
617 | + $split_output = explode("\n", $output); |
|
618 | + |
|
619 | + //loop through to remove any critical pages from the array. |
|
620 | + foreach ($critical_pages as $page_id) { |
|
621 | + $needle = 'value="' . $page_id . '"'; |
|
622 | + foreach ($split_output as $key => $haystack) { |
|
623 | + if (strpos($haystack, $needle) !== false) { |
|
624 | + unset($split_output[$key]); |
|
625 | + } |
|
626 | + } |
|
627 | + } |
|
628 | + //replace output with the new contents |
|
629 | + return implode("\n", $split_output); |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * enqueue all admin scripts that need loaded for admin pages |
|
635 | + * |
|
636 | + * @return void |
|
637 | + */ |
|
638 | + public function enqueue_admin_scripts() |
|
639 | + { |
|
640 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
641 | + // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
642 | + // calls. |
|
643 | + wp_enqueue_script( |
|
644 | + 'ee-inject-wp', |
|
645 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
646 | + array('jquery'), |
|
647 | + EVENT_ESPRESSO_VERSION, |
|
648 | + true |
|
649 | + ); |
|
650 | + // register cookie script for future dependencies |
|
651 | + wp_register_script( |
|
652 | + 'jquery-cookie', |
|
653 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
654 | + array('jquery'), |
|
655 | + '2.1', |
|
656 | + true |
|
657 | + ); |
|
658 | + //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
659 | + // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
660 | + if (apply_filters('FHEE_load_joyride', false)) { |
|
661 | + //joyride style |
|
662 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
663 | + wp_register_style( |
|
664 | + 'ee-joyride-css', |
|
665 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
666 | + array('joyride-css'), |
|
667 | + EVENT_ESPRESSO_VERSION |
|
668 | + ); |
|
669 | + wp_register_script( |
|
670 | + 'joyride-modernizr', |
|
671 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
672 | + array(), |
|
673 | + '2.1', |
|
674 | + true |
|
675 | + ); |
|
676 | + //joyride JS |
|
677 | + wp_register_script( |
|
678 | + 'jquery-joyride', |
|
679 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
680 | + array('jquery-cookie', 'joyride-modernizr'), |
|
681 | + '2.1', |
|
682 | + true |
|
683 | + ); |
|
684 | + // wanna go for a joyride? |
|
685 | + wp_enqueue_style('ee-joyride-css'); |
|
686 | + wp_enqueue_script('jquery-joyride'); |
|
687 | + } |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * display_admin_notices |
|
693 | + * |
|
694 | + * @return void |
|
695 | + */ |
|
696 | + public function display_admin_notices() |
|
697 | + { |
|
698 | + echo EE_Error::get_notices(); |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + |
|
703 | + /** |
|
704 | + * @param array $elements |
|
705 | + * @return array |
|
706 | + * @throws EE_Error |
|
707 | + * @throws InvalidArgumentException |
|
708 | + * @throws InvalidDataTypeException |
|
709 | + * @throws InvalidInterfaceException |
|
710 | + */ |
|
711 | + public function dashboard_glance_items($elements) |
|
712 | + { |
|
713 | + $elements = is_array($elements) ? $elements : array($elements); |
|
714 | + $events = EEM_Event::instance()->count(); |
|
715 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
716 | + array('page' => 'espresso_events'), |
|
717 | + admin_url('admin.php') |
|
718 | + ); |
|
719 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
720 | + $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
721 | + $registrations = EEM_Registration::instance()->count( |
|
722 | + array( |
|
723 | + array( |
|
724 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
725 | + ), |
|
726 | + ) |
|
727 | + ); |
|
728 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
729 | + array('page' => 'espresso_registrations'), |
|
730 | + admin_url('admin.php') |
|
731 | + ); |
|
732 | + $items['registrations']['text'] = sprintf( |
|
733 | + _n('%s Registration', '%s Registrations', $registrations), |
|
734 | + number_format_i18n($registrations) |
|
735 | + ); |
|
736 | + $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
737 | + |
|
738 | + $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
739 | + |
|
740 | + foreach ($items as $type => $item_properties) { |
|
741 | + $elements[] = sprintf( |
|
742 | + '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
743 | + $item_properties['url'], |
|
744 | + $item_properties['title'], |
|
745 | + $item_properties['text'] |
|
746 | + ); |
|
747 | + } |
|
748 | + return $elements; |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + /** |
|
753 | + * check_for_invalid_datetime_formats |
|
754 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
755 | + * their selected format can be parsed by PHP |
|
756 | + * |
|
757 | + * @param $value |
|
758 | + * @param $option |
|
759 | + * @throws EE_Error |
|
760 | + * @return string |
|
761 | + */ |
|
762 | + public function check_for_invalid_datetime_formats($value, $option) |
|
763 | + { |
|
764 | + // check for date_format or time_format |
|
765 | + switch ($option) { |
|
766 | + case 'date_format': |
|
767 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
768 | + break; |
|
769 | + case 'time_format': |
|
770 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
771 | + break; |
|
772 | + default: |
|
773 | + $date_time_format = false; |
|
774 | + } |
|
775 | + // do we have a date_time format to check ? |
|
776 | + if ($date_time_format) { |
|
777 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
778 | + |
|
779 | + if (is_array($error_msg)) { |
|
780 | + $msg = '<p>' |
|
781 | + . sprintf( |
|
782 | + esc_html__( |
|
783 | + 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
784 | + 'event_espresso' |
|
785 | + ), |
|
786 | + date($date_time_format), |
|
787 | + $date_time_format |
|
788 | + ) |
|
789 | + . '</p><p><ul>'; |
|
790 | + |
|
791 | + |
|
792 | + foreach ($error_msg as $error) { |
|
793 | + $msg .= '<li>' . $error . '</li>'; |
|
794 | + } |
|
795 | + |
|
796 | + $msg .= '</ul></p><p>' |
|
797 | + . sprintf( |
|
798 | + esc_html__( |
|
799 | + '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
800 | + 'event_espresso' |
|
801 | + ), |
|
802 | + '<span style="color:#D54E21;">', |
|
803 | + '</span>' |
|
804 | + ) |
|
805 | + . '</p>'; |
|
806 | + |
|
807 | + // trigger WP settings error |
|
808 | + add_settings_error( |
|
809 | + 'date_format', |
|
810 | + 'date_format', |
|
811 | + $msg |
|
812 | + ); |
|
813 | + |
|
814 | + // set format to something valid |
|
815 | + switch ($option) { |
|
816 | + case 'date_format': |
|
817 | + $value = 'F j, Y'; |
|
818 | + break; |
|
819 | + case 'time_format': |
|
820 | + $value = 'g:i a'; |
|
821 | + break; |
|
822 | + } |
|
823 | + } |
|
824 | + } |
|
825 | + return $value; |
|
826 | + } |
|
827 | + |
|
828 | + |
|
829 | + /** |
|
830 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
831 | + * |
|
832 | + * @param $content |
|
833 | + * @return string |
|
834 | + */ |
|
835 | + public function its_eSpresso($content) |
|
836 | + { |
|
837 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * espresso_admin_footer |
|
843 | + * |
|
844 | + * @return string |
|
845 | + */ |
|
846 | + public function espresso_admin_footer() |
|
847 | + { |
|
848 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
849 | + } |
|
850 | + |
|
851 | + |
|
852 | + /** |
|
853 | + * static method for registering ee admin page. |
|
854 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
855 | + * |
|
856 | + * @since 4.3.0 |
|
857 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
858 | + * @see EE_Register_Admin_Page::register() |
|
859 | + * @param $page_basename |
|
860 | + * @param $page_path |
|
861 | + * @param array $config |
|
862 | + * @return void |
|
863 | + * @throws EE_Error |
|
864 | + */ |
|
865 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
866 | + { |
|
867 | + EE_Error::doing_it_wrong( |
|
868 | + __METHOD__, |
|
869 | + sprintf( |
|
870 | + esc_html__( |
|
871 | + 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
872 | + 'event_espresso' |
|
873 | + ), |
|
874 | + $page_basename |
|
875 | + ), |
|
876 | + '4.3' |
|
877 | + ); |
|
878 | + if (class_exists('EE_Register_Admin_Page')) { |
|
879 | + $config['page_path'] = $page_path; |
|
880 | + } |
|
881 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + /** |
|
886 | + * @deprecated 4.8.41 |
|
887 | + * @param int $post_ID |
|
888 | + * @param \WP_Post $post |
|
889 | + * @return void |
|
890 | + */ |
|
891 | + public static function parse_post_content_on_save($post_ID, $post) |
|
892 | + { |
|
893 | + EE_Error::doing_it_wrong( |
|
894 | + __METHOD__, |
|
895 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
896 | + '4.8.41' |
|
897 | + ); |
|
898 | + } |
|
899 | + |
|
900 | + |
|
901 | + /** |
|
902 | + * @deprecated 4.8.41 |
|
903 | + * @param $option |
|
904 | + * @param $old_value |
|
905 | + * @param $value |
|
906 | + * @return void |
|
907 | + */ |
|
908 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
909 | + { |
|
910 | + EE_Error::doing_it_wrong( |
|
911 | + __METHOD__, |
|
912 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
913 | + '4.8.41' |
|
914 | + ); |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * @deprecated 4.9.27 |
|
921 | + * @return void |
|
922 | + */ |
|
923 | + public function get_persistent_admin_notices() |
|
924 | + { |
|
925 | + EE_Error::doing_it_wrong( |
|
926 | + __METHOD__, |
|
927 | + sprintf( |
|
928 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
929 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
930 | + ), |
|
931 | + '4.9.27' |
|
932 | + ); |
|
933 | + } |
|
934 | + |
|
935 | + |
|
936 | + |
|
937 | + /** |
|
938 | + * @deprecated 4.9.27 |
|
939 | + * @throws InvalidInterfaceException |
|
940 | + * @throws InvalidDataTypeException |
|
941 | + * @throws DomainException |
|
942 | + */ |
|
943 | + public function dismiss_ee_nag_notice_callback() |
|
944 | + { |
|
945 | + EE_Error::doing_it_wrong( |
|
946 | + __METHOD__, |
|
947 | + sprintf( |
|
948 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
949 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
950 | + ), |
|
951 | + '4.9.27' |
|
952 | + ); |
|
953 | + $this->persistent_admin_notice_manager->dismissNotice(); |
|
954 | + } |
|
955 | 955 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public static function instance() |
41 | 41 | { |
42 | 42 | // check if class object is instantiated |
43 | - if (! self::$_instance instanceof EE_Admin) { |
|
43 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
44 | 44 | self::$_instance = new self(); |
45 | 45 | } |
46 | 46 | return self::$_instance; |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | */ |
101 | 101 | private function _define_all_constants() |
102 | 102 | { |
103 | - if (! defined('EE_ADMIN_URL')) { |
|
104 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
105 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
106 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
107 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
103 | + if ( ! defined('EE_ADMIN_URL')) { |
|
104 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
105 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
106 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
107 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
108 | 108 | define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
109 | 109 | } |
110 | 110 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | // set $main_file in stone |
123 | 123 | static $main_file; |
124 | 124 | // if $main_file is not set yet |
125 | - if (! $main_file) { |
|
125 | + if ( ! $main_file) { |
|
126 | 126 | $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
127 | 127 | } |
128 | 128 | if ($plugin === $main_file) { |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
176 | 176 | { |
177 | 177 | return array( |
178 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
179 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
180 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
178 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
179 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
180 | + 'support' => EE_ADMIN_PAGES.'support'.DS, |
|
181 | 181 | ); |
182 | 182 | } |
183 | 183 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
220 | 220 | } |
221 | 221 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
222 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
222 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
223 | 223 | try { |
224 | 224 | //this loads the controller for the admin pages which will setup routing etc |
225 | 225 | EE_Registry::instance()->load_core('Admin_Page_Loader'); |
@@ -267,13 +267,13 @@ discard block |
||
267 | 267 | '</strong>', |
268 | 268 | '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
269 | 269 | '</a>', |
270 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
270 | + '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
271 | 271 | array( |
272 | 272 | 'page' => 'espresso_maintenance_settings', |
273 | 273 | 'action' => 'datetime_tools' |
274 | 274 | ), |
275 | 275 | admin_url('admin.php') |
276 | - ) . '">' |
|
276 | + ).'">' |
|
277 | 277 | ), |
278 | 278 | false, |
279 | 279 | 'manage_options', |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | public function enable_hidden_ee_nav_menu_metaboxes() |
322 | 322 | { |
323 | 323 | global $wp_meta_boxes, $pagenow; |
324 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
324 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
325 | 325 | return; |
326 | 326 | } |
327 | 327 | $user = wp_get_current_user(); |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | */ |
393 | 393 | public function modify_edit_post_link($link, $id) |
394 | 394 | { |
395 | - if (! $post = get_post($id)) { |
|
395 | + if ( ! $post = get_post($id)) { |
|
396 | 396 | return $link; |
397 | 397 | } |
398 | 398 | if ($post->post_type === 'espresso_attendees') { |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | |
619 | 619 | //loop through to remove any critical pages from the array. |
620 | 620 | foreach ($critical_pages as $page_id) { |
621 | - $needle = 'value="' . $page_id . '"'; |
|
621 | + $needle = 'value="'.$page_id.'"'; |
|
622 | 622 | foreach ($split_output as $key => $haystack) { |
623 | 623 | if (strpos($haystack, $needle) !== false) { |
624 | 624 | unset($split_output[$key]); |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | // calls. |
643 | 643 | wp_enqueue_script( |
644 | 644 | 'ee-inject-wp', |
645 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
645 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
646 | 646 | array('jquery'), |
647 | 647 | EVENT_ESPRESSO_VERSION, |
648 | 648 | true |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | // register cookie script for future dependencies |
651 | 651 | wp_register_script( |
652 | 652 | 'jquery-cookie', |
653 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
653 | + EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', |
|
654 | 654 | array('jquery'), |
655 | 655 | '2.1', |
656 | 656 | true |
@@ -659,16 +659,16 @@ discard block |
||
659 | 659 | // via: add_filter('FHEE_load_joyride', '__return_true' ); |
660 | 660 | if (apply_filters('FHEE_load_joyride', false)) { |
661 | 661 | //joyride style |
662 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
662 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
663 | 663 | wp_register_style( |
664 | 664 | 'ee-joyride-css', |
665 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
665 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
666 | 666 | array('joyride-css'), |
667 | 667 | EVENT_ESPRESSO_VERSION |
668 | 668 | ); |
669 | 669 | wp_register_script( |
670 | 670 | 'joyride-modernizr', |
671 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
671 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
672 | 672 | array(), |
673 | 673 | '2.1', |
674 | 674 | true |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | //joyride JS |
677 | 677 | wp_register_script( |
678 | 678 | 'jquery-joyride', |
679 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
679 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
680 | 680 | array('jquery-cookie', 'joyride-modernizr'), |
681 | 681 | '2.1', |
682 | 682 | true |
@@ -725,21 +725,21 @@ discard block |
||
725 | 725 | ), |
726 | 726 | ) |
727 | 727 | ); |
728 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
728 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
729 | 729 | array('page' => 'espresso_registrations'), |
730 | 730 | admin_url('admin.php') |
731 | 731 | ); |
732 | - $items['registrations']['text'] = sprintf( |
|
732 | + $items['registrations']['text'] = sprintf( |
|
733 | 733 | _n('%s Registration', '%s Registrations', $registrations), |
734 | 734 | number_format_i18n($registrations) |
735 | 735 | ); |
736 | 736 | $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
737 | 737 | |
738 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
738 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
739 | 739 | |
740 | 740 | foreach ($items as $type => $item_properties) { |
741 | 741 | $elements[] = sprintf( |
742 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
742 | + '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', |
|
743 | 743 | $item_properties['url'], |
744 | 744 | $item_properties['title'], |
745 | 745 | $item_properties['text'] |
@@ -764,10 +764,10 @@ discard block |
||
764 | 764 | // check for date_format or time_format |
765 | 765 | switch ($option) { |
766 | 766 | case 'date_format': |
767 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
767 | + $date_time_format = $value.' '.get_option('time_format'); |
|
768 | 768 | break; |
769 | 769 | case 'time_format': |
770 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
770 | + $date_time_format = get_option('date_format').' '.$value; |
|
771 | 771 | break; |
772 | 772 | default: |
773 | 773 | $date_time_format = false; |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | |
791 | 791 | |
792 | 792 | foreach ($error_msg as $error) { |
793 | - $msg .= '<li>' . $error . '</li>'; |
|
793 | + $msg .= '<li>'.$error.'</li>'; |
|
794 | 794 | } |
795 | 795 | |
796 | 796 | $msg .= '</ul></p><p>' |
@@ -21,581 +21,581 @@ |
||
21 | 21 | class EE_Payment_Method_Manager implements ResettableInterface |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * prefix added to all payment method capabilities names |
|
26 | - */ |
|
27 | - const CAPABILITIES_PREFIX= 'ee_payment_method_'; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var EE_Payment_Method_Manager $_instance |
|
31 | - */ |
|
32 | - private static $_instance; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var boolean |
|
36 | - */ |
|
37 | - protected $payment_method_caps_initialized = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var array keys are class names without 'EE_PMT_', values are their filepaths |
|
41 | - */ |
|
42 | - protected $_payment_method_types = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * @var EE_PMT_Base[] |
|
46 | - */ |
|
47 | - protected $payment_method_objects = array(); |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * EE_Payment_Method_Manager constructor. |
|
53 | - * |
|
54 | - * @throws EE_Error |
|
55 | - * @throws DomainException |
|
56 | - */ |
|
57 | - public function __construct() |
|
58 | - { |
|
59 | - // if in admin lets ensure caps are set. |
|
60 | - if (is_admin()) { |
|
61 | - $this->_register_payment_methods(); |
|
62 | - // set them immediately |
|
63 | - $this->initializePaymentMethodCaps(); |
|
64 | - // plus any time they get reset |
|
65 | - add_filter( |
|
66 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
67 | - array($this, 'addPaymentMethodCapsDuringReset') |
|
68 | - ); |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @singleton method used to instantiate class object |
|
76 | - * @return EE_Payment_Method_Manager instance |
|
77 | - * @throws DomainException |
|
78 | - * @throws EE_Error |
|
79 | - */ |
|
80 | - public static function instance() |
|
81 | - { |
|
82 | - // check if class object is instantiated, and instantiated properly |
|
83 | - if (! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
84 | - EE_Registry::instance()->load_lib('PMT_Base'); |
|
85 | - self::$_instance = new self(); |
|
86 | - } |
|
87 | - return self::$_instance; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Resets the instance and returns a new one |
|
94 | - * |
|
95 | - * @return EE_Payment_Method_Manager |
|
96 | - * @throws DomainException |
|
97 | - * @throws EE_Error |
|
98 | - */ |
|
99 | - public static function reset() |
|
100 | - { |
|
101 | - self::$_instance = null; |
|
102 | - return self::instance(); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * If necessary, re-register payment methods |
|
109 | - * |
|
110 | - * @param boolean $force_recheck whether to recheck for payment method types, |
|
111 | - * or just re-use the PMTs we found last time we checked during this request (if |
|
112 | - * we have not yet checked during this request, then we need to check anyways) |
|
113 | - */ |
|
114 | - public function maybe_register_payment_methods($force_recheck = false) |
|
115 | - { |
|
116 | - if (! $this->_payment_method_types || $force_recheck) { |
|
117 | - $this->_register_payment_methods(); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * register_payment_methods |
|
125 | - * |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - protected function _register_payment_methods() |
|
129 | - { |
|
130 | - // grab list of installed modules |
|
131 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
132 | - // filter list of modules to register |
|
133 | - $pm_to_register = apply_filters( |
|
134 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
135 | - $pm_to_register |
|
136 | - ); |
|
137 | - // remove any duplicates if that should happen for some reason |
|
138 | - $pm_to_register = array_unique($pm_to_register); |
|
139 | - // loop through folders |
|
140 | - foreach ($pm_to_register as $pm_path) { |
|
141 | - $this->register_payment_method($pm_path); |
|
142 | - } |
|
143 | - do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
144 | - // filter list of installed modules |
|
145 | - //keep them organized alphabetically by the payment method type's name |
|
146 | - ksort($this->_payment_method_types); |
|
147 | - return apply_filters( |
|
148 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
149 | - $this->_payment_method_types |
|
150 | - ); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * register_payment_method- makes core aware of this payment method |
|
157 | - * |
|
158 | - * @param string $payment_method_path - full path up to and including payment method folder |
|
159 | - * @return boolean |
|
160 | - */ |
|
161 | - public function register_payment_method($payment_method_path = '') |
|
162 | - { |
|
163 | - do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
164 | - $module_ext = '.pm.php'; |
|
165 | - // make all separators match |
|
166 | - $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
167 | - // grab and sanitize module name |
|
168 | - $module_dir = basename($payment_method_path); |
|
169 | - // create class name from module directory name |
|
170 | - $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir); |
|
171 | - // add class prefix |
|
172 | - $module_class = 'EE_PMT_' . $module; |
|
173 | - // does the module exist ? |
|
174 | - if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
175 | - $msg = sprintf( |
|
176 | - esc_html__( |
|
177 | - 'The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
178 | - 'event_espresso' |
|
179 | - ), $module |
|
180 | - ); |
|
181 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
182 | - return false; |
|
183 | - } |
|
184 | - // load the module class file |
|
185 | - require_once($payment_method_path . DS . $module_class . $module_ext); |
|
186 | - // verify that class exists |
|
187 | - if (! class_exists($module_class)) { |
|
188 | - $msg = sprintf( |
|
189 | - esc_html__('The requested %s module class does not exist.', 'event_espresso'), |
|
190 | - $module_class |
|
191 | - ); |
|
192 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
193 | - return false; |
|
194 | - } |
|
195 | - // add to array of registered modules |
|
196 | - $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
197 | - return true; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * Checks if a payment method has been registered, and if so includes it |
|
204 | - * |
|
205 | - * @param string $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_') |
|
206 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
207 | - * @return boolean |
|
208 | - */ |
|
209 | - public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
210 | - { |
|
211 | - if ( |
|
212 | - $force_recheck |
|
213 | - || ! is_array($this->_payment_method_types) |
|
214 | - || ! isset($this->_payment_method_types[$payment_method_name]) |
|
215 | - ) { |
|
216 | - $this->maybe_register_payment_methods($force_recheck); |
|
217 | - } |
|
218 | - if (isset($this->_payment_method_types[$payment_method_name])) { |
|
219 | - require_once($this->_payment_method_types[$payment_method_name]); |
|
220 | - return true; |
|
221 | - } |
|
222 | - return false; |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * Returns all the class names of the various payment method types |
|
229 | - * |
|
230 | - * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names' |
|
231 | - * (what you'd find in wp_esp_payment_method.PMD_type) |
|
232 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
233 | - * @return array |
|
234 | - */ |
|
235 | - public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
236 | - { |
|
237 | - $this->maybe_register_payment_methods($force_recheck); |
|
238 | - if ($with_prefixes) { |
|
239 | - $classnames = array_keys($this->_payment_method_types); |
|
240 | - $payment_methods = array(); |
|
241 | - foreach ($classnames as $classname) { |
|
242 | - $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
243 | - } |
|
244 | - return $payment_methods; |
|
245 | - } |
|
246 | - return array_keys($this->_payment_method_types); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Gets an object of each payment method type, none of which are bound to a |
|
253 | - * payment method instance |
|
254 | - * |
|
255 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
256 | - * @return EE_PMT_Base[] |
|
257 | - */ |
|
258 | - public function payment_method_types($force_recheck = false) |
|
259 | - { |
|
260 | - if ($force_recheck || empty($this->payment_method_objects)) { |
|
261 | - $this->maybe_register_payment_methods($force_recheck); |
|
262 | - foreach ($this->payment_method_type_names(true) as $classname) { |
|
263 | - if (! isset($this->payment_method_objects[$classname])) { |
|
264 | - $this->payment_method_objects[$classname] = new $classname; |
|
265 | - } |
|
266 | - } |
|
267 | - } |
|
268 | - return $this->payment_method_objects; |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Changes the payment method's class name into the payment method type's name |
|
275 | - * (as used on the payment method's table's PMD_type field) |
|
276 | - * |
|
277 | - * @param string $classname |
|
278 | - * @return string |
|
279 | - */ |
|
280 | - public function payment_method_type_sans_class_prefix($classname) |
|
281 | - { |
|
282 | - return str_replace('EE_PMT_', '', $classname); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * Does the opposite of payment-method_type_sans_prefix |
|
289 | - * |
|
290 | - * @param string $type |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - public function payment_method_class_from_type($type) |
|
294 | - { |
|
295 | - return 'EE_PMT_' . $type; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * Activates a payment method of the given type. |
|
302 | - * |
|
303 | - * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
304 | - * @return EE_Payment_Method |
|
305 | - * @throws InvalidDataTypeException |
|
306 | - * @throws EE_Error |
|
307 | - */ |
|
308 | - public function activate_a_payment_method_of_type($payment_method_type) |
|
309 | - { |
|
310 | - $this->maybe_register_payment_methods(); |
|
311 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
312 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
313 | - $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
314 | - if (class_exists($pm_type_class)) { |
|
315 | - /** @var $pm_type_obj EE_PMT_Base */ |
|
316 | - $pm_type_obj = new $pm_type_class; |
|
317 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
318 | - if (! $payment_method) { |
|
319 | - $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
320 | - } |
|
321 | - $payment_method->set_type($payment_method_type); |
|
322 | - $this->initialize_payment_method($payment_method); |
|
323 | - } else { |
|
324 | - throw new EE_Error( |
|
325 | - sprintf( |
|
326 | - esc_html__( |
|
327 | - 'There is no payment method of type %1$s, so it could not be activated', |
|
328 | - 'event_espresso' |
|
329 | - ), |
|
330 | - $pm_type_class |
|
331 | - ) |
|
332 | - ); |
|
333 | - } |
|
334 | - } |
|
335 | - $payment_method->set_active(); |
|
336 | - $payment_method->save(); |
|
337 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
338 | - //if this was the invoice message type, make sure users can view their invoices |
|
339 | - if ($payment_method->type() === 'Invoice' |
|
340 | - && ( |
|
341 | - ! EEH_MSG_Template::is_mt_active('invoice') |
|
342 | - ) |
|
343 | - ) { |
|
344 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
345 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
346 | - $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
347 | - new PersistentAdminNotice( |
|
348 | - 'invoice_pm_requirements_notice', |
|
349 | - sprintf( |
|
350 | - esc_html__( |
|
351 | - 'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.', |
|
352 | - 'event_espresso' |
|
353 | - ), |
|
354 | - '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">', |
|
355 | - '</a>' |
|
356 | - ), |
|
357 | - true |
|
358 | - ); |
|
359 | - } |
|
360 | - return $payment_method; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * Creates a payment method of the specified type. Does not save it. |
|
367 | - * |
|
368 | - * @global WP_User $current_user |
|
369 | - * @param EE_PMT_Base $pm_type_obj |
|
370 | - * @return EE_Payment_Method |
|
371 | - * @throws EE_Error |
|
372 | - */ |
|
373 | - public function create_payment_method_of_type($pm_type_obj) |
|
374 | - { |
|
375 | - global $current_user; |
|
376 | - $payment_method = EE_Payment_Method::new_instance( |
|
377 | - array( |
|
378 | - 'PMD_type' => $pm_type_obj->system_name(), |
|
379 | - 'PMD_name' => $pm_type_obj->pretty_name(), |
|
380 | - 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
381 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
382 | - 'PMD_wp_user' => $current_user->ID, |
|
383 | - 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
384 | - array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
385 | - ) * 10, |
|
386 | - ) |
|
387 | - ); |
|
388 | - return $payment_method; |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * Sets the initial payment method properties (including extra meta) |
|
395 | - * |
|
396 | - * @param EE_Payment_Method $payment_method |
|
397 | - * @return EE_Payment_Method |
|
398 | - * @throws EE_Error |
|
399 | - */ |
|
400 | - public function initialize_payment_method($payment_method) |
|
401 | - { |
|
402 | - $pm_type_obj = $payment_method->type_obj(); |
|
403 | - $payment_method->set_description($pm_type_obj->default_description()); |
|
404 | - if (! $payment_method->button_url()) { |
|
405 | - $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
406 | - } |
|
407 | - //now add setup its default extra meta properties |
|
408 | - $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
409 | - if (! empty($extra_metas)) { |
|
410 | - //verify the payment method has an ID before adding extra meta |
|
411 | - if (! $payment_method->ID()) { |
|
412 | - $payment_method->save(); |
|
413 | - } |
|
414 | - foreach ($extra_metas as $meta_name => $input) { |
|
415 | - $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
416 | - } |
|
417 | - } |
|
418 | - return $payment_method; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * Makes sure the payment method is related to the specified payment method |
|
425 | - * |
|
426 | - * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
427 | - * @param EE_Payment_Method $payment_method |
|
428 | - * @return EE_Payment_Method |
|
429 | - * @throws EE_Error |
|
430 | - */ |
|
431 | - public function set_usable_currencies_on_payment_method($payment_method) |
|
432 | - { |
|
433 | - EE_Error::doing_it_wrong( |
|
434 | - 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
435 | - esc_html__( |
|
436 | - 'We no longer define what currencies are usable by payment methods. Its not used nor efficient.', |
|
437 | - 'event_espresso' |
|
438 | - ), |
|
439 | - '4.9.40' |
|
440 | - ); |
|
441 | - return $payment_method; |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * Deactivates a payment method of the given payment method slug. |
|
448 | - * |
|
449 | - * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
450 | - * @return int count of rows updated. |
|
451 | - * @throws EE_Error |
|
452 | - */ |
|
453 | - public function deactivate_payment_method($payment_method_slug) |
|
454 | - { |
|
455 | - EE_Log::instance()->log( |
|
456 | - __FILE__, |
|
457 | - __FUNCTION__, |
|
458 | - sprintf( |
|
459 | - esc_html__( |
|
460 | - 'Payment method with slug %1$s is being deactivated by site admin', |
|
461 | - 'event_espresso' |
|
462 | - ), |
|
463 | - $payment_method_slug |
|
464 | - ), |
|
465 | - 'payment_method_change' |
|
466 | - ); |
|
467 | - $count_updated = EEM_Payment_Method::instance()->update( |
|
468 | - array('PMD_scope' => array()), |
|
469 | - array(array('PMD_slug' => $payment_method_slug)) |
|
470 | - ); |
|
471 | - do_action( |
|
472 | - 'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method', |
|
473 | - $payment_method_slug, |
|
474 | - $count_updated |
|
475 | - ); |
|
476 | - return $count_updated; |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * initializes payment method access caps via EE_Capabilities::init_role_caps() |
|
483 | - * upon EE_Payment_Method_Manager construction |
|
484 | - * |
|
485 | - * @throws EE_Error |
|
486 | - * @throws DomainException |
|
487 | - */ |
|
488 | - protected function initializePaymentMethodCaps() |
|
489 | - { |
|
490 | - // don't do this twice |
|
491 | - if ($this->payment_method_caps_initialized) { |
|
492 | - return; |
|
493 | - } |
|
494 | - EE_Capabilities::instance()->addCaps( |
|
495 | - $this->getPaymentMethodCaps() |
|
496 | - ); |
|
497 | - $this->payment_method_caps_initialized = true; |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * array of dynamic payment method access caps. |
|
504 | - * at the time of writing, october 20 2014, these are the caps added: |
|
505 | - * ee_payment_method_admin_only |
|
506 | - * ee_payment_method_aim |
|
507 | - * ee_payment_method_bank |
|
508 | - * ee_payment_method_check |
|
509 | - * ee_payment_method_invoice |
|
510 | - * ee_payment_method_mijireh |
|
511 | - * ee_payment_method_paypal_pro |
|
512 | - * ee_payment_method_paypal_standard |
|
513 | - * Any other payment methods added to core or via addons will also get |
|
514 | - * their related capability automatically added too, so long as they are |
|
515 | - * registered properly using EE_Register_Payment_Method::register() |
|
516 | - * |
|
517 | - * @return array |
|
518 | - * @throws DomainException |
|
519 | - */ |
|
520 | - protected function getPaymentMethodCaps() |
|
521 | - { |
|
522 | - $caps = array(); |
|
523 | - foreach ($this->payment_method_type_names() as $payment_method_name) { |
|
524 | - $caps = $this->addPaymentMethodCap($payment_method_name,$caps); |
|
525 | - } |
|
526 | - return $caps; |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - |
|
531 | - /** |
|
532 | - * @param string $payment_method_name |
|
533 | - * @param array $payment_method_caps |
|
534 | - * @param string $role |
|
535 | - * @return array |
|
536 | - * @throws DomainException |
|
537 | - */ |
|
538 | - public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator') |
|
539 | - { |
|
540 | - if (empty($payment_method_name)) { |
|
541 | - throw new DomainException( |
|
542 | - esc_html__( |
|
543 | - 'The name of a payment method must be specified to add capabilities.', |
|
544 | - 'event_espresso' |
|
545 | - ) |
|
546 | - ); |
|
547 | - } |
|
548 | - if (empty($role)) { |
|
549 | - throw new DomainException( |
|
550 | - sprintf( |
|
551 | - esc_html__( |
|
552 | - 'No role was supplied while trying to add capabilities for the %1$s payment method.', |
|
553 | - 'event_espresso' |
|
554 | - ), |
|
555 | - $payment_method_name |
|
556 | - ) |
|
557 | - ); |
|
558 | - } |
|
559 | - if(! isset($payment_method_caps[$role])) { |
|
560 | - $payment_method_caps[$role] = array(); |
|
561 | - } |
|
562 | - $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX |
|
563 | - . strtolower($payment_method_name); |
|
564 | - return $payment_method_caps; |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter |
|
571 | - * to add dynamic payment method access caps when capabilities are reset |
|
572 | - * (or if that filter is called and PM caps are not already set) |
|
573 | - * |
|
574 | - * @param array $caps capabilities being filtered |
|
575 | - * @param bool $reset |
|
576 | - * @return array |
|
577 | - * @throws DomainException |
|
578 | - */ |
|
579 | - public function addPaymentMethodCapsDuringReset(array $caps, $reset = false) |
|
580 | - { |
|
581 | - if ($reset || ! $this->payment_method_caps_initialized) { |
|
582 | - $this->payment_method_caps_initialized = true; |
|
583 | - $caps = array_merge_recursive($caps, $this->getPaymentMethodCaps()); |
|
584 | - } |
|
585 | - return $caps; |
|
586 | - } |
|
587 | - |
|
588 | - |
|
589 | - |
|
590 | - /** |
|
591 | - * @deprecated 4.9.42 |
|
592 | - * @param $caps |
|
593 | - * @return mixed |
|
594 | - */ |
|
595 | - public function add_payment_method_caps($caps) |
|
596 | - { |
|
597 | - return $caps; |
|
598 | - } |
|
24 | + /** |
|
25 | + * prefix added to all payment method capabilities names |
|
26 | + */ |
|
27 | + const CAPABILITIES_PREFIX= 'ee_payment_method_'; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var EE_Payment_Method_Manager $_instance |
|
31 | + */ |
|
32 | + private static $_instance; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var boolean |
|
36 | + */ |
|
37 | + protected $payment_method_caps_initialized = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var array keys are class names without 'EE_PMT_', values are their filepaths |
|
41 | + */ |
|
42 | + protected $_payment_method_types = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * @var EE_PMT_Base[] |
|
46 | + */ |
|
47 | + protected $payment_method_objects = array(); |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * EE_Payment_Method_Manager constructor. |
|
53 | + * |
|
54 | + * @throws EE_Error |
|
55 | + * @throws DomainException |
|
56 | + */ |
|
57 | + public function __construct() |
|
58 | + { |
|
59 | + // if in admin lets ensure caps are set. |
|
60 | + if (is_admin()) { |
|
61 | + $this->_register_payment_methods(); |
|
62 | + // set them immediately |
|
63 | + $this->initializePaymentMethodCaps(); |
|
64 | + // plus any time they get reset |
|
65 | + add_filter( |
|
66 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
67 | + array($this, 'addPaymentMethodCapsDuringReset') |
|
68 | + ); |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @singleton method used to instantiate class object |
|
76 | + * @return EE_Payment_Method_Manager instance |
|
77 | + * @throws DomainException |
|
78 | + * @throws EE_Error |
|
79 | + */ |
|
80 | + public static function instance() |
|
81 | + { |
|
82 | + // check if class object is instantiated, and instantiated properly |
|
83 | + if (! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
84 | + EE_Registry::instance()->load_lib('PMT_Base'); |
|
85 | + self::$_instance = new self(); |
|
86 | + } |
|
87 | + return self::$_instance; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Resets the instance and returns a new one |
|
94 | + * |
|
95 | + * @return EE_Payment_Method_Manager |
|
96 | + * @throws DomainException |
|
97 | + * @throws EE_Error |
|
98 | + */ |
|
99 | + public static function reset() |
|
100 | + { |
|
101 | + self::$_instance = null; |
|
102 | + return self::instance(); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * If necessary, re-register payment methods |
|
109 | + * |
|
110 | + * @param boolean $force_recheck whether to recheck for payment method types, |
|
111 | + * or just re-use the PMTs we found last time we checked during this request (if |
|
112 | + * we have not yet checked during this request, then we need to check anyways) |
|
113 | + */ |
|
114 | + public function maybe_register_payment_methods($force_recheck = false) |
|
115 | + { |
|
116 | + if (! $this->_payment_method_types || $force_recheck) { |
|
117 | + $this->_register_payment_methods(); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * register_payment_methods |
|
125 | + * |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + protected function _register_payment_methods() |
|
129 | + { |
|
130 | + // grab list of installed modules |
|
131 | + $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
132 | + // filter list of modules to register |
|
133 | + $pm_to_register = apply_filters( |
|
134 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
135 | + $pm_to_register |
|
136 | + ); |
|
137 | + // remove any duplicates if that should happen for some reason |
|
138 | + $pm_to_register = array_unique($pm_to_register); |
|
139 | + // loop through folders |
|
140 | + foreach ($pm_to_register as $pm_path) { |
|
141 | + $this->register_payment_method($pm_path); |
|
142 | + } |
|
143 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
144 | + // filter list of installed modules |
|
145 | + //keep them organized alphabetically by the payment method type's name |
|
146 | + ksort($this->_payment_method_types); |
|
147 | + return apply_filters( |
|
148 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
149 | + $this->_payment_method_types |
|
150 | + ); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * register_payment_method- makes core aware of this payment method |
|
157 | + * |
|
158 | + * @param string $payment_method_path - full path up to and including payment method folder |
|
159 | + * @return boolean |
|
160 | + */ |
|
161 | + public function register_payment_method($payment_method_path = '') |
|
162 | + { |
|
163 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
164 | + $module_ext = '.pm.php'; |
|
165 | + // make all separators match |
|
166 | + $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
167 | + // grab and sanitize module name |
|
168 | + $module_dir = basename($payment_method_path); |
|
169 | + // create class name from module directory name |
|
170 | + $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir); |
|
171 | + // add class prefix |
|
172 | + $module_class = 'EE_PMT_' . $module; |
|
173 | + // does the module exist ? |
|
174 | + if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
175 | + $msg = sprintf( |
|
176 | + esc_html__( |
|
177 | + 'The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
178 | + 'event_espresso' |
|
179 | + ), $module |
|
180 | + ); |
|
181 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
182 | + return false; |
|
183 | + } |
|
184 | + // load the module class file |
|
185 | + require_once($payment_method_path . DS . $module_class . $module_ext); |
|
186 | + // verify that class exists |
|
187 | + if (! class_exists($module_class)) { |
|
188 | + $msg = sprintf( |
|
189 | + esc_html__('The requested %s module class does not exist.', 'event_espresso'), |
|
190 | + $module_class |
|
191 | + ); |
|
192 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
193 | + return false; |
|
194 | + } |
|
195 | + // add to array of registered modules |
|
196 | + $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
197 | + return true; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * Checks if a payment method has been registered, and if so includes it |
|
204 | + * |
|
205 | + * @param string $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_') |
|
206 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
207 | + * @return boolean |
|
208 | + */ |
|
209 | + public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
210 | + { |
|
211 | + if ( |
|
212 | + $force_recheck |
|
213 | + || ! is_array($this->_payment_method_types) |
|
214 | + || ! isset($this->_payment_method_types[$payment_method_name]) |
|
215 | + ) { |
|
216 | + $this->maybe_register_payment_methods($force_recheck); |
|
217 | + } |
|
218 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
219 | + require_once($this->_payment_method_types[$payment_method_name]); |
|
220 | + return true; |
|
221 | + } |
|
222 | + return false; |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * Returns all the class names of the various payment method types |
|
229 | + * |
|
230 | + * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names' |
|
231 | + * (what you'd find in wp_esp_payment_method.PMD_type) |
|
232 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
233 | + * @return array |
|
234 | + */ |
|
235 | + public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
236 | + { |
|
237 | + $this->maybe_register_payment_methods($force_recheck); |
|
238 | + if ($with_prefixes) { |
|
239 | + $classnames = array_keys($this->_payment_method_types); |
|
240 | + $payment_methods = array(); |
|
241 | + foreach ($classnames as $classname) { |
|
242 | + $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
243 | + } |
|
244 | + return $payment_methods; |
|
245 | + } |
|
246 | + return array_keys($this->_payment_method_types); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Gets an object of each payment method type, none of which are bound to a |
|
253 | + * payment method instance |
|
254 | + * |
|
255 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
256 | + * @return EE_PMT_Base[] |
|
257 | + */ |
|
258 | + public function payment_method_types($force_recheck = false) |
|
259 | + { |
|
260 | + if ($force_recheck || empty($this->payment_method_objects)) { |
|
261 | + $this->maybe_register_payment_methods($force_recheck); |
|
262 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
263 | + if (! isset($this->payment_method_objects[$classname])) { |
|
264 | + $this->payment_method_objects[$classname] = new $classname; |
|
265 | + } |
|
266 | + } |
|
267 | + } |
|
268 | + return $this->payment_method_objects; |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Changes the payment method's class name into the payment method type's name |
|
275 | + * (as used on the payment method's table's PMD_type field) |
|
276 | + * |
|
277 | + * @param string $classname |
|
278 | + * @return string |
|
279 | + */ |
|
280 | + public function payment_method_type_sans_class_prefix($classname) |
|
281 | + { |
|
282 | + return str_replace('EE_PMT_', '', $classname); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * Does the opposite of payment-method_type_sans_prefix |
|
289 | + * |
|
290 | + * @param string $type |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + public function payment_method_class_from_type($type) |
|
294 | + { |
|
295 | + return 'EE_PMT_' . $type; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * Activates a payment method of the given type. |
|
302 | + * |
|
303 | + * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
304 | + * @return EE_Payment_Method |
|
305 | + * @throws InvalidDataTypeException |
|
306 | + * @throws EE_Error |
|
307 | + */ |
|
308 | + public function activate_a_payment_method_of_type($payment_method_type) |
|
309 | + { |
|
310 | + $this->maybe_register_payment_methods(); |
|
311 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
312 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
313 | + $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
314 | + if (class_exists($pm_type_class)) { |
|
315 | + /** @var $pm_type_obj EE_PMT_Base */ |
|
316 | + $pm_type_obj = new $pm_type_class; |
|
317 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
318 | + if (! $payment_method) { |
|
319 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
320 | + } |
|
321 | + $payment_method->set_type($payment_method_type); |
|
322 | + $this->initialize_payment_method($payment_method); |
|
323 | + } else { |
|
324 | + throw new EE_Error( |
|
325 | + sprintf( |
|
326 | + esc_html__( |
|
327 | + 'There is no payment method of type %1$s, so it could not be activated', |
|
328 | + 'event_espresso' |
|
329 | + ), |
|
330 | + $pm_type_class |
|
331 | + ) |
|
332 | + ); |
|
333 | + } |
|
334 | + } |
|
335 | + $payment_method->set_active(); |
|
336 | + $payment_method->save(); |
|
337 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
338 | + //if this was the invoice message type, make sure users can view their invoices |
|
339 | + if ($payment_method->type() === 'Invoice' |
|
340 | + && ( |
|
341 | + ! EEH_MSG_Template::is_mt_active('invoice') |
|
342 | + ) |
|
343 | + ) { |
|
344 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
345 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
346 | + $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
347 | + new PersistentAdminNotice( |
|
348 | + 'invoice_pm_requirements_notice', |
|
349 | + sprintf( |
|
350 | + esc_html__( |
|
351 | + 'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.', |
|
352 | + 'event_espresso' |
|
353 | + ), |
|
354 | + '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">', |
|
355 | + '</a>' |
|
356 | + ), |
|
357 | + true |
|
358 | + ); |
|
359 | + } |
|
360 | + return $payment_method; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * Creates a payment method of the specified type. Does not save it. |
|
367 | + * |
|
368 | + * @global WP_User $current_user |
|
369 | + * @param EE_PMT_Base $pm_type_obj |
|
370 | + * @return EE_Payment_Method |
|
371 | + * @throws EE_Error |
|
372 | + */ |
|
373 | + public function create_payment_method_of_type($pm_type_obj) |
|
374 | + { |
|
375 | + global $current_user; |
|
376 | + $payment_method = EE_Payment_Method::new_instance( |
|
377 | + array( |
|
378 | + 'PMD_type' => $pm_type_obj->system_name(), |
|
379 | + 'PMD_name' => $pm_type_obj->pretty_name(), |
|
380 | + 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
381 | + 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
382 | + 'PMD_wp_user' => $current_user->ID, |
|
383 | + 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
384 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
385 | + ) * 10, |
|
386 | + ) |
|
387 | + ); |
|
388 | + return $payment_method; |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * Sets the initial payment method properties (including extra meta) |
|
395 | + * |
|
396 | + * @param EE_Payment_Method $payment_method |
|
397 | + * @return EE_Payment_Method |
|
398 | + * @throws EE_Error |
|
399 | + */ |
|
400 | + public function initialize_payment_method($payment_method) |
|
401 | + { |
|
402 | + $pm_type_obj = $payment_method->type_obj(); |
|
403 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
404 | + if (! $payment_method->button_url()) { |
|
405 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
406 | + } |
|
407 | + //now add setup its default extra meta properties |
|
408 | + $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
409 | + if (! empty($extra_metas)) { |
|
410 | + //verify the payment method has an ID before adding extra meta |
|
411 | + if (! $payment_method->ID()) { |
|
412 | + $payment_method->save(); |
|
413 | + } |
|
414 | + foreach ($extra_metas as $meta_name => $input) { |
|
415 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
416 | + } |
|
417 | + } |
|
418 | + return $payment_method; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * Makes sure the payment method is related to the specified payment method |
|
425 | + * |
|
426 | + * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
427 | + * @param EE_Payment_Method $payment_method |
|
428 | + * @return EE_Payment_Method |
|
429 | + * @throws EE_Error |
|
430 | + */ |
|
431 | + public function set_usable_currencies_on_payment_method($payment_method) |
|
432 | + { |
|
433 | + EE_Error::doing_it_wrong( |
|
434 | + 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
435 | + esc_html__( |
|
436 | + 'We no longer define what currencies are usable by payment methods. Its not used nor efficient.', |
|
437 | + 'event_espresso' |
|
438 | + ), |
|
439 | + '4.9.40' |
|
440 | + ); |
|
441 | + return $payment_method; |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * Deactivates a payment method of the given payment method slug. |
|
448 | + * |
|
449 | + * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
450 | + * @return int count of rows updated. |
|
451 | + * @throws EE_Error |
|
452 | + */ |
|
453 | + public function deactivate_payment_method($payment_method_slug) |
|
454 | + { |
|
455 | + EE_Log::instance()->log( |
|
456 | + __FILE__, |
|
457 | + __FUNCTION__, |
|
458 | + sprintf( |
|
459 | + esc_html__( |
|
460 | + 'Payment method with slug %1$s is being deactivated by site admin', |
|
461 | + 'event_espresso' |
|
462 | + ), |
|
463 | + $payment_method_slug |
|
464 | + ), |
|
465 | + 'payment_method_change' |
|
466 | + ); |
|
467 | + $count_updated = EEM_Payment_Method::instance()->update( |
|
468 | + array('PMD_scope' => array()), |
|
469 | + array(array('PMD_slug' => $payment_method_slug)) |
|
470 | + ); |
|
471 | + do_action( |
|
472 | + 'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method', |
|
473 | + $payment_method_slug, |
|
474 | + $count_updated |
|
475 | + ); |
|
476 | + return $count_updated; |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * initializes payment method access caps via EE_Capabilities::init_role_caps() |
|
483 | + * upon EE_Payment_Method_Manager construction |
|
484 | + * |
|
485 | + * @throws EE_Error |
|
486 | + * @throws DomainException |
|
487 | + */ |
|
488 | + protected function initializePaymentMethodCaps() |
|
489 | + { |
|
490 | + // don't do this twice |
|
491 | + if ($this->payment_method_caps_initialized) { |
|
492 | + return; |
|
493 | + } |
|
494 | + EE_Capabilities::instance()->addCaps( |
|
495 | + $this->getPaymentMethodCaps() |
|
496 | + ); |
|
497 | + $this->payment_method_caps_initialized = true; |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * array of dynamic payment method access caps. |
|
504 | + * at the time of writing, october 20 2014, these are the caps added: |
|
505 | + * ee_payment_method_admin_only |
|
506 | + * ee_payment_method_aim |
|
507 | + * ee_payment_method_bank |
|
508 | + * ee_payment_method_check |
|
509 | + * ee_payment_method_invoice |
|
510 | + * ee_payment_method_mijireh |
|
511 | + * ee_payment_method_paypal_pro |
|
512 | + * ee_payment_method_paypal_standard |
|
513 | + * Any other payment methods added to core or via addons will also get |
|
514 | + * their related capability automatically added too, so long as they are |
|
515 | + * registered properly using EE_Register_Payment_Method::register() |
|
516 | + * |
|
517 | + * @return array |
|
518 | + * @throws DomainException |
|
519 | + */ |
|
520 | + protected function getPaymentMethodCaps() |
|
521 | + { |
|
522 | + $caps = array(); |
|
523 | + foreach ($this->payment_method_type_names() as $payment_method_name) { |
|
524 | + $caps = $this->addPaymentMethodCap($payment_method_name,$caps); |
|
525 | + } |
|
526 | + return $caps; |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + |
|
531 | + /** |
|
532 | + * @param string $payment_method_name |
|
533 | + * @param array $payment_method_caps |
|
534 | + * @param string $role |
|
535 | + * @return array |
|
536 | + * @throws DomainException |
|
537 | + */ |
|
538 | + public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator') |
|
539 | + { |
|
540 | + if (empty($payment_method_name)) { |
|
541 | + throw new DomainException( |
|
542 | + esc_html__( |
|
543 | + 'The name of a payment method must be specified to add capabilities.', |
|
544 | + 'event_espresso' |
|
545 | + ) |
|
546 | + ); |
|
547 | + } |
|
548 | + if (empty($role)) { |
|
549 | + throw new DomainException( |
|
550 | + sprintf( |
|
551 | + esc_html__( |
|
552 | + 'No role was supplied while trying to add capabilities for the %1$s payment method.', |
|
553 | + 'event_espresso' |
|
554 | + ), |
|
555 | + $payment_method_name |
|
556 | + ) |
|
557 | + ); |
|
558 | + } |
|
559 | + if(! isset($payment_method_caps[$role])) { |
|
560 | + $payment_method_caps[$role] = array(); |
|
561 | + } |
|
562 | + $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX |
|
563 | + . strtolower($payment_method_name); |
|
564 | + return $payment_method_caps; |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter |
|
571 | + * to add dynamic payment method access caps when capabilities are reset |
|
572 | + * (or if that filter is called and PM caps are not already set) |
|
573 | + * |
|
574 | + * @param array $caps capabilities being filtered |
|
575 | + * @param bool $reset |
|
576 | + * @return array |
|
577 | + * @throws DomainException |
|
578 | + */ |
|
579 | + public function addPaymentMethodCapsDuringReset(array $caps, $reset = false) |
|
580 | + { |
|
581 | + if ($reset || ! $this->payment_method_caps_initialized) { |
|
582 | + $this->payment_method_caps_initialized = true; |
|
583 | + $caps = array_merge_recursive($caps, $this->getPaymentMethodCaps()); |
|
584 | + } |
|
585 | + return $caps; |
|
586 | + } |
|
587 | + |
|
588 | + |
|
589 | + |
|
590 | + /** |
|
591 | + * @deprecated 4.9.42 |
|
592 | + * @param $caps |
|
593 | + * @return mixed |
|
594 | + */ |
|
595 | + public function add_payment_method_caps($caps) |
|
596 | + { |
|
597 | + return $caps; |
|
598 | + } |
|
599 | 599 | |
600 | 600 | |
601 | 601 |
@@ -294,15 +294,15 @@ discard block |
||
294 | 294 | |
295 | 295 | |
296 | 296 | |
297 | - /** |
|
298 | - * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
299 | - * but also verifies the payment method type of each is a usable object. If not, |
|
300 | - * deactivate it, sets a notification, and deactivates it |
|
301 | - * |
|
302 | - * @param array $rows |
|
303 | - * @return EE_Payment_Method[] |
|
304 | - * @throws InvalidDataTypeException |
|
305 | - */ |
|
297 | + /** |
|
298 | + * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
299 | + * but also verifies the payment method type of each is a usable object. If not, |
|
300 | + * deactivate it, sets a notification, and deactivates it |
|
301 | + * |
|
302 | + * @param array $rows |
|
303 | + * @return EE_Payment_Method[] |
|
304 | + * @throws InvalidDataTypeException |
|
305 | + */ |
|
306 | 306 | protected function _create_objects( $rows = array() ) { |
307 | 307 | EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
308 | 308 | $payment_methods = parent::_create_objects( $rows ); |
@@ -319,22 +319,22 @@ discard block |
||
319 | 319 | //only deactivate and notify the admin if the payment is active somewhere |
320 | 320 | $payment_method->deactivate(); |
321 | 321 | $payment_method->save(); |
322 | - do_action( |
|
323 | - 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
324 | - $payment_method |
|
325 | - ); |
|
326 | - new PersistentAdminNotice( |
|
327 | - 'auto-deactivated-' . $payment_method->type(), |
|
328 | - sprintf( |
|
329 | - __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
330 | - 'event_espresso'), |
|
331 | - $payment_method->admin_name(), |
|
332 | - '<br />', |
|
333 | - '<a href="' . admin_url('plugins.php') . '">', |
|
334 | - '</a>' |
|
335 | - ), |
|
336 | - true |
|
337 | - ); |
|
322 | + do_action( |
|
323 | + 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
324 | + $payment_method |
|
325 | + ); |
|
326 | + new PersistentAdminNotice( |
|
327 | + 'auto-deactivated-' . $payment_method->type(), |
|
328 | + sprintf( |
|
329 | + __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
330 | + 'event_espresso'), |
|
331 | + $payment_method->admin_name(), |
|
332 | + '<br />', |
|
333 | + '<a href="' . admin_url('plugins.php') . '">', |
|
334 | + '</a>' |
|
335 | + ), |
|
336 | + true |
|
337 | + ); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | return $usable_payment_methods; |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice; |
2 | 2 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | /** |
8 | 8 | * |
@@ -40,33 +40,33 @@ discard block |
||
40 | 40 | * @access protected |
41 | 41 | * @return EEM_Payment_Method |
42 | 42 | */ |
43 | - protected function __construct( $timezone = NULL ) { |
|
44 | - $this->singlular_item = __( 'Payment Method', 'event_espresso' ); |
|
45 | - $this->plural_item = __( 'Payment Methods', 'event_espresso' ); |
|
46 | - $this->_tables = array( 'Payment_Method' => new EE_Primary_Table( 'esp_payment_method', 'PMD_ID' ) ); |
|
43 | + protected function __construct($timezone = NULL) { |
|
44 | + $this->singlular_item = __('Payment Method', 'event_espresso'); |
|
45 | + $this->plural_item = __('Payment Methods', 'event_espresso'); |
|
46 | + $this->_tables = array('Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID')); |
|
47 | 47 | $this->_fields = array( |
48 | 48 | 'Payment_Method' => array( |
49 | - 'PMD_ID' => new EE_Primary_Key_Int_Field( 'PMD_ID', __( "ID", 'event_espresso' ) ), |
|
50 | - 'PMD_type' => new EE_Plain_Text_Field( 'PMD_type', __( "Payment Method Type", 'event_espresso' ), FALSE, 'Admin_Only' ), |
|
51 | - 'PMD_name' => new EE_Plain_Text_Field( 'PMD_name', __( "Name", 'event_espresso' ), FALSE ), |
|
52 | - 'PMD_desc' => new EE_Post_Content_Field( 'PMD_desc', __( "Description", 'event_espresso' ), FALSE, '' ), |
|
53 | - 'PMD_admin_name' => new EE_Plain_Text_Field( 'PMD_admin_name', __( "Admin-Only Name", 'event_espresso' ), TRUE ), |
|
54 | - 'PMD_admin_desc' => new EE_Post_Content_Field( 'PMD_admin_desc', __( "Admin-Only Description", 'event_espresso' ), TRUE ), |
|
55 | - 'PMD_slug' => new EE_Slug_Field( 'PMD_slug', __( "Slug", 'event_espresso' ), FALSE ), |
|
56 | - 'PMD_order' => new EE_Integer_Field( 'PMD_order', __( "Order", 'event_espresso' ), FALSE, 0 ), |
|
57 | - 'PMD_debug_mode' => new EE_Boolean_Field( 'PMD_debug_mode', __( "Debug Mode On?", 'event_espresso' ), FALSE, FALSE ), |
|
58 | - 'PMD_wp_user' => new EE_WP_User_Field( 'PMD_wp_user', __( "Payment Method Creator ID", 'event_espresso' ), FALSE ), |
|
59 | - 'PMD_open_by_default' => new EE_Boolean_Field( 'PMD_open_by_default', __( "Open by Default?", 'event_espresso' ), FALSE, FALSE ), 'PMD_button_url' => new EE_Plain_Text_Field( 'PMD_button_url', __( "Button URL", 'event_espresso' ), TRUE, '' ), |
|
60 | - 'PMD_scope' => new EE_Serialized_Text_Field( 'PMD_scope', __( "Usable From?", 'event_espresso' ), FALSE, array() ), //possible values currently are 'CART','ADMIN','API' |
|
49 | + 'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')), |
|
50 | + 'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), FALSE, 'Admin_Only'), |
|
51 | + 'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), FALSE), |
|
52 | + 'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), FALSE, ''), |
|
53 | + 'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), TRUE), |
|
54 | + 'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), TRUE), |
|
55 | + 'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), FALSE), |
|
56 | + 'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), FALSE, 0), |
|
57 | + 'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), FALSE, FALSE), |
|
58 | + 'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), FALSE), |
|
59 | + 'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), FALSE, FALSE), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), TRUE, ''), |
|
60 | + 'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), FALSE, array()), //possible values currently are 'CART','ADMIN','API' |
|
61 | 61 | ) ); |
62 | 62 | $this->_model_relations = array( |
63 | 63 | // 'Event'=>new EE_HABTM_Relation('Event_Payment_Method'), |
64 | 64 | 'Payment' => new EE_Has_Many_Relation(), |
65 | - 'Currency' => new EE_HABTM_Relation( 'Currency_Payment_Method' ), |
|
65 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
66 | 66 | 'Transaction' => new EE_Has_Many_Relation(), |
67 | 67 | 'WP_User' => new EE_Belongs_To_Relation(), |
68 | 68 | ); |
69 | - parent::__construct( $timezone ); |
|
69 | + parent::__construct($timezone); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @param string $slug |
77 | 77 | * @return EE_Payment_Method |
78 | 78 | */ |
79 | - public function get_one_by_slug( $slug ) { |
|
80 | - return $this->get_one( array( array( 'PMD_slug' => $slug ) ) ); |
|
79 | + public function get_one_by_slug($slug) { |
|
80 | + return $this->get_one(array(array('PMD_slug' => $slug))); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | return apply_filters( |
92 | 92 | 'FHEE__EEM_Payment_Method__scopes', |
93 | 93 | array( |
94 | - self::scope_cart => __( "Front-end Registration Page", 'event_espresso' ), |
|
95 | - self::scope_admin => __( "Admin Registration Page (no online processing)", 'event_espresso' ) |
|
94 | + self::scope_cart => __("Front-end Registration Page", 'event_espresso'), |
|
95 | + self::scope_admin => __("Admin Registration Page (no online processing)", 'event_espresso') |
|
96 | 96 | ) |
97 | 97 | ); |
98 | 98 | } |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
105 | 105 | * @return boolean |
106 | 106 | */ |
107 | - public function is_valid_scope( $scope ) { |
|
107 | + public function is_valid_scope($scope) { |
|
108 | 108 | $scopes = $this->scopes(); |
109 | - if ( isset( $scopes[ $scope ] ) ) { |
|
109 | + if (isset($scopes[$scope])) { |
|
110 | 110 | return TRUE; |
111 | 111 | } else { |
112 | 112 | return FALSE; |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | * @throws EE_Error |
123 | 123 | * @return EE_Payment_Method[] |
124 | 124 | */ |
125 | - public function get_all_active( $scope = NULL, $query_params = array() ) { |
|
126 | - if( ! isset( $query_params[ 'order_by' ] ) && ! isset( $query_params[ 'order' ] ) ) { |
|
127 | - $query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' ); |
|
125 | + public function get_all_active($scope = NULL, $query_params = array()) { |
|
126 | + if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
127 | + $query_params['order_by'] = array('PMD_order' => 'ASC', 'PMD_ID' => 'ASC'); |
|
128 | 128 | } |
129 | - return $this->get_all( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
129 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | * @param array $query_params |
136 | 136 | * @return int |
137 | 137 | */ |
138 | - public function count_active( $scope = NULL, $query_params = array() ){ |
|
139 | - return $this->count( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
138 | + public function count_active($scope = NULL, $query_params = array()) { |
|
139 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -147,21 +147,21 @@ discard block |
||
147 | 147 | * @return array like param of EEM_Base::get_all() |
148 | 148 | * @throws EE_Error |
149 | 149 | */ |
150 | - protected function _get_query_params_for_all_active( $scope = NULL, $query_params = array() ){ |
|
151 | - if ( $scope ) { |
|
152 | - if ( $this->is_valid_scope( $scope ) ) { |
|
153 | - return array_replace_recursive( array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params ); |
|
150 | + protected function _get_query_params_for_all_active($scope = NULL, $query_params = array()) { |
|
151 | + if ($scope) { |
|
152 | + if ($this->is_valid_scope($scope)) { |
|
153 | + return array_replace_recursive(array(array('PMD_scope' => array('LIKE', "%$scope%"))), $query_params); |
|
154 | 154 | } else { |
155 | - throw new EE_Error( sprintf( __( "'%s' is not a valid scope for a payment method", "event_espresso" ), $scope ) ); |
|
155 | + throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope)); |
|
156 | 156 | } |
157 | 157 | } else { |
158 | 158 | $acceptable_scopes = array(); |
159 | 159 | $count = 0; |
160 | - foreach ( $this->scopes() as $scope_name => $desc ) { |
|
160 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
161 | 161 | $count++; |
162 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' ); |
|
162 | + $acceptable_scopes['PMD_scope*'.$count] = array('LIKE', '%'.$scope_name.'%'); |
|
163 | 163 | } |
164 | - return array_replace_recursive( array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params ); |
|
164 | + return array_replace_recursive(array(array('OR*active_scope' => $acceptable_scopes)), $query_params); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * @return array like param of EEM_Base::get_all() |
174 | 174 | * @throws EE_Error |
175 | 175 | */ |
176 | - public function get_query_params_for_all_active( $scope = NULL, $query_params = array() ) { |
|
177 | - return $this->_get_query_params_for_all_active( $scope, $query_params ); |
|
176 | + public function get_query_params_for_all_active($scope = NULL, $query_params = array()) { |
|
177 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @param array $query_params |
185 | 185 | * @return EE_Payment_Method |
186 | 186 | */ |
187 | - public function get_one_active( $scope = NULL, $query_params = array() ) { |
|
188 | - return $this->get_one( $this->_get_query_params_for_all_active( $scope, $query_params ) ); |
|
187 | + public function get_one_active($scope = NULL, $query_params = array()) { |
|
188 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | * @param string $type |
196 | 196 | * @return EE_Payment_Method |
197 | 197 | */ |
198 | - public function get_one_of_type( $type ) { |
|
199 | - return $this->get_one( array( array( 'PMD_type' => $type ) ) ); |
|
198 | + public function get_one_of_type($type) { |
|
199 | + return $this->get_one(array(array('PMD_type' => $type))); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -209,22 +209,22 @@ discard block |
||
209 | 209 | * @return EE_Payment_Method |
210 | 210 | * @throws EE_Error |
211 | 211 | */ |
212 | - public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ) { |
|
212 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) { |
|
213 | 213 | //first: check if it's a slug |
214 | - if( is_string( $base_class_obj_or_id ) ) { |
|
215 | - $obj = $this->get_one_by_slug( $base_class_obj_or_id ); |
|
216 | - if( $obj ) { |
|
214 | + if (is_string($base_class_obj_or_id)) { |
|
215 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
216 | + if ($obj) { |
|
217 | 217 | return $obj; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | //ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
221 | 221 | try { |
222 | - return parent::ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db ); |
|
222 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
223 | 223 | } |
224 | - catch ( EE_Error $e ) { |
|
224 | + catch (EE_Error $e) { |
|
225 | 225 | //handle it outside the catch |
226 | 226 | } |
227 | - throw new EE_Error( sprintf( __( "'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso" ), $base_class_obj_or_id ) ); |
|
227 | + throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id)); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | |
@@ -235,12 +235,12 @@ discard block |
||
235 | 235 | * @param mixed $base_obj_or_id_or_slug |
236 | 236 | * @return int |
237 | 237 | */ |
238 | - function ensure_is_ID( $base_obj_or_id_or_slug ) { |
|
239 | - if ( is_string( $base_obj_or_id_or_slug ) ) { |
|
238 | + function ensure_is_ID($base_obj_or_id_or_slug) { |
|
239 | + if (is_string($base_obj_or_id_or_slug)) { |
|
240 | 240 | //assume it's a slug |
241 | - $base_obj_or_id_or_slug = $this->get_one_by_slug( $base_obj_or_id_or_slug ); |
|
241 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
242 | 242 | } |
243 | - return parent::ensure_is_ID( $base_obj_or_id_or_slug ); |
|
243 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | |
@@ -249,36 +249,36 @@ discard block |
||
249 | 249 | * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default. |
250 | 250 | * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart |
251 | 251 | */ |
252 | - function verify_button_urls( $payment_methods = NULL ) { |
|
253 | - $payment_methods = is_array( $payment_methods ) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
254 | - foreach ( $payment_methods as $payment_method ) { |
|
252 | + function verify_button_urls($payment_methods = NULL) { |
|
253 | + $payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
254 | + foreach ($payment_methods as $payment_method) { |
|
255 | 255 | try { |
256 | 256 | $current_button_url = $payment_method->button_url(); |
257 | - $buttons_urls_to_try = apply_filters( 'FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
258 | - 'current_ssl' => str_replace( "http://", "https://", $current_button_url ), |
|
259 | - 'current' => str_replace( "https://", "http://", $current_button_url ), |
|
260 | - 'default_ssl' => str_replace( "http://", "https://", $payment_method->type_obj()->default_button_url() ), |
|
261 | - 'default' => str_replace( "https://", "http://", $payment_method->type_obj()->default_button_url() ), |
|
262 | - ) ); |
|
263 | - foreach( $buttons_urls_to_try as $button_url_to_try ) { |
|
264 | - if( |
|
257 | + $buttons_urls_to_try = apply_filters('FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array( |
|
258 | + 'current_ssl' => str_replace("http://", "https://", $current_button_url), |
|
259 | + 'current' => str_replace("https://", "http://", $current_button_url), |
|
260 | + 'default_ssl' => str_replace("http://", "https://", $payment_method->type_obj()->default_button_url()), |
|
261 | + 'default' => str_replace("https://", "http://", $payment_method->type_obj()->default_button_url()), |
|
262 | + )); |
|
263 | + foreach ($buttons_urls_to_try as $button_url_to_try) { |
|
264 | + if ( |
|
265 | 265 | (//this is the current url and it exists, regardless of SSL issues |
266 | 266 | $button_url_to_try == $current_button_url && |
267 | 267 | EEH_URL::remote_file_exists( |
268 | 268 | $button_url_to_try, |
269 | 269 | array( |
270 | 270 | 'sslverify' => false, |
271 | - 'limit_response_size' => 4095,//we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
271 | + 'limit_response_size' => 4095, //we don't really care for a full response, but we do want headers at least. Lets just ask for a one block |
|
272 | 272 | ) ) |
273 | 273 | ) |
274 | 274 | || |
275 | 275 | (//this is NOT the current url and it exists with a working SSL cert |
276 | 276 | $button_url_to_try != $current_button_url && |
277 | - EEH_URL::remote_file_exists( $button_url_to_try ) |
|
277 | + EEH_URL::remote_file_exists($button_url_to_try) |
|
278 | 278 | ) ) { |
279 | - if( $current_button_url != $button_url_to_try ){ |
|
280 | - $payment_method->save( array( 'PMD_button_url' => $button_url_to_try ) ); |
|
281 | - EE_Error::add_attention( sprintf( __( "Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso" ), $payment_method->name(), $button_url_to_try ) ); |
|
279 | + if ($current_button_url != $button_url_to_try) { |
|
280 | + $payment_method->save(array('PMD_button_url' => $button_url_to_try)); |
|
281 | + EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try)); |
|
282 | 282 | } |
283 | 283 | //this image exists. So if wasn't set before, now it is; |
284 | 284 | //or if it was already set, we have nothing to do |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | } |
287 | 287 | } |
288 | 288 | } |
289 | - catch ( EE_Error $e ) { |
|
290 | - $payment_method->set_active( FALSE ); |
|
289 | + catch (EE_Error $e) { |
|
290 | + $payment_method->set_active(FALSE); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | } |
@@ -303,19 +303,19 @@ discard block |
||
303 | 303 | * @return EE_Payment_Method[] |
304 | 304 | * @throws InvalidDataTypeException |
305 | 305 | */ |
306 | - protected function _create_objects( $rows = array() ) { |
|
307 | - EE_Registry::instance()->load_lib( 'Payment_Method_Manager' ); |
|
308 | - $payment_methods = parent::_create_objects( $rows ); |
|
306 | + protected function _create_objects($rows = array()) { |
|
307 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
308 | + $payment_methods = parent::_create_objects($rows); |
|
309 | 309 | /* @var $payment_methods EE_Payment_Method[] */ |
310 | 310 | $usable_payment_methods = array(); |
311 | - foreach ( $payment_methods as $key => $payment_method ) { |
|
312 | - if ( EE_Payment_Method_Manager::instance()->payment_method_type_exists( $payment_method->type() ) ) { |
|
313 | - $usable_payment_methods[ $key ] = $payment_method; |
|
311 | + foreach ($payment_methods as $key => $payment_method) { |
|
312 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
313 | + $usable_payment_methods[$key] = $payment_method; |
|
314 | 314 | //some payment methods enqueue their scripts in EE_PMT_*::__construct |
315 | 315 | //which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
316 | 316 | //its scripts). but for backwards-compat we should continue to do that |
317 | 317 | $payment_method->type_obj(); |
318 | - } elseif( $payment_method->active() ) { |
|
318 | + } elseif ($payment_method->active()) { |
|
319 | 319 | //only deactivate and notify the admin if the payment is active somewhere |
320 | 320 | $payment_method->deactivate(); |
321 | 321 | $payment_method->save(); |
@@ -324,13 +324,13 @@ discard block |
||
324 | 324 | $payment_method |
325 | 325 | ); |
326 | 326 | new PersistentAdminNotice( |
327 | - 'auto-deactivated-' . $payment_method->type(), |
|
327 | + 'auto-deactivated-'.$payment_method->type(), |
|
328 | 328 | sprintf( |
329 | 329 | __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
330 | 330 | 'event_espresso'), |
331 | 331 | $payment_method->admin_name(), |
332 | 332 | '<br />', |
333 | - '<a href="' . admin_url('plugins.php') . '">', |
|
333 | + '<a href="'.admin_url('plugins.php').'">', |
|
334 | 334 | '</a>' |
335 | 335 | ), |
336 | 336 | true |
@@ -350,11 +350,11 @@ discard block |
||
350 | 350 | * @param string $scope @see EEM_Payment_Method::get_all_for_events |
351 | 351 | * @return EE_Payment_Method[] |
352 | 352 | */ |
353 | - public function get_all_for_transaction( $transaction, $scope ) { |
|
353 | + public function get_all_for_transaction($transaction, $scope) { |
|
354 | 354 | //give addons a chance to override what payment methods are chosen based on the transaction |
355 | 355 | return apply_filters( |
356 | 356 | 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
357 | - $this->get_all_active( $scope, array( 'group_by' => 'PMD_type' ) ), |
|
357 | + $this->get_all_active($scope, array('group_by' => 'PMD_type')), |
|
358 | 358 | $transaction, |
359 | 359 | $scope |
360 | 360 | ); |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the registration. |
371 | 371 | * @return EE_Payment|null |
372 | 372 | */ |
373 | - public function get_last_used_for_registration( $registration_or_reg_id ) { |
|
374 | - $registration_id = EEM_Registration::instance()->ensure_is_ID( $registration_or_reg_id ); |
|
373 | + public function get_last_used_for_registration($registration_or_reg_id) { |
|
374 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
375 | 375 | |
376 | 376 | $query_params = array( |
377 | 377 | 0 => array( |
378 | 378 | 'Payment.Registration.REG_ID' => $registration_id, |
379 | 379 | ), |
380 | - 'order_by' => array( 'Payment.PAY_ID' => 'DESC' ) |
|
380 | + 'order_by' => array('Payment.PAY_ID' => 'DESC') |
|
381 | 381 | ); |
382 | - return $this->get_one( $query_params ); |
|
382 | + return $this->get_one($query_params); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | } |