@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | public static function instance() |
33 | 33 | { |
34 | 34 | // check if class object is instantiated |
35 | - if (! self::$_instance instanceof EE_Admin) { |
|
35 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
36 | 36 | self::$_instance = new self(); |
37 | 37 | } |
38 | 38 | return self::$_instance; |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | */ |
92 | 92 | private function _define_all_constants() |
93 | 93 | { |
94 | - if (! defined('EE_ADMIN_URL')) { |
|
95 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
96 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
97 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
98 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
94 | + if ( ! defined('EE_ADMIN_URL')) { |
|
95 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
96 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
97 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
98 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
99 | 99 | define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
100 | 100 | } |
101 | 101 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | // set $main_file in stone |
115 | 115 | static $main_file; |
116 | 116 | // if $main_file is not set yet |
117 | - if (! $main_file) { |
|
117 | + if ( ! $main_file) { |
|
118 | 118 | $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
119 | 119 | } |
120 | 120 | if ($plugin === $main_file) { |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
166 | 166 | { |
167 | 167 | return array( |
168 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
169 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
170 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
168 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
169 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
170 | + 'support' => EE_ADMIN_PAGES.'support'.DS, |
|
171 | 171 | ); |
172 | 172 | } |
173 | 173 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
196 | 196 | } |
197 | 197 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
198 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
198 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
199 | 199 | try { |
200 | 200 | //this loads the controller for the admin pages which will setup routing etc |
201 | 201 | EE_Registry::instance()->load_core('Admin_Page_Loader'); |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | public function enable_hidden_ee_nav_menu_metaboxes() |
248 | 248 | { |
249 | 249 | global $wp_meta_boxes, $pagenow; |
250 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
250 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
251 | 251 | return; |
252 | 252 | } |
253 | 253 | $user = wp_get_current_user(); |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | */ |
319 | 319 | public function modify_edit_post_link($link, $id) |
320 | 320 | { |
321 | - if (! $post = get_post($id)) { |
|
321 | + if ( ! $post = get_post($id)) { |
|
322 | 322 | return $link; |
323 | 323 | } |
324 | 324 | if ($post->post_type === 'espresso_attendees') { |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | |
545 | 545 | //loop through to remove any critical pages from the array. |
546 | 546 | foreach ($critical_pages as $page_id) { |
547 | - $needle = 'value="' . $page_id . '"'; |
|
547 | + $needle = 'value="'.$page_id.'"'; |
|
548 | 548 | foreach ($split_output as $key => $haystack) { |
549 | 549 | if (strpos($haystack, $needle) !== false) { |
550 | 550 | unset($split_output[$key]); |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | // calls. |
571 | 571 | wp_enqueue_script( |
572 | 572 | 'ee-inject-wp', |
573 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
573 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
574 | 574 | array('jquery'), |
575 | 575 | EVENT_ESPRESSO_VERSION, |
576 | 576 | true |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | // register cookie script for future dependencies |
579 | 579 | wp_register_script( |
580 | 580 | 'jquery-cookie', |
581 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
581 | + EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', |
|
582 | 582 | array('jquery'), |
583 | 583 | '2.1', |
584 | 584 | true |
@@ -587,16 +587,16 @@ discard block |
||
587 | 587 | // via: add_filter('FHEE_load_joyride', '__return_true' ); |
588 | 588 | if (apply_filters('FHEE_load_joyride', false)) { |
589 | 589 | //joyride style |
590 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
590 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
591 | 591 | wp_register_style( |
592 | 592 | 'ee-joyride-css', |
593 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
593 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
594 | 594 | array('joyride-css'), |
595 | 595 | EVENT_ESPRESSO_VERSION |
596 | 596 | ); |
597 | 597 | wp_register_script( |
598 | 598 | 'joyride-modernizr', |
599 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
599 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
600 | 600 | array(), |
601 | 601 | '2.1', |
602 | 602 | true |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | //joyride JS |
605 | 605 | wp_register_script( |
606 | 606 | 'jquery-joyride', |
607 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
607 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
608 | 608 | array('jquery-cookie', 'joyride-modernizr'), |
609 | 609 | '2.1', |
610 | 610 | true |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | public function get_persistent_admin_notices() |
658 | 658 | { |
659 | 659 | // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
660 | - $args = array( |
|
660 | + $args = array( |
|
661 | 661 | 'page' => EE_Registry::instance()->REQ->is_set('page') |
662 | 662 | ? EE_Registry::instance()->REQ->get('page') |
663 | 663 | : '', |
@@ -704,21 +704,21 @@ discard block |
||
704 | 704 | ), |
705 | 705 | ) |
706 | 706 | ); |
707 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
707 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
708 | 708 | array('page' => 'espresso_registrations'), |
709 | 709 | admin_url('admin.php') |
710 | 710 | ); |
711 | - $items['registrations']['text'] = sprintf( |
|
711 | + $items['registrations']['text'] = sprintf( |
|
712 | 712 | _n('%s Registration', '%s Registrations', $registrations), |
713 | 713 | number_format_i18n($registrations) |
714 | 714 | ); |
715 | 715 | $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
716 | 716 | |
717 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
717 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
718 | 718 | |
719 | 719 | foreach ($items as $type => $item_properties) { |
720 | 720 | $elements[] = sprintf( |
721 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
721 | + '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', |
|
722 | 722 | $item_properties['url'], |
723 | 723 | $item_properties['title'], |
724 | 724 | $item_properties['text'] |
@@ -744,10 +744,10 @@ discard block |
||
744 | 744 | // check for date_format or time_format |
745 | 745 | switch ($option) { |
746 | 746 | case 'date_format': |
747 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
747 | + $date_time_format = $value.' '.get_option('time_format'); |
|
748 | 748 | break; |
749 | 749 | case 'time_format': |
750 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
750 | + $date_time_format = get_option('date_format').' '.$value; |
|
751 | 751 | break; |
752 | 752 | default: |
753 | 753 | $date_time_format = false; |
@@ -770,7 +770,7 @@ discard block |
||
770 | 770 | |
771 | 771 | |
772 | 772 | foreach ($error_msg as $error) { |
773 | - $msg .= '<li>' . $error . '</li>'; |
|
773 | + $msg .= '<li>'.$error.'</li>'; |
|
774 | 774 | } |
775 | 775 | |
776 | 776 | $msg .= '</ul></p><p>' |
@@ -15,395 +15,395 @@ discard block |
||
15 | 15 | final class EE_Admin implements InterminableInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @access private |
|
20 | - * @var EE_Admin $_instance |
|
21 | - */ |
|
22 | - private static $_instance; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - *@ singleton method used to instantiate class object |
|
27 | - *@ access public |
|
28 | - *@ return class instance |
|
29 | - * |
|
30 | - * @throws \EE_Error |
|
31 | - */ |
|
32 | - public static function instance() |
|
33 | - { |
|
34 | - // check if class object is instantiated |
|
35 | - if (! self::$_instance instanceof EE_Admin) { |
|
36 | - self::$_instance = new self(); |
|
37 | - } |
|
38 | - return self::$_instance; |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @return EE_Admin |
|
44 | - * @throws EE_Error |
|
45 | - */ |
|
46 | - public static function reset() |
|
47 | - { |
|
48 | - self::$_instance = null; |
|
49 | - return self::instance(); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * class constructor |
|
55 | - * |
|
56 | - * @throws \EE_Error |
|
57 | - */ |
|
58 | - protected function __construct() |
|
59 | - { |
|
60 | - // define global EE_Admin constants |
|
61 | - $this->_define_all_constants(); |
|
62 | - // set autoloaders for our admin page classes based on included path information |
|
63 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
64 | - // admin hooks |
|
65 | - add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
66 | - // load EE_Request_Handler early |
|
67 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
68 | - add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
69 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
70 | - add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
71 | - add_action('admin_init', array($this, 'admin_init'), 100); |
|
72 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
73 | - add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
74 | - add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
75 | - add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
76 | - add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
77 | - |
|
78 | - //reset Environment config (we only do this on admin page loads); |
|
79 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
80 | - |
|
81 | - do_action('AHEE__EE_Admin__loaded'); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * _define_all_constants |
|
87 | - * define constants that are set globally for all admin pages |
|
88 | - * |
|
89 | - * @access private |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - private function _define_all_constants() |
|
93 | - { |
|
94 | - if (! defined('EE_ADMIN_URL')) { |
|
95 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
96 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
97 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
98 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
99 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @param array $links |
|
109 | - * @param string $plugin |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function filter_plugin_actions($links, $plugin) |
|
113 | - { |
|
114 | - // set $main_file in stone |
|
115 | - static $main_file; |
|
116 | - // if $main_file is not set yet |
|
117 | - if (! $main_file) { |
|
118 | - $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
119 | - } |
|
120 | - if ($plugin === $main_file) { |
|
121 | - // compare current plugin to this one |
|
122 | - if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
123 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
124 | - . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
125 | - . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
126 | - . '</a>'; |
|
127 | - array_unshift($links, $maintenance_link); |
|
128 | - } else { |
|
129 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
130 | - . esc_html__('Settings', 'event_espresso') |
|
131 | - . '</a>'; |
|
132 | - $events_link = '<a href="admin.php?page=espresso_events">' |
|
133 | - . esc_html__('Events', 'event_espresso') |
|
134 | - . '</a>'; |
|
135 | - // add before other links |
|
136 | - array_unshift($links, $org_settings_link, $events_link); |
|
137 | - } |
|
138 | - } |
|
139 | - return $links; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * _get_request |
|
145 | - * |
|
146 | - * @access public |
|
147 | - * @return void |
|
148 | - * @throws EE_Error |
|
149 | - * @throws ReflectionException |
|
150 | - */ |
|
151 | - public function get_request() |
|
152 | - { |
|
153 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
154 | - EE_Registry::instance()->load_core('CPT_Strategy'); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * hide_admin_pages_except_maintenance_mode |
|
160 | - * |
|
161 | - * @access public |
|
162 | - * @param array $admin_page_folder_names |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
166 | - { |
|
167 | - return array( |
|
168 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
169 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
170 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
171 | - ); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
177 | - * EE_Front_Controller's init phases have run |
|
178 | - * |
|
179 | - * @access public |
|
180 | - * @return void |
|
181 | - * @throws EE_Error |
|
182 | - * @throws ReflectionException |
|
183 | - */ |
|
184 | - public function init() |
|
185 | - { |
|
186 | - //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
187 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
188 | - //ok so we want to enable the entire admin |
|
189 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
190 | - add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
191 | - add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
192 | - //at a glance dashboard widget |
|
193 | - add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
194 | - //filter for get_edit_post_link used on comments for custom post types |
|
195 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
196 | - } |
|
197 | - // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
198 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
199 | - try { |
|
200 | - //this loads the controller for the admin pages which will setup routing etc |
|
201 | - EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
202 | - } catch (EE_Error $e) { |
|
203 | - $e->get_error(); |
|
204 | - } |
|
205 | - } |
|
206 | - add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
207 | - //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
208 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
209 | - add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
210 | - //exclude EE critical pages from all nav menus and wp_list_pages |
|
211 | - add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
217 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
218 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
219 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
220 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
221 | - * |
|
222 | - * @param object $post_type WP post type object |
|
223 | - * @return object WP post type object |
|
224 | - */ |
|
225 | - public function remove_pages_from_nav_menu($post_type) |
|
226 | - { |
|
227 | - //if this isn't the "pages" post type let's get out |
|
228 | - if ($post_type->name !== 'page') { |
|
229 | - return $post_type; |
|
230 | - } |
|
231 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
232 | - |
|
233 | - $post_type->_default_query = array( |
|
234 | - 'post__not_in' => $critical_pages, |
|
235 | - ); |
|
236 | - return $post_type; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
242 | - * metaboxes get shown as well |
|
243 | - * |
|
244 | - * @access public |
|
245 | - * @return void |
|
246 | - */ |
|
247 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
248 | - { |
|
249 | - global $wp_meta_boxes, $pagenow; |
|
250 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
251 | - return; |
|
252 | - } |
|
253 | - $user = wp_get_current_user(); |
|
254 | - //has this been done yet? |
|
255 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
256 | - return; |
|
257 | - } |
|
258 | - |
|
259 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
260 | - $initial_meta_boxes = apply_filters( |
|
261 | - 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
262 | - array( |
|
263 | - 'nav-menu-theme-locations', |
|
264 | - 'add-page', |
|
265 | - 'add-custom-links', |
|
266 | - 'add-category', |
|
267 | - 'add-espresso_events', |
|
268 | - 'add-espresso_venues', |
|
269 | - 'add-espresso_event_categories', |
|
270 | - 'add-espresso_venue_categories', |
|
271 | - 'add-post-type-post', |
|
272 | - 'add-post-type-page', |
|
273 | - ) |
|
274 | - ); |
|
275 | - |
|
276 | - if (is_array($hidden_meta_boxes)) { |
|
277 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
278 | - if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
279 | - unset($hidden_meta_boxes[$key]); |
|
280 | - } |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
285 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
291 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
292 | - * |
|
293 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
294 | - * addons etc. |
|
295 | - * @access public |
|
296 | - * @return void |
|
297 | - */ |
|
298 | - public function register_custom_nav_menu_boxes() |
|
299 | - { |
|
300 | - add_meta_box( |
|
301 | - 'add-extra-nav-menu-pages', |
|
302 | - esc_html__('Event Espresso Pages', 'event_espresso'), |
|
303 | - array($this, 'ee_cpt_archive_pages'), |
|
304 | - 'nav-menus', |
|
305 | - 'side', |
|
306 | - 'core' |
|
307 | - ); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
313 | - * |
|
314 | - * @since 4.3.0 |
|
315 | - * @param string $link the original link generated by wp |
|
316 | - * @param int $id post id |
|
317 | - * @return string the (maybe) modified link |
|
318 | - */ |
|
319 | - public function modify_edit_post_link($link, $id) |
|
320 | - { |
|
321 | - if (! $post = get_post($id)) { |
|
322 | - return $link; |
|
323 | - } |
|
324 | - if ($post->post_type === 'espresso_attendees') { |
|
325 | - $query_args = array( |
|
326 | - 'action' => 'edit_attendee', |
|
327 | - 'post' => $id, |
|
328 | - ); |
|
329 | - return EEH_URL::add_query_args_and_nonce( |
|
330 | - $query_args, |
|
331 | - admin_url('admin.php?page=espresso_registrations') |
|
332 | - ); |
|
333 | - } |
|
334 | - return $link; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - public function ee_cpt_archive_pages() |
|
339 | - { |
|
340 | - global $nav_menu_selected_id; |
|
341 | - |
|
342 | - $db_fields = false; |
|
343 | - $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
344 | - $current_tab = 'event-archives'; |
|
345 | - |
|
346 | - /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
18 | + /** |
|
19 | + * @access private |
|
20 | + * @var EE_Admin $_instance |
|
21 | + */ |
|
22 | + private static $_instance; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + *@ singleton method used to instantiate class object |
|
27 | + *@ access public |
|
28 | + *@ return class instance |
|
29 | + * |
|
30 | + * @throws \EE_Error |
|
31 | + */ |
|
32 | + public static function instance() |
|
33 | + { |
|
34 | + // check if class object is instantiated |
|
35 | + if (! self::$_instance instanceof EE_Admin) { |
|
36 | + self::$_instance = new self(); |
|
37 | + } |
|
38 | + return self::$_instance; |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @return EE_Admin |
|
44 | + * @throws EE_Error |
|
45 | + */ |
|
46 | + public static function reset() |
|
47 | + { |
|
48 | + self::$_instance = null; |
|
49 | + return self::instance(); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * class constructor |
|
55 | + * |
|
56 | + * @throws \EE_Error |
|
57 | + */ |
|
58 | + protected function __construct() |
|
59 | + { |
|
60 | + // define global EE_Admin constants |
|
61 | + $this->_define_all_constants(); |
|
62 | + // set autoloaders for our admin page classes based on included path information |
|
63 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
64 | + // admin hooks |
|
65 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
66 | + // load EE_Request_Handler early |
|
67 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
68 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
69 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
70 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
71 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
72 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
73 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
74 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
75 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
76 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
77 | + |
|
78 | + //reset Environment config (we only do this on admin page loads); |
|
79 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
80 | + |
|
81 | + do_action('AHEE__EE_Admin__loaded'); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * _define_all_constants |
|
87 | + * define constants that are set globally for all admin pages |
|
88 | + * |
|
89 | + * @access private |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + private function _define_all_constants() |
|
93 | + { |
|
94 | + if (! defined('EE_ADMIN_URL')) { |
|
95 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
96 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
97 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
98 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
99 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @param array $links |
|
109 | + * @param string $plugin |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function filter_plugin_actions($links, $plugin) |
|
113 | + { |
|
114 | + // set $main_file in stone |
|
115 | + static $main_file; |
|
116 | + // if $main_file is not set yet |
|
117 | + if (! $main_file) { |
|
118 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
119 | + } |
|
120 | + if ($plugin === $main_file) { |
|
121 | + // compare current plugin to this one |
|
122 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
123 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
124 | + . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
125 | + . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
126 | + . '</a>'; |
|
127 | + array_unshift($links, $maintenance_link); |
|
128 | + } else { |
|
129 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
130 | + . esc_html__('Settings', 'event_espresso') |
|
131 | + . '</a>'; |
|
132 | + $events_link = '<a href="admin.php?page=espresso_events">' |
|
133 | + . esc_html__('Events', 'event_espresso') |
|
134 | + . '</a>'; |
|
135 | + // add before other links |
|
136 | + array_unshift($links, $org_settings_link, $events_link); |
|
137 | + } |
|
138 | + } |
|
139 | + return $links; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * _get_request |
|
145 | + * |
|
146 | + * @access public |
|
147 | + * @return void |
|
148 | + * @throws EE_Error |
|
149 | + * @throws ReflectionException |
|
150 | + */ |
|
151 | + public function get_request() |
|
152 | + { |
|
153 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
154 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * hide_admin_pages_except_maintenance_mode |
|
160 | + * |
|
161 | + * @access public |
|
162 | + * @param array $admin_page_folder_names |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
166 | + { |
|
167 | + return array( |
|
168 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
169 | + 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
170 | + 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
171 | + ); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
177 | + * EE_Front_Controller's init phases have run |
|
178 | + * |
|
179 | + * @access public |
|
180 | + * @return void |
|
181 | + * @throws EE_Error |
|
182 | + * @throws ReflectionException |
|
183 | + */ |
|
184 | + public function init() |
|
185 | + { |
|
186 | + //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
187 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
188 | + //ok so we want to enable the entire admin |
|
189 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
190 | + add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
191 | + add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
192 | + //at a glance dashboard widget |
|
193 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
194 | + //filter for get_edit_post_link used on comments for custom post types |
|
195 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
196 | + } |
|
197 | + // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
198 | + if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
199 | + try { |
|
200 | + //this loads the controller for the admin pages which will setup routing etc |
|
201 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
202 | + } catch (EE_Error $e) { |
|
203 | + $e->get_error(); |
|
204 | + } |
|
205 | + } |
|
206 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
207 | + //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
208 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
209 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
210 | + //exclude EE critical pages from all nav menus and wp_list_pages |
|
211 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
217 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
218 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
219 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
220 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
221 | + * |
|
222 | + * @param object $post_type WP post type object |
|
223 | + * @return object WP post type object |
|
224 | + */ |
|
225 | + public function remove_pages_from_nav_menu($post_type) |
|
226 | + { |
|
227 | + //if this isn't the "pages" post type let's get out |
|
228 | + if ($post_type->name !== 'page') { |
|
229 | + return $post_type; |
|
230 | + } |
|
231 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
232 | + |
|
233 | + $post_type->_default_query = array( |
|
234 | + 'post__not_in' => $critical_pages, |
|
235 | + ); |
|
236 | + return $post_type; |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
242 | + * metaboxes get shown as well |
|
243 | + * |
|
244 | + * @access public |
|
245 | + * @return void |
|
246 | + */ |
|
247 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
248 | + { |
|
249 | + global $wp_meta_boxes, $pagenow; |
|
250 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
251 | + return; |
|
252 | + } |
|
253 | + $user = wp_get_current_user(); |
|
254 | + //has this been done yet? |
|
255 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
256 | + return; |
|
257 | + } |
|
258 | + |
|
259 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
260 | + $initial_meta_boxes = apply_filters( |
|
261 | + 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
262 | + array( |
|
263 | + 'nav-menu-theme-locations', |
|
264 | + 'add-page', |
|
265 | + 'add-custom-links', |
|
266 | + 'add-category', |
|
267 | + 'add-espresso_events', |
|
268 | + 'add-espresso_venues', |
|
269 | + 'add-espresso_event_categories', |
|
270 | + 'add-espresso_venue_categories', |
|
271 | + 'add-post-type-post', |
|
272 | + 'add-post-type-page', |
|
273 | + ) |
|
274 | + ); |
|
275 | + |
|
276 | + if (is_array($hidden_meta_boxes)) { |
|
277 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
278 | + if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
279 | + unset($hidden_meta_boxes[$key]); |
|
280 | + } |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
285 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
291 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
292 | + * |
|
293 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
294 | + * addons etc. |
|
295 | + * @access public |
|
296 | + * @return void |
|
297 | + */ |
|
298 | + public function register_custom_nav_menu_boxes() |
|
299 | + { |
|
300 | + add_meta_box( |
|
301 | + 'add-extra-nav-menu-pages', |
|
302 | + esc_html__('Event Espresso Pages', 'event_espresso'), |
|
303 | + array($this, 'ee_cpt_archive_pages'), |
|
304 | + 'nav-menus', |
|
305 | + 'side', |
|
306 | + 'core' |
|
307 | + ); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
313 | + * |
|
314 | + * @since 4.3.0 |
|
315 | + * @param string $link the original link generated by wp |
|
316 | + * @param int $id post id |
|
317 | + * @return string the (maybe) modified link |
|
318 | + */ |
|
319 | + public function modify_edit_post_link($link, $id) |
|
320 | + { |
|
321 | + if (! $post = get_post($id)) { |
|
322 | + return $link; |
|
323 | + } |
|
324 | + if ($post->post_type === 'espresso_attendees') { |
|
325 | + $query_args = array( |
|
326 | + 'action' => 'edit_attendee', |
|
327 | + 'post' => $id, |
|
328 | + ); |
|
329 | + return EEH_URL::add_query_args_and_nonce( |
|
330 | + $query_args, |
|
331 | + admin_url('admin.php?page=espresso_registrations') |
|
332 | + ); |
|
333 | + } |
|
334 | + return $link; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + public function ee_cpt_archive_pages() |
|
339 | + { |
|
340 | + global $nav_menu_selected_id; |
|
341 | + |
|
342 | + $db_fields = false; |
|
343 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
344 | + $current_tab = 'event-archives'; |
|
345 | + |
|
346 | + /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
347 | 347 | $current_tab = 'search'; |
348 | 348 | }/**/ |
349 | 349 | |
350 | - $removed_args = array( |
|
351 | - 'action', |
|
352 | - 'customlink-tab', |
|
353 | - 'edit-menu-item', |
|
354 | - 'menu-item', |
|
355 | - 'page-tab', |
|
356 | - '_wpnonce', |
|
357 | - ); |
|
350 | + $removed_args = array( |
|
351 | + 'action', |
|
352 | + 'customlink-tab', |
|
353 | + 'edit-menu-item', |
|
354 | + 'menu-item', |
|
355 | + 'page-tab', |
|
356 | + '_wpnonce', |
|
357 | + ); |
|
358 | 358 | |
359 | - ?> |
|
359 | + ?> |
|
360 | 360 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
361 | 361 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
362 | 362 | <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
363 | 363 | <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
364 | 364 | href="<?php if ($nav_menu_selected_id) { |
365 | - echo esc_url( |
|
366 | - add_query_arg( |
|
367 | - 'extra-nav-menu-pages-tab', |
|
368 | - 'event-archives', |
|
369 | - remove_query_arg($removed_args) |
|
370 | - ) |
|
371 | - ); |
|
372 | - } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
365 | + echo esc_url( |
|
366 | + add_query_arg( |
|
367 | + 'extra-nav-menu-pages-tab', |
|
368 | + 'event-archives', |
|
369 | + remove_query_arg($removed_args) |
|
370 | + ) |
|
371 | + ); |
|
372 | + } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
373 | 373 | <?php _e('Event Archive Pages', 'event_espresso'); ?> |
374 | 374 | </a> |
375 | 375 | </li> |
376 | 376 | |
377 | 377 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
378 | - echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
379 | - ?>"> |
|
378 | + echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
379 | + ?>"> |
|
380 | 380 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
381 | 381 | <?php |
382 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
383 | - $args['walker'] = $walker; |
|
384 | - echo walk_nav_menu_tree( |
|
385 | - array_map( |
|
386 | - array($this, '_setup_extra_nav_menu_pages_items'), |
|
387 | - $pages |
|
388 | - ), |
|
389 | - 0, |
|
390 | - (object) $args |
|
391 | - ); |
|
392 | - ?> |
|
382 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
383 | + $args['walker'] = $walker; |
|
384 | + echo walk_nav_menu_tree( |
|
385 | + array_map( |
|
386 | + array($this, '_setup_extra_nav_menu_pages_items'), |
|
387 | + $pages |
|
388 | + ), |
|
389 | + 0, |
|
390 | + (object) $args |
|
391 | + ); |
|
392 | + ?> |
|
393 | 393 | </ul> |
394 | 394 | </div><!-- /.tabs-panel --> |
395 | 395 | |
396 | 396 | <p class="button-controls"> |
397 | 397 | <span class="list-controls"> |
398 | 398 | <a href="<?php |
399 | - echo esc_url(add_query_arg( |
|
400 | - array( |
|
401 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
402 | - 'selectall' => 1, |
|
403 | - ), |
|
404 | - remove_query_arg($removed_args) |
|
405 | - )); |
|
406 | - ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
399 | + echo esc_url(add_query_arg( |
|
400 | + array( |
|
401 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
402 | + 'selectall' => 1, |
|
403 | + ), |
|
404 | + remove_query_arg($removed_args) |
|
405 | + )); |
|
406 | + ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
407 | 407 | </span> |
408 | 408 | <span class="add-to-menu"> |
409 | 409 | <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> |
@@ -416,485 +416,485 @@ discard block |
||
416 | 416 | |
417 | 417 | </div><!-- /.posttypediv --> |
418 | 418 | <?php |
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Returns an array of event archive nav items. |
|
424 | - * |
|
425 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
426 | - * method we use for getting the extra nav menu items |
|
427 | - * @return array |
|
428 | - */ |
|
429 | - private function _get_extra_nav_menu_pages_items() |
|
430 | - { |
|
431 | - $menuitems[] = array( |
|
432 | - 'title' => esc_html__('Event List', 'event_espresso'), |
|
433 | - 'url' => get_post_type_archive_link('espresso_events'), |
|
434 | - 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
435 | - ); |
|
436 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
442 | - * the properties and converts it to the menu item object. |
|
443 | - * |
|
444 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
445 | - * @param $menu_item_values |
|
446 | - * @return stdClass |
|
447 | - */ |
|
448 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
449 | - { |
|
450 | - $menu_item = new stdClass(); |
|
451 | - $keys = array( |
|
452 | - 'ID' => 0, |
|
453 | - 'db_id' => 0, |
|
454 | - 'menu_item_parent' => 0, |
|
455 | - 'object_id' => -1, |
|
456 | - 'post_parent' => 0, |
|
457 | - 'type' => 'custom', |
|
458 | - 'object' => '', |
|
459 | - 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
460 | - 'title' => '', |
|
461 | - 'url' => '', |
|
462 | - 'target' => '', |
|
463 | - 'attr_title' => '', |
|
464 | - 'description' => '', |
|
465 | - 'classes' => array(), |
|
466 | - 'xfn' => '', |
|
467 | - ); |
|
468 | - |
|
469 | - foreach ($keys as $key => $value) { |
|
470 | - $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
471 | - } |
|
472 | - return $menu_item; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
478 | - * EE_Admin_Page route is called. |
|
479 | - * |
|
480 | - * @return void |
|
481 | - */ |
|
482 | - public function route_admin_request() |
|
483 | - { |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
489 | - * |
|
490 | - * @return void |
|
491 | - */ |
|
492 | - public function wp_loaded() |
|
493 | - { |
|
494 | - } |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * admin_init |
|
499 | - * |
|
500 | - * @access public |
|
501 | - * @return void |
|
502 | - * @throws EE_Error |
|
503 | - * @throws ReflectionException |
|
504 | - */ |
|
505 | - public function admin_init() |
|
506 | - { |
|
507 | - |
|
508 | - /** |
|
509 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
510 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
511 | - * - check if doing post processing. |
|
512 | - * - check if doing post processing of one of EE CPTs |
|
513 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
514 | - */ |
|
515 | - if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
516 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
517 | - EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
523 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
524 | - * Pages" tab in the EE General Settings Admin page. |
|
525 | - * This is for user-proofing. |
|
526 | - */ |
|
527 | - add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - /** |
|
532 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
533 | - * |
|
534 | - * @param string $output Current output. |
|
535 | - * @return string |
|
536 | - */ |
|
537 | - public function modify_dropdown_pages($output) |
|
538 | - { |
|
539 | - //get critical pages |
|
540 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
541 | - |
|
542 | - //split current output by line break for easier parsing. |
|
543 | - $split_output = explode("\n", $output); |
|
544 | - |
|
545 | - //loop through to remove any critical pages from the array. |
|
546 | - foreach ($critical_pages as $page_id) { |
|
547 | - $needle = 'value="' . $page_id . '"'; |
|
548 | - foreach ($split_output as $key => $haystack) { |
|
549 | - if (strpos($haystack, $needle) !== false) { |
|
550 | - unset($split_output[$key]); |
|
551 | - } |
|
552 | - } |
|
553 | - } |
|
554 | - |
|
555 | - //replace output with the new contents |
|
556 | - return implode("\n", $split_output); |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * enqueue all admin scripts that need loaded for admin pages |
|
562 | - * |
|
563 | - * @access public |
|
564 | - * @return void |
|
565 | - */ |
|
566 | - public function enqueue_admin_scripts() |
|
567 | - { |
|
568 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
569 | - // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
570 | - // calls. |
|
571 | - wp_enqueue_script( |
|
572 | - 'ee-inject-wp', |
|
573 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
574 | - array('jquery'), |
|
575 | - EVENT_ESPRESSO_VERSION, |
|
576 | - true |
|
577 | - ); |
|
578 | - // register cookie script for future dependencies |
|
579 | - wp_register_script( |
|
580 | - 'jquery-cookie', |
|
581 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
582 | - array('jquery'), |
|
583 | - '2.1', |
|
584 | - true |
|
585 | - ); |
|
586 | - //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
587 | - // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
588 | - if (apply_filters('FHEE_load_joyride', false)) { |
|
589 | - //joyride style |
|
590 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
591 | - wp_register_style( |
|
592 | - 'ee-joyride-css', |
|
593 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
594 | - array('joyride-css'), |
|
595 | - EVENT_ESPRESSO_VERSION |
|
596 | - ); |
|
597 | - wp_register_script( |
|
598 | - 'joyride-modernizr', |
|
599 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
600 | - array(), |
|
601 | - '2.1', |
|
602 | - true |
|
603 | - ); |
|
604 | - //joyride JS |
|
605 | - wp_register_script( |
|
606 | - 'jquery-joyride', |
|
607 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
608 | - array('jquery-cookie', 'joyride-modernizr'), |
|
609 | - '2.1', |
|
610 | - true |
|
611 | - ); |
|
612 | - // wanna go for a joyride? |
|
613 | - wp_enqueue_style('ee-joyride-css'); |
|
614 | - wp_enqueue_script('jquery-joyride'); |
|
615 | - } |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * display_admin_notices |
|
621 | - * |
|
622 | - * @access public |
|
623 | - * @return string |
|
624 | - */ |
|
625 | - public function display_admin_notices() |
|
626 | - { |
|
627 | - //add non-dismissable notice for datetime changes. Only valid if EE version is greater than 4.9.46.p and the |
|
628 | - // site does not have a timezone_string set. |
|
629 | - if (EE_Register_Addon::_meets_min_core_version_requirement( |
|
630 | - '4.9.46.p' |
|
631 | - ) |
|
632 | - && ! get_option('timezone_string') |
|
633 | - ) { |
|
634 | - EE_Error::add_attention( |
|
635 | - sprintf( |
|
636 | - esc_html__( |
|
637 | - '%1$sImportant%2$s: Please note some upcoming changes to dates and times in Event Espresso that may affect your website. Read more about it %3$shere%4$s.', |
|
638 | - 'event_espresso' |
|
639 | - ), |
|
640 | - '<strong>', |
|
641 | - '</strong>', |
|
642 | - '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
643 | - '</a>' |
|
644 | - ) |
|
645 | - ); |
|
646 | - } |
|
647 | - echo EE_Error::get_notices(); |
|
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * get_persistent_admin_notices |
|
653 | - * |
|
654 | - * @access public |
|
655 | - * @return void |
|
656 | - */ |
|
657 | - public function get_persistent_admin_notices() |
|
658 | - { |
|
659 | - // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
660 | - $args = array( |
|
661 | - 'page' => EE_Registry::instance()->REQ->is_set('page') |
|
662 | - ? EE_Registry::instance()->REQ->get('page') |
|
663 | - : '', |
|
664 | - 'action' => EE_Registry::instance()->REQ->is_set('action') |
|
665 | - ? EE_Registry::instance()->REQ->get('action') |
|
666 | - : '', |
|
667 | - ); |
|
668 | - $return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL); |
|
669 | - echo EE_Error::get_persistent_admin_notices($return_url); |
|
670 | - } |
|
671 | - |
|
672 | - |
|
673 | - /** |
|
674 | - * dismiss_persistent_admin_notice |
|
675 | - * |
|
676 | - * @access public |
|
677 | - * @return void |
|
678 | - */ |
|
679 | - public function dismiss_ee_nag_notice_callback() |
|
680 | - { |
|
681 | - EE_Error::dismiss_persistent_admin_notice(); |
|
682 | - } |
|
683 | - |
|
684 | - |
|
685 | - /** |
|
686 | - * @param array $elements |
|
687 | - * @return array |
|
688 | - * @throws \EE_Error |
|
689 | - */ |
|
690 | - public function dashboard_glance_items($elements) |
|
691 | - { |
|
692 | - $elements = is_array($elements) ? $elements : array($elements); |
|
693 | - $events = EEM_Event::instance()->count(); |
|
694 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
695 | - array('page' => 'espresso_events'), |
|
696 | - admin_url('admin.php') |
|
697 | - ); |
|
698 | - $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
699 | - $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
700 | - $registrations = EEM_Registration::instance()->count( |
|
701 | - array( |
|
702 | - array( |
|
703 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
704 | - ), |
|
705 | - ) |
|
706 | - ); |
|
707 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
708 | - array('page' => 'espresso_registrations'), |
|
709 | - admin_url('admin.php') |
|
710 | - ); |
|
711 | - $items['registrations']['text'] = sprintf( |
|
712 | - _n('%s Registration', '%s Registrations', $registrations), |
|
713 | - number_format_i18n($registrations) |
|
714 | - ); |
|
715 | - $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
716 | - |
|
717 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
718 | - |
|
719 | - foreach ($items as $type => $item_properties) { |
|
720 | - $elements[] = sprintf( |
|
721 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
722 | - $item_properties['url'], |
|
723 | - $item_properties['title'], |
|
724 | - $item_properties['text'] |
|
725 | - ); |
|
726 | - } |
|
727 | - return $elements; |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * check_for_invalid_datetime_formats |
|
733 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
734 | - * their selected format can be parsed by PHP |
|
735 | - * |
|
736 | - * @access public |
|
737 | - * @param $value |
|
738 | - * @param $option |
|
739 | - * @throws EE_Error |
|
740 | - * @return string |
|
741 | - */ |
|
742 | - public function check_for_invalid_datetime_formats($value, $option) |
|
743 | - { |
|
744 | - // check for date_format or time_format |
|
745 | - switch ($option) { |
|
746 | - case 'date_format': |
|
747 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
748 | - break; |
|
749 | - case 'time_format': |
|
750 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
751 | - break; |
|
752 | - default: |
|
753 | - $date_time_format = false; |
|
754 | - } |
|
755 | - // do we have a date_time format to check ? |
|
756 | - if ($date_time_format) { |
|
757 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
758 | - |
|
759 | - if (is_array($error_msg)) { |
|
760 | - $msg = '<p>' |
|
761 | - . sprintf( |
|
762 | - esc_html__( |
|
763 | - 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
764 | - 'event_espresso' |
|
765 | - ), |
|
766 | - date($date_time_format), |
|
767 | - $date_time_format |
|
768 | - ) |
|
769 | - . '</p><p><ul>'; |
|
770 | - |
|
771 | - |
|
772 | - foreach ($error_msg as $error) { |
|
773 | - $msg .= '<li>' . $error . '</li>'; |
|
774 | - } |
|
775 | - |
|
776 | - $msg .= '</ul></p><p>' |
|
777 | - . sprintf( |
|
778 | - esc_html__( |
|
779 | - '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
780 | - 'event_espresso' |
|
781 | - ), |
|
782 | - '<span style="color:#D54E21;">', |
|
783 | - '</span>' |
|
784 | - ) |
|
785 | - . '</p>'; |
|
786 | - |
|
787 | - // trigger WP settings error |
|
788 | - add_settings_error( |
|
789 | - 'date_format', |
|
790 | - 'date_format', |
|
791 | - $msg |
|
792 | - ); |
|
793 | - |
|
794 | - // set format to something valid |
|
795 | - switch ($option) { |
|
796 | - case 'date_format': |
|
797 | - $value = 'F j, Y'; |
|
798 | - break; |
|
799 | - case 'time_format': |
|
800 | - $value = 'g:i a'; |
|
801 | - break; |
|
802 | - } |
|
803 | - } |
|
804 | - } |
|
805 | - return $value; |
|
806 | - } |
|
807 | - |
|
808 | - |
|
809 | - /** |
|
810 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
811 | - * |
|
812 | - * @access public |
|
813 | - * @param $content |
|
814 | - * @return string |
|
815 | - */ |
|
816 | - public function its_eSpresso($content) |
|
817 | - { |
|
818 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
819 | - } |
|
820 | - |
|
821 | - |
|
822 | - /** |
|
823 | - * espresso_admin_footer |
|
824 | - * |
|
825 | - * @access public |
|
826 | - * @return string |
|
827 | - */ |
|
828 | - public function espresso_admin_footer() |
|
829 | - { |
|
830 | - return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
831 | - } |
|
832 | - |
|
833 | - |
|
834 | - /** |
|
835 | - * static method for registering ee admin page. |
|
836 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
837 | - * |
|
838 | - * @since 4.3.0 |
|
839 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
840 | - * @see EE_Register_Admin_Page::register() |
|
841 | - * @param $page_basename |
|
842 | - * @param $page_path |
|
843 | - * @param array $config |
|
844 | - * @return void |
|
845 | - * @throws EE_Error |
|
846 | - */ |
|
847 | - public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
848 | - { |
|
849 | - EE_Error::doing_it_wrong( |
|
850 | - __METHOD__, |
|
851 | - sprintf( |
|
852 | - esc_html__( |
|
853 | - 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
854 | - 'event_espresso' |
|
855 | - ), |
|
856 | - $page_basename |
|
857 | - ), |
|
858 | - '4.3' |
|
859 | - ); |
|
860 | - if (class_exists('EE_Register_Admin_Page')) { |
|
861 | - $config['page_path'] = $page_path; |
|
862 | - } |
|
863 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - /** |
|
868 | - * @deprecated 4.8.41 |
|
869 | - * @access public |
|
870 | - * @param int $post_ID |
|
871 | - * @param \WP_Post $post |
|
872 | - * @return void |
|
873 | - */ |
|
874 | - public static function parse_post_content_on_save($post_ID, $post) |
|
875 | - { |
|
876 | - EE_Error::doing_it_wrong( |
|
877 | - __METHOD__, |
|
878 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
879 | - '4.8.41' |
|
880 | - ); |
|
881 | - } |
|
882 | - |
|
883 | - |
|
884 | - /** |
|
885 | - * @deprecated 4.8.41 |
|
886 | - * @access public |
|
887 | - * @param $option |
|
888 | - * @param $old_value |
|
889 | - * @param $value |
|
890 | - * @return void |
|
891 | - */ |
|
892 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
893 | - { |
|
894 | - EE_Error::doing_it_wrong( |
|
895 | - __METHOD__, |
|
896 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
897 | - '4.8.41' |
|
898 | - ); |
|
899 | - } |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Returns an array of event archive nav items. |
|
424 | + * |
|
425 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
426 | + * method we use for getting the extra nav menu items |
|
427 | + * @return array |
|
428 | + */ |
|
429 | + private function _get_extra_nav_menu_pages_items() |
|
430 | + { |
|
431 | + $menuitems[] = array( |
|
432 | + 'title' => esc_html__('Event List', 'event_espresso'), |
|
433 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
434 | + 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
435 | + ); |
|
436 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
442 | + * the properties and converts it to the menu item object. |
|
443 | + * |
|
444 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
445 | + * @param $menu_item_values |
|
446 | + * @return stdClass |
|
447 | + */ |
|
448 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
449 | + { |
|
450 | + $menu_item = new stdClass(); |
|
451 | + $keys = array( |
|
452 | + 'ID' => 0, |
|
453 | + 'db_id' => 0, |
|
454 | + 'menu_item_parent' => 0, |
|
455 | + 'object_id' => -1, |
|
456 | + 'post_parent' => 0, |
|
457 | + 'type' => 'custom', |
|
458 | + 'object' => '', |
|
459 | + 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
460 | + 'title' => '', |
|
461 | + 'url' => '', |
|
462 | + 'target' => '', |
|
463 | + 'attr_title' => '', |
|
464 | + 'description' => '', |
|
465 | + 'classes' => array(), |
|
466 | + 'xfn' => '', |
|
467 | + ); |
|
468 | + |
|
469 | + foreach ($keys as $key => $value) { |
|
470 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
471 | + } |
|
472 | + return $menu_item; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
478 | + * EE_Admin_Page route is called. |
|
479 | + * |
|
480 | + * @return void |
|
481 | + */ |
|
482 | + public function route_admin_request() |
|
483 | + { |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
489 | + * |
|
490 | + * @return void |
|
491 | + */ |
|
492 | + public function wp_loaded() |
|
493 | + { |
|
494 | + } |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * admin_init |
|
499 | + * |
|
500 | + * @access public |
|
501 | + * @return void |
|
502 | + * @throws EE_Error |
|
503 | + * @throws ReflectionException |
|
504 | + */ |
|
505 | + public function admin_init() |
|
506 | + { |
|
507 | + |
|
508 | + /** |
|
509 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
510 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
511 | + * - check if doing post processing. |
|
512 | + * - check if doing post processing of one of EE CPTs |
|
513 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
514 | + */ |
|
515 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
516 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
517 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
523 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
524 | + * Pages" tab in the EE General Settings Admin page. |
|
525 | + * This is for user-proofing. |
|
526 | + */ |
|
527 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + /** |
|
532 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
533 | + * |
|
534 | + * @param string $output Current output. |
|
535 | + * @return string |
|
536 | + */ |
|
537 | + public function modify_dropdown_pages($output) |
|
538 | + { |
|
539 | + //get critical pages |
|
540 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
541 | + |
|
542 | + //split current output by line break for easier parsing. |
|
543 | + $split_output = explode("\n", $output); |
|
544 | + |
|
545 | + //loop through to remove any critical pages from the array. |
|
546 | + foreach ($critical_pages as $page_id) { |
|
547 | + $needle = 'value="' . $page_id . '"'; |
|
548 | + foreach ($split_output as $key => $haystack) { |
|
549 | + if (strpos($haystack, $needle) !== false) { |
|
550 | + unset($split_output[$key]); |
|
551 | + } |
|
552 | + } |
|
553 | + } |
|
554 | + |
|
555 | + //replace output with the new contents |
|
556 | + return implode("\n", $split_output); |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * enqueue all admin scripts that need loaded for admin pages |
|
562 | + * |
|
563 | + * @access public |
|
564 | + * @return void |
|
565 | + */ |
|
566 | + public function enqueue_admin_scripts() |
|
567 | + { |
|
568 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
569 | + // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
570 | + // calls. |
|
571 | + wp_enqueue_script( |
|
572 | + 'ee-inject-wp', |
|
573 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
574 | + array('jquery'), |
|
575 | + EVENT_ESPRESSO_VERSION, |
|
576 | + true |
|
577 | + ); |
|
578 | + // register cookie script for future dependencies |
|
579 | + wp_register_script( |
|
580 | + 'jquery-cookie', |
|
581 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
582 | + array('jquery'), |
|
583 | + '2.1', |
|
584 | + true |
|
585 | + ); |
|
586 | + //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
587 | + // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
588 | + if (apply_filters('FHEE_load_joyride', false)) { |
|
589 | + //joyride style |
|
590 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
591 | + wp_register_style( |
|
592 | + 'ee-joyride-css', |
|
593 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
594 | + array('joyride-css'), |
|
595 | + EVENT_ESPRESSO_VERSION |
|
596 | + ); |
|
597 | + wp_register_script( |
|
598 | + 'joyride-modernizr', |
|
599 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
600 | + array(), |
|
601 | + '2.1', |
|
602 | + true |
|
603 | + ); |
|
604 | + //joyride JS |
|
605 | + wp_register_script( |
|
606 | + 'jquery-joyride', |
|
607 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
608 | + array('jquery-cookie', 'joyride-modernizr'), |
|
609 | + '2.1', |
|
610 | + true |
|
611 | + ); |
|
612 | + // wanna go for a joyride? |
|
613 | + wp_enqueue_style('ee-joyride-css'); |
|
614 | + wp_enqueue_script('jquery-joyride'); |
|
615 | + } |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * display_admin_notices |
|
621 | + * |
|
622 | + * @access public |
|
623 | + * @return string |
|
624 | + */ |
|
625 | + public function display_admin_notices() |
|
626 | + { |
|
627 | + //add non-dismissable notice for datetime changes. Only valid if EE version is greater than 4.9.46.p and the |
|
628 | + // site does not have a timezone_string set. |
|
629 | + if (EE_Register_Addon::_meets_min_core_version_requirement( |
|
630 | + '4.9.46.p' |
|
631 | + ) |
|
632 | + && ! get_option('timezone_string') |
|
633 | + ) { |
|
634 | + EE_Error::add_attention( |
|
635 | + sprintf( |
|
636 | + esc_html__( |
|
637 | + '%1$sImportant%2$s: Please note some upcoming changes to dates and times in Event Espresso that may affect your website. Read more about it %3$shere%4$s.', |
|
638 | + 'event_espresso' |
|
639 | + ), |
|
640 | + '<strong>', |
|
641 | + '</strong>', |
|
642 | + '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
643 | + '</a>' |
|
644 | + ) |
|
645 | + ); |
|
646 | + } |
|
647 | + echo EE_Error::get_notices(); |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * get_persistent_admin_notices |
|
653 | + * |
|
654 | + * @access public |
|
655 | + * @return void |
|
656 | + */ |
|
657 | + public function get_persistent_admin_notices() |
|
658 | + { |
|
659 | + // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
660 | + $args = array( |
|
661 | + 'page' => EE_Registry::instance()->REQ->is_set('page') |
|
662 | + ? EE_Registry::instance()->REQ->get('page') |
|
663 | + : '', |
|
664 | + 'action' => EE_Registry::instance()->REQ->is_set('action') |
|
665 | + ? EE_Registry::instance()->REQ->get('action') |
|
666 | + : '', |
|
667 | + ); |
|
668 | + $return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL); |
|
669 | + echo EE_Error::get_persistent_admin_notices($return_url); |
|
670 | + } |
|
671 | + |
|
672 | + |
|
673 | + /** |
|
674 | + * dismiss_persistent_admin_notice |
|
675 | + * |
|
676 | + * @access public |
|
677 | + * @return void |
|
678 | + */ |
|
679 | + public function dismiss_ee_nag_notice_callback() |
|
680 | + { |
|
681 | + EE_Error::dismiss_persistent_admin_notice(); |
|
682 | + } |
|
683 | + |
|
684 | + |
|
685 | + /** |
|
686 | + * @param array $elements |
|
687 | + * @return array |
|
688 | + * @throws \EE_Error |
|
689 | + */ |
|
690 | + public function dashboard_glance_items($elements) |
|
691 | + { |
|
692 | + $elements = is_array($elements) ? $elements : array($elements); |
|
693 | + $events = EEM_Event::instance()->count(); |
|
694 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
695 | + array('page' => 'espresso_events'), |
|
696 | + admin_url('admin.php') |
|
697 | + ); |
|
698 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
699 | + $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
700 | + $registrations = EEM_Registration::instance()->count( |
|
701 | + array( |
|
702 | + array( |
|
703 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
704 | + ), |
|
705 | + ) |
|
706 | + ); |
|
707 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
708 | + array('page' => 'espresso_registrations'), |
|
709 | + admin_url('admin.php') |
|
710 | + ); |
|
711 | + $items['registrations']['text'] = sprintf( |
|
712 | + _n('%s Registration', '%s Registrations', $registrations), |
|
713 | + number_format_i18n($registrations) |
|
714 | + ); |
|
715 | + $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
716 | + |
|
717 | + $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
718 | + |
|
719 | + foreach ($items as $type => $item_properties) { |
|
720 | + $elements[] = sprintf( |
|
721 | + '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
722 | + $item_properties['url'], |
|
723 | + $item_properties['title'], |
|
724 | + $item_properties['text'] |
|
725 | + ); |
|
726 | + } |
|
727 | + return $elements; |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * check_for_invalid_datetime_formats |
|
733 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
734 | + * their selected format can be parsed by PHP |
|
735 | + * |
|
736 | + * @access public |
|
737 | + * @param $value |
|
738 | + * @param $option |
|
739 | + * @throws EE_Error |
|
740 | + * @return string |
|
741 | + */ |
|
742 | + public function check_for_invalid_datetime_formats($value, $option) |
|
743 | + { |
|
744 | + // check for date_format or time_format |
|
745 | + switch ($option) { |
|
746 | + case 'date_format': |
|
747 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
748 | + break; |
|
749 | + case 'time_format': |
|
750 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
751 | + break; |
|
752 | + default: |
|
753 | + $date_time_format = false; |
|
754 | + } |
|
755 | + // do we have a date_time format to check ? |
|
756 | + if ($date_time_format) { |
|
757 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
758 | + |
|
759 | + if (is_array($error_msg)) { |
|
760 | + $msg = '<p>' |
|
761 | + . sprintf( |
|
762 | + esc_html__( |
|
763 | + 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
764 | + 'event_espresso' |
|
765 | + ), |
|
766 | + date($date_time_format), |
|
767 | + $date_time_format |
|
768 | + ) |
|
769 | + . '</p><p><ul>'; |
|
770 | + |
|
771 | + |
|
772 | + foreach ($error_msg as $error) { |
|
773 | + $msg .= '<li>' . $error . '</li>'; |
|
774 | + } |
|
775 | + |
|
776 | + $msg .= '</ul></p><p>' |
|
777 | + . sprintf( |
|
778 | + esc_html__( |
|
779 | + '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
780 | + 'event_espresso' |
|
781 | + ), |
|
782 | + '<span style="color:#D54E21;">', |
|
783 | + '</span>' |
|
784 | + ) |
|
785 | + . '</p>'; |
|
786 | + |
|
787 | + // trigger WP settings error |
|
788 | + add_settings_error( |
|
789 | + 'date_format', |
|
790 | + 'date_format', |
|
791 | + $msg |
|
792 | + ); |
|
793 | + |
|
794 | + // set format to something valid |
|
795 | + switch ($option) { |
|
796 | + case 'date_format': |
|
797 | + $value = 'F j, Y'; |
|
798 | + break; |
|
799 | + case 'time_format': |
|
800 | + $value = 'g:i a'; |
|
801 | + break; |
|
802 | + } |
|
803 | + } |
|
804 | + } |
|
805 | + return $value; |
|
806 | + } |
|
807 | + |
|
808 | + |
|
809 | + /** |
|
810 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
811 | + * |
|
812 | + * @access public |
|
813 | + * @param $content |
|
814 | + * @return string |
|
815 | + */ |
|
816 | + public function its_eSpresso($content) |
|
817 | + { |
|
818 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
819 | + } |
|
820 | + |
|
821 | + |
|
822 | + /** |
|
823 | + * espresso_admin_footer |
|
824 | + * |
|
825 | + * @access public |
|
826 | + * @return string |
|
827 | + */ |
|
828 | + public function espresso_admin_footer() |
|
829 | + { |
|
830 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
831 | + } |
|
832 | + |
|
833 | + |
|
834 | + /** |
|
835 | + * static method for registering ee admin page. |
|
836 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
837 | + * |
|
838 | + * @since 4.3.0 |
|
839 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
840 | + * @see EE_Register_Admin_Page::register() |
|
841 | + * @param $page_basename |
|
842 | + * @param $page_path |
|
843 | + * @param array $config |
|
844 | + * @return void |
|
845 | + * @throws EE_Error |
|
846 | + */ |
|
847 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
848 | + { |
|
849 | + EE_Error::doing_it_wrong( |
|
850 | + __METHOD__, |
|
851 | + sprintf( |
|
852 | + esc_html__( |
|
853 | + 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
854 | + 'event_espresso' |
|
855 | + ), |
|
856 | + $page_basename |
|
857 | + ), |
|
858 | + '4.3' |
|
859 | + ); |
|
860 | + if (class_exists('EE_Register_Admin_Page')) { |
|
861 | + $config['page_path'] = $page_path; |
|
862 | + } |
|
863 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + /** |
|
868 | + * @deprecated 4.8.41 |
|
869 | + * @access public |
|
870 | + * @param int $post_ID |
|
871 | + * @param \WP_Post $post |
|
872 | + * @return void |
|
873 | + */ |
|
874 | + public static function parse_post_content_on_save($post_ID, $post) |
|
875 | + { |
|
876 | + EE_Error::doing_it_wrong( |
|
877 | + __METHOD__, |
|
878 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
879 | + '4.8.41' |
|
880 | + ); |
|
881 | + } |
|
882 | + |
|
883 | + |
|
884 | + /** |
|
885 | + * @deprecated 4.8.41 |
|
886 | + * @access public |
|
887 | + * @param $option |
|
888 | + * @param $old_value |
|
889 | + * @param $value |
|
890 | + * @return void |
|
891 | + */ |
|
892 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
893 | + { |
|
894 | + EE_Error::doing_it_wrong( |
|
895 | + __METHOD__, |
|
896 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
897 | + '4.8.41' |
|
898 | + ); |
|
899 | + } |
|
900 | 900 | } |
@@ -157,7 +157,7 @@ |
||
157 | 157 | /** |
158 | 158 | * This retrieves the EE_Venue from the available data object. |
159 | 159 | * |
160 | - * @return EE_Venue|null |
|
160 | + * @return EE_Base_Class|null |
|
161 | 161 | */ |
162 | 162 | private function _get_venue() { |
163 | 163 |
@@ -16,288 +16,288 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * Will hold the EE_Event if available |
|
21 | - * |
|
22 | - * @var EE_Event |
|
23 | - */ |
|
24 | - protected $_event; |
|
25 | - |
|
26 | - /** |
|
27 | - * Will hold the EE_Venue if available |
|
28 | - * |
|
29 | - * @var EE_Venue |
|
30 | - */ |
|
31 | - protected $_venue; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Initialize properties |
|
36 | - */ |
|
37 | - protected function _init_props() |
|
38 | - { |
|
39 | - $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
40 | - $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
41 | - $this->_shortcodes = array( |
|
42 | - '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
43 | - '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
44 | - '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
45 | - '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
46 | - '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
47 | - '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
48 | - '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
49 | - '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
50 | - '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
51 | - '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
52 | - '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
53 | - 'This just outputs the venue address in a semantic address format.', |
|
54 | - 'event_espresso' |
|
55 | - ), |
|
56 | - '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
57 | - '[VENUE_META_*]' => esc_html__( |
|
58 | - 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
59 | - 'event_espresso' |
|
60 | - ), |
|
61 | - '[GOOGLE_MAP_URL]' => esc_html__( |
|
62 | - 'URL for the google map associated with the venue.', |
|
63 | - 'event_espresso' |
|
64 | - ), |
|
65 | - '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
66 | - '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
67 | - ); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Parse incoming shortcode |
|
73 | - * @param string $shortcode |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - protected function _parser($shortcode) |
|
77 | - { |
|
78 | - $this->_venue = $this->_get_venue(); |
|
79 | - //If there is no venue object by now then get out. |
|
80 | - if ( ! $this->_venue instanceof EE_Venue ) |
|
81 | - return ''; |
|
82 | - |
|
83 | - switch ($shortcode) { |
|
84 | - case '[VENUE_TITLE]': |
|
85 | - return $this->_venue('title'); |
|
86 | - break; |
|
87 | - |
|
88 | - case '[VENUE_DESCRIPTION]': |
|
89 | - return $this->_venue('description'); |
|
90 | - break; |
|
91 | - |
|
92 | - case '[VENUE_URL]': |
|
93 | - return $this->_venue('url'); |
|
94 | - break; |
|
95 | - |
|
96 | - case '[VENUE_IMAGE]': |
|
97 | - return $this->_venue('image'); |
|
98 | - break; |
|
99 | - |
|
100 | - case '[VENUE_PHONE]': |
|
101 | - return $this->_venue('phone'); |
|
102 | - break; |
|
103 | - |
|
104 | - case '[VENUE_ADDRESS]': |
|
105 | - return $this->_venue('address'); |
|
106 | - break; |
|
107 | - |
|
108 | - case '[VENUE_ADDRESS2]': |
|
109 | - return $this->_venue('address2'); |
|
110 | - break; |
|
111 | - |
|
112 | - case '[VENUE_CITY]': |
|
113 | - return $this->_venue('city'); |
|
114 | - break; |
|
115 | - |
|
116 | - case '[VENUE_COUNTRY]': |
|
117 | - return $this->_venue('country'); |
|
118 | - break; |
|
119 | - |
|
120 | - case '[VENUE_STATE]': |
|
121 | - return $this->_venue('state'); |
|
122 | - break; |
|
123 | - |
|
124 | - case '[VENUE_ZIP]': |
|
125 | - return $this->_venue('zip'); |
|
126 | - break; |
|
127 | - |
|
128 | - case '[VENUE_FORMATTED_ADDRESS]': |
|
129 | - return $this->_venue('formatted_address'); |
|
130 | - break; |
|
131 | - |
|
132 | - case '[GOOGLE_MAP_URL]': |
|
133 | - return $this->_venue('gmap_url'); |
|
134 | - break; |
|
135 | - |
|
136 | - case '[GOOGLE_MAP_LINK]': |
|
137 | - return $this->_venue('gmap_link'); |
|
138 | - break; |
|
139 | - |
|
140 | - case '[GOOGLE_MAP_IMAGE]': |
|
141 | - return $this->_venue('gmap_link_img'); |
|
142 | - break; |
|
143 | - |
|
144 | - } |
|
145 | - |
|
146 | - if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) { |
|
147 | - $shortcode = str_replace( '[VENUE_META_*', '', $shortcode ); |
|
148 | - $shortcode = trim( str_replace( ']', '', $shortcode ) ); |
|
149 | - |
|
150 | - //pull the meta value from the venue post |
|
151 | - $venue_meta = $this->_venue->get_post_meta( $shortcode, true ); |
|
152 | - |
|
153 | - return ! empty( $venue_meta ) ? $venue_meta : ''; |
|
154 | - |
|
155 | - } |
|
156 | - } |
|
157 | - /** |
|
158 | - * This retrieves the EE_Venue from the available data object. |
|
159 | - * |
|
160 | - * @return EE_Venue|null |
|
161 | - */ |
|
162 | - private function _get_venue() { |
|
163 | - |
|
164 | - //we need the EE_Event object to get the venue. |
|
165 | - $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
166 | - |
|
167 | - //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the reg_obj instead. |
|
168 | - if (empty($this->_event)) { |
|
169 | - $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
170 | - $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
171 | - |
|
172 | - $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null; |
|
173 | - |
|
174 | - //if still empty do we have a ticket data item? |
|
175 | - $this->_event = empty($this->_event) |
|
176 | - && $this->_data instanceof EE_Ticket |
|
177 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
178 | - ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
179 | - : $this->_event; |
|
180 | - |
|
181 | - //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that. |
|
182 | - $event = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array(); |
|
183 | - $this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event; |
|
184 | - } |
|
185 | - |
|
186 | - //If we have an event object use it to pull the venue. |
|
187 | - if ($this->_event instanceof EE_Event) { |
|
188 | - return $this->_event->get_first_related('Venue'); |
|
189 | - } |
|
190 | - |
|
191 | - return null; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * This retrieves the specified venue information |
|
196 | - * |
|
197 | - * @param string $field What Venue field to retrieve |
|
198 | - * @return string What was retrieved! |
|
199 | - * @throws EE_Error |
|
200 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
201 | - */ |
|
202 | - private function _venue($field) |
|
203 | - { |
|
204 | - |
|
205 | - if (empty($this->_venue)) { |
|
206 | - return ''; |
|
207 | - } //no venue so get out. |
|
208 | - |
|
209 | - switch ($field) { |
|
210 | - case 'title': |
|
211 | - return $this->_venue->get('VNU_name'); |
|
212 | - break; |
|
213 | - |
|
214 | - case 'description': |
|
215 | - return $this->_venue->get('VNU_desc'); |
|
216 | - break; |
|
217 | - |
|
218 | - case 'url': |
|
219 | - $url = $this->_venue->get('VNU_url'); |
|
220 | - return empty($url) ? $this->_venue->get_permalink() : $url; |
|
221 | - break; |
|
222 | - |
|
223 | - case 'image': |
|
224 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
225 | - . '" alt="' . sprintf( |
|
226 | - esc_attr__('%s Feature Image', 'event_espresso'), |
|
227 | - $this->_venue->get('VNU_name') |
|
228 | - ) . '" />'; |
|
229 | - break; |
|
230 | - |
|
231 | - case 'phone': |
|
232 | - return $this->_venue->get('VNU_phone'); |
|
233 | - break; |
|
234 | - |
|
235 | - case 'address': |
|
236 | - return $this->_venue->get('VNU_address'); |
|
237 | - break; |
|
238 | - |
|
239 | - case 'address2': |
|
240 | - return $this->_venue->get('VNU_address2'); |
|
241 | - break; |
|
242 | - |
|
243 | - case 'city': |
|
244 | - return $this->_venue->get('VNU_city'); |
|
245 | - break; |
|
246 | - |
|
247 | - case 'state': |
|
248 | - $state = $this->_venue->state_obj(); |
|
249 | - return is_object($state) ? $state->get('STA_name') : ''; |
|
250 | - break; |
|
251 | - |
|
252 | - case 'country': |
|
253 | - $country = $this->_venue->country_obj(); |
|
254 | - return is_object($country) ? $country->get('CNT_name') : ''; |
|
255 | - break; |
|
256 | - |
|
257 | - case 'zip': |
|
258 | - return $this->_venue->get('VNU_zip'); |
|
259 | - break; |
|
260 | - |
|
261 | - case 'formatted_address': |
|
262 | - return EEH_Address::format($this->_venue); |
|
263 | - break; |
|
264 | - |
|
265 | - case 'gmap_link': |
|
266 | - case 'gmap_url': |
|
267 | - case 'gmap_link_img': |
|
268 | - $atts = $this->get_map_attributes($this->_venue, $field); |
|
269 | - return EEH_Maps::google_map_link($atts); |
|
270 | - break; |
|
271 | - } |
|
272 | - return ''; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * Generates the attributes for retrieving a google_map artifact. |
|
278 | - * @param EE_Venue $venue |
|
279 | - * @param string $field |
|
280 | - * @return array |
|
281 | - * @throws EE_Error |
|
282 | - */ |
|
283 | - protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
284 | - { |
|
285 | - $state = $venue->state_obj(); |
|
286 | - $country = $venue->country_obj(); |
|
287 | - $atts = array( |
|
288 | - 'id' => $venue->ID(), |
|
289 | - 'address' => $venue->get('VNU_address'), |
|
290 | - 'city' => $venue->get('VNU_city'), |
|
291 | - 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
292 | - 'zip' => $venue->get('VNU_zip'), |
|
293 | - 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
294 | - 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
295 | - 'map_w' => 200, |
|
296 | - 'map_h' => 200, |
|
297 | - ); |
|
298 | - if ($field === 'gmap_url') { |
|
299 | - $atts['type'] = 'url_only'; |
|
300 | - } |
|
301 | - return $atts; |
|
302 | - } |
|
19 | + /** |
|
20 | + * Will hold the EE_Event if available |
|
21 | + * |
|
22 | + * @var EE_Event |
|
23 | + */ |
|
24 | + protected $_event; |
|
25 | + |
|
26 | + /** |
|
27 | + * Will hold the EE_Venue if available |
|
28 | + * |
|
29 | + * @var EE_Venue |
|
30 | + */ |
|
31 | + protected $_venue; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Initialize properties |
|
36 | + */ |
|
37 | + protected function _init_props() |
|
38 | + { |
|
39 | + $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
40 | + $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
41 | + $this->_shortcodes = array( |
|
42 | + '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
43 | + '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
44 | + '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
45 | + '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
46 | + '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
47 | + '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
48 | + '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
49 | + '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
50 | + '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
51 | + '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
52 | + '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
53 | + 'This just outputs the venue address in a semantic address format.', |
|
54 | + 'event_espresso' |
|
55 | + ), |
|
56 | + '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
57 | + '[VENUE_META_*]' => esc_html__( |
|
58 | + 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
59 | + 'event_espresso' |
|
60 | + ), |
|
61 | + '[GOOGLE_MAP_URL]' => esc_html__( |
|
62 | + 'URL for the google map associated with the venue.', |
|
63 | + 'event_espresso' |
|
64 | + ), |
|
65 | + '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
66 | + '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
67 | + ); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Parse incoming shortcode |
|
73 | + * @param string $shortcode |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + protected function _parser($shortcode) |
|
77 | + { |
|
78 | + $this->_venue = $this->_get_venue(); |
|
79 | + //If there is no venue object by now then get out. |
|
80 | + if ( ! $this->_venue instanceof EE_Venue ) |
|
81 | + return ''; |
|
82 | + |
|
83 | + switch ($shortcode) { |
|
84 | + case '[VENUE_TITLE]': |
|
85 | + return $this->_venue('title'); |
|
86 | + break; |
|
87 | + |
|
88 | + case '[VENUE_DESCRIPTION]': |
|
89 | + return $this->_venue('description'); |
|
90 | + break; |
|
91 | + |
|
92 | + case '[VENUE_URL]': |
|
93 | + return $this->_venue('url'); |
|
94 | + break; |
|
95 | + |
|
96 | + case '[VENUE_IMAGE]': |
|
97 | + return $this->_venue('image'); |
|
98 | + break; |
|
99 | + |
|
100 | + case '[VENUE_PHONE]': |
|
101 | + return $this->_venue('phone'); |
|
102 | + break; |
|
103 | + |
|
104 | + case '[VENUE_ADDRESS]': |
|
105 | + return $this->_venue('address'); |
|
106 | + break; |
|
107 | + |
|
108 | + case '[VENUE_ADDRESS2]': |
|
109 | + return $this->_venue('address2'); |
|
110 | + break; |
|
111 | + |
|
112 | + case '[VENUE_CITY]': |
|
113 | + return $this->_venue('city'); |
|
114 | + break; |
|
115 | + |
|
116 | + case '[VENUE_COUNTRY]': |
|
117 | + return $this->_venue('country'); |
|
118 | + break; |
|
119 | + |
|
120 | + case '[VENUE_STATE]': |
|
121 | + return $this->_venue('state'); |
|
122 | + break; |
|
123 | + |
|
124 | + case '[VENUE_ZIP]': |
|
125 | + return $this->_venue('zip'); |
|
126 | + break; |
|
127 | + |
|
128 | + case '[VENUE_FORMATTED_ADDRESS]': |
|
129 | + return $this->_venue('formatted_address'); |
|
130 | + break; |
|
131 | + |
|
132 | + case '[GOOGLE_MAP_URL]': |
|
133 | + return $this->_venue('gmap_url'); |
|
134 | + break; |
|
135 | + |
|
136 | + case '[GOOGLE_MAP_LINK]': |
|
137 | + return $this->_venue('gmap_link'); |
|
138 | + break; |
|
139 | + |
|
140 | + case '[GOOGLE_MAP_IMAGE]': |
|
141 | + return $this->_venue('gmap_link_img'); |
|
142 | + break; |
|
143 | + |
|
144 | + } |
|
145 | + |
|
146 | + if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) { |
|
147 | + $shortcode = str_replace( '[VENUE_META_*', '', $shortcode ); |
|
148 | + $shortcode = trim( str_replace( ']', '', $shortcode ) ); |
|
149 | + |
|
150 | + //pull the meta value from the venue post |
|
151 | + $venue_meta = $this->_venue->get_post_meta( $shortcode, true ); |
|
152 | + |
|
153 | + return ! empty( $venue_meta ) ? $venue_meta : ''; |
|
154 | + |
|
155 | + } |
|
156 | + } |
|
157 | + /** |
|
158 | + * This retrieves the EE_Venue from the available data object. |
|
159 | + * |
|
160 | + * @return EE_Venue|null |
|
161 | + */ |
|
162 | + private function _get_venue() { |
|
163 | + |
|
164 | + //we need the EE_Event object to get the venue. |
|
165 | + $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
166 | + |
|
167 | + //if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the reg_obj instead. |
|
168 | + if (empty($this->_event)) { |
|
169 | + $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
170 | + $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
171 | + |
|
172 | + $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration ? $aee->reg_obj->event() : null; |
|
173 | + |
|
174 | + //if still empty do we have a ticket data item? |
|
175 | + $this->_event = empty($this->_event) |
|
176 | + && $this->_data instanceof EE_Ticket |
|
177 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
178 | + ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
179 | + : $this->_event; |
|
180 | + |
|
181 | + //if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee and use that. |
|
182 | + $event = $aee instanceof EE_Messages_Addressee ? reset($aee->events) : array(); |
|
183 | + $this->_event = empty($this->_event) && ! empty($events) ? $event : $this->_event; |
|
184 | + } |
|
185 | + |
|
186 | + //If we have an event object use it to pull the venue. |
|
187 | + if ($this->_event instanceof EE_Event) { |
|
188 | + return $this->_event->get_first_related('Venue'); |
|
189 | + } |
|
190 | + |
|
191 | + return null; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * This retrieves the specified venue information |
|
196 | + * |
|
197 | + * @param string $field What Venue field to retrieve |
|
198 | + * @return string What was retrieved! |
|
199 | + * @throws EE_Error |
|
200 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
201 | + */ |
|
202 | + private function _venue($field) |
|
203 | + { |
|
204 | + |
|
205 | + if (empty($this->_venue)) { |
|
206 | + return ''; |
|
207 | + } //no venue so get out. |
|
208 | + |
|
209 | + switch ($field) { |
|
210 | + case 'title': |
|
211 | + return $this->_venue->get('VNU_name'); |
|
212 | + break; |
|
213 | + |
|
214 | + case 'description': |
|
215 | + return $this->_venue->get('VNU_desc'); |
|
216 | + break; |
|
217 | + |
|
218 | + case 'url': |
|
219 | + $url = $this->_venue->get('VNU_url'); |
|
220 | + return empty($url) ? $this->_venue->get_permalink() : $url; |
|
221 | + break; |
|
222 | + |
|
223 | + case 'image': |
|
224 | + return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
225 | + . '" alt="' . sprintf( |
|
226 | + esc_attr__('%s Feature Image', 'event_espresso'), |
|
227 | + $this->_venue->get('VNU_name') |
|
228 | + ) . '" />'; |
|
229 | + break; |
|
230 | + |
|
231 | + case 'phone': |
|
232 | + return $this->_venue->get('VNU_phone'); |
|
233 | + break; |
|
234 | + |
|
235 | + case 'address': |
|
236 | + return $this->_venue->get('VNU_address'); |
|
237 | + break; |
|
238 | + |
|
239 | + case 'address2': |
|
240 | + return $this->_venue->get('VNU_address2'); |
|
241 | + break; |
|
242 | + |
|
243 | + case 'city': |
|
244 | + return $this->_venue->get('VNU_city'); |
|
245 | + break; |
|
246 | + |
|
247 | + case 'state': |
|
248 | + $state = $this->_venue->state_obj(); |
|
249 | + return is_object($state) ? $state->get('STA_name') : ''; |
|
250 | + break; |
|
251 | + |
|
252 | + case 'country': |
|
253 | + $country = $this->_venue->country_obj(); |
|
254 | + return is_object($country) ? $country->get('CNT_name') : ''; |
|
255 | + break; |
|
256 | + |
|
257 | + case 'zip': |
|
258 | + return $this->_venue->get('VNU_zip'); |
|
259 | + break; |
|
260 | + |
|
261 | + case 'formatted_address': |
|
262 | + return EEH_Address::format($this->_venue); |
|
263 | + break; |
|
264 | + |
|
265 | + case 'gmap_link': |
|
266 | + case 'gmap_url': |
|
267 | + case 'gmap_link_img': |
|
268 | + $atts = $this->get_map_attributes($this->_venue, $field); |
|
269 | + return EEH_Maps::google_map_link($atts); |
|
270 | + break; |
|
271 | + } |
|
272 | + return ''; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * Generates the attributes for retrieving a google_map artifact. |
|
278 | + * @param EE_Venue $venue |
|
279 | + * @param string $field |
|
280 | + * @return array |
|
281 | + * @throws EE_Error |
|
282 | + */ |
|
283 | + protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
284 | + { |
|
285 | + $state = $venue->state_obj(); |
|
286 | + $country = $venue->country_obj(); |
|
287 | + $atts = array( |
|
288 | + 'id' => $venue->ID(), |
|
289 | + 'address' => $venue->get('VNU_address'), |
|
290 | + 'city' => $venue->get('VNU_city'), |
|
291 | + 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
292 | + 'zip' => $venue->get('VNU_zip'), |
|
293 | + 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
294 | + 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
295 | + 'map_w' => 200, |
|
296 | + 'map_h' => 200, |
|
297 | + ); |
|
298 | + if ($field === 'gmap_url') { |
|
299 | + $atts['type'] = 'url_only'; |
|
300 | + } |
|
301 | + return $atts; |
|
302 | + } |
|
303 | 303 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | { |
78 | 78 | $this->_venue = $this->_get_venue(); |
79 | 79 | //If there is no venue object by now then get out. |
80 | - if ( ! $this->_venue instanceof EE_Venue ) |
|
80 | + if ( ! $this->_venue instanceof EE_Venue) |
|
81 | 81 | return ''; |
82 | 82 | |
83 | 83 | switch ($shortcode) { |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | |
144 | 144 | } |
145 | 145 | |
146 | - if ( strpos( $shortcode, '[VENUE_META_*' ) !== false ) { |
|
147 | - $shortcode = str_replace( '[VENUE_META_*', '', $shortcode ); |
|
148 | - $shortcode = trim( str_replace( ']', '', $shortcode ) ); |
|
146 | + if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
147 | + $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
148 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
149 | 149 | |
150 | 150 | //pull the meta value from the venue post |
151 | - $venue_meta = $this->_venue->get_post_meta( $shortcode, true ); |
|
151 | + $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
152 | 152 | |
153 | - return ! empty( $venue_meta ) ? $venue_meta : ''; |
|
153 | + return ! empty($venue_meta) ? $venue_meta : ''; |
|
154 | 154 | |
155 | 155 | } |
156 | 156 | } |
@@ -221,11 +221,11 @@ discard block |
||
221 | 221 | break; |
222 | 222 | |
223 | 223 | case 'image': |
224 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
225 | - . '" alt="' . sprintf( |
|
224 | + return '<img src="'.$this->_venue->feature_image_url(array(200, 200,)) |
|
225 | + . '" alt="'.sprintf( |
|
226 | 226 | esc_attr__('%s Feature Image', 'event_espresso'), |
227 | 227 | $this->_venue->get('VNU_name') |
228 | - ) . '" />'; |
|
228 | + ).'" />'; |
|
229 | 229 | break; |
230 | 230 | |
231 | 231 | case 'phone': |
@@ -77,8 +77,9 @@ |
||
77 | 77 | { |
78 | 78 | $this->_venue = $this->_get_venue(); |
79 | 79 | //If there is no venue object by now then get out. |
80 | - if ( ! $this->_venue instanceof EE_Venue ) |
|
81 | - return ''; |
|
80 | + if ( ! $this->_venue instanceof EE_Venue ) { |
|
81 | + return ''; |
|
82 | + } |
|
82 | 83 | |
83 | 84 | switch ($shortcode) { |
84 | 85 | case '[VENUE_TITLE]': |
@@ -9,20 +9,20 @@ |
||
9 | 9 | interface LoaderDecoratorInterface |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @param string $fqcn |
|
14 | - * @param array $arguments |
|
15 | - * @param bool $shared |
|
16 | - * @return mixed |
|
17 | - */ |
|
18 | - public function load($fqcn, $arguments = array(), $shared = true); |
|
12 | + /** |
|
13 | + * @param string $fqcn |
|
14 | + * @param array $arguments |
|
15 | + * @param bool $shared |
|
16 | + * @return mixed |
|
17 | + */ |
|
18 | + public function load($fqcn, $arguments = array(), $shared = true); |
|
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * calls reset() on loader if method exists |
|
24 | - */ |
|
25 | - public function reset(); |
|
22 | + /** |
|
23 | + * calls reset() on loader if method exists |
|
24 | + */ |
|
25 | + public function reset(); |
|
26 | 26 | |
27 | 27 | } |
28 | 28 | // End of file LoaderInterface.php |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\services\orm\ModelFieldFactory; |
4 | 4 | |
5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | |
@@ -19,128 +19,128 @@ discard block |
||
19 | 19 | class EEM_WP_User extends EEM_Base |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * private instance of the EEM_WP_User object |
|
24 | - * |
|
25 | - * @type EEM_WP_User |
|
26 | - */ |
|
27 | - protected static $_instance; |
|
28 | - |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * constructor |
|
33 | - * |
|
34 | - * @param null $timezone |
|
35 | - * @param ModelFieldFactory $model_field_factory |
|
36 | - * @throws EE_Error |
|
37 | - * @throws InvalidArgumentException |
|
38 | - */ |
|
39 | - protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
40 | - { |
|
41 | - $this->singular_item = __('WP_User', 'event_espresso'); |
|
42 | - $this->plural_item = __('WP_Users', 'event_espresso'); |
|
43 | - global $wpdb; |
|
44 | - $this->_tables = array( |
|
45 | - 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
46 | - ); |
|
47 | - $this->_fields = array( |
|
48 | - 'WP_User' => array( |
|
49 | - 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
50 | - 'ID', |
|
51 | - __('WP_User ID', 'event_espresso') |
|
52 | - ), |
|
53 | - 'user_login' => $model_field_factory->createPlainTextField( |
|
54 | - 'user_login', |
|
55 | - __('User Login', 'event_espresso'), |
|
56 | - false |
|
57 | - ), |
|
58 | - 'user_pass' => $model_field_factory->createPlainTextField( |
|
59 | - 'user_pass', |
|
60 | - __('User Password', 'event_espresso'), |
|
61 | - false |
|
62 | - ), |
|
63 | - 'user_nicename' => $model_field_factory->createPlainTextField( |
|
64 | - 'user_nicename', |
|
65 | - __(' User Nice Name', 'event_espresso'), |
|
66 | - false |
|
67 | - ), |
|
68 | - 'user_email' => $model_field_factory->createEmailField( |
|
69 | - 'user_email', |
|
70 | - __('User Email', 'event_espresso'), |
|
71 | - false, |
|
72 | - null |
|
73 | - ), |
|
74 | - 'user_registered' => $model_field_factory->createDatetimeField( |
|
75 | - 'user_registered', |
|
76 | - __('Date User Registered', 'event_espresso'), |
|
77 | - $timezone |
|
78 | - ), |
|
79 | - 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
80 | - 'user_activation_key', |
|
81 | - __('User Activation Key', 'event_espresso'), |
|
82 | - false |
|
83 | - ), |
|
84 | - 'user_status' => $model_field_factory->createIntegerField( |
|
85 | - 'user_status', |
|
86 | - __('User Status', 'event_espresso') |
|
87 | - ), |
|
88 | - 'display_name' => $model_field_factory->createPlainTextField( |
|
89 | - 'display_name', |
|
90 | - __('Display Name', 'event_espresso'), |
|
91 | - false |
|
92 | - ), |
|
93 | - ), |
|
94 | - ); |
|
95 | - $this->_model_relations = array( |
|
96 | - 'Attendee' => new EE_Has_Many_Relation(), |
|
97 | - // all models are related to the change log |
|
98 | - // 'Change_Log' => new EE_Has_Many_Relation(), |
|
99 | - 'Event' => new EE_Has_Many_Relation(), |
|
100 | - 'Payment_Method' => new EE_Has_Many_Relation(), |
|
101 | - 'Price' => new EE_Has_Many_Relation(), |
|
102 | - 'Price_Type' => new EE_Has_Many_Relation(), |
|
103 | - 'Question' => new EE_Has_Many_Relation(), |
|
104 | - 'Question_Group' => new EE_Has_Many_Relation(), |
|
105 | - 'Ticket' => new EE_Has_Many_Relation(), |
|
106 | - 'Venue' => new EE_Has_Many_Relation(), |
|
107 | - 'Message' => new EE_Has_Many_Relation(), |
|
108 | - ); |
|
109 | - $this->_wp_core_model = true; |
|
110 | - $this->_caps_slug = 'users'; |
|
111 | - $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list'; |
|
112 | - $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list'; |
|
113 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
114 | - $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User(); |
|
115 | - } |
|
116 | - //@todo: account for create_users controls whether they can create users at all |
|
117 | - parent::__construct($timezone); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * We don't need a foreign key to the WP_User model, we just need its primary key |
|
124 | - * |
|
125 | - * @return string |
|
126 | - * @throws EE_Error |
|
127 | - */ |
|
128 | - public function wp_user_field_name() |
|
129 | - { |
|
130 | - return $this->primary_key_name(); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
137 | - * |
|
138 | - * @return boolean |
|
139 | - */ |
|
140 | - public function is_owned() |
|
141 | - { |
|
142 | - return true; |
|
143 | - } |
|
22 | + /** |
|
23 | + * private instance of the EEM_WP_User object |
|
24 | + * |
|
25 | + * @type EEM_WP_User |
|
26 | + */ |
|
27 | + protected static $_instance; |
|
28 | + |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * constructor |
|
33 | + * |
|
34 | + * @param null $timezone |
|
35 | + * @param ModelFieldFactory $model_field_factory |
|
36 | + * @throws EE_Error |
|
37 | + * @throws InvalidArgumentException |
|
38 | + */ |
|
39 | + protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
40 | + { |
|
41 | + $this->singular_item = __('WP_User', 'event_espresso'); |
|
42 | + $this->plural_item = __('WP_Users', 'event_espresso'); |
|
43 | + global $wpdb; |
|
44 | + $this->_tables = array( |
|
45 | + 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
46 | + ); |
|
47 | + $this->_fields = array( |
|
48 | + 'WP_User' => array( |
|
49 | + 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
50 | + 'ID', |
|
51 | + __('WP_User ID', 'event_espresso') |
|
52 | + ), |
|
53 | + 'user_login' => $model_field_factory->createPlainTextField( |
|
54 | + 'user_login', |
|
55 | + __('User Login', 'event_espresso'), |
|
56 | + false |
|
57 | + ), |
|
58 | + 'user_pass' => $model_field_factory->createPlainTextField( |
|
59 | + 'user_pass', |
|
60 | + __('User Password', 'event_espresso'), |
|
61 | + false |
|
62 | + ), |
|
63 | + 'user_nicename' => $model_field_factory->createPlainTextField( |
|
64 | + 'user_nicename', |
|
65 | + __(' User Nice Name', 'event_espresso'), |
|
66 | + false |
|
67 | + ), |
|
68 | + 'user_email' => $model_field_factory->createEmailField( |
|
69 | + 'user_email', |
|
70 | + __('User Email', 'event_espresso'), |
|
71 | + false, |
|
72 | + null |
|
73 | + ), |
|
74 | + 'user_registered' => $model_field_factory->createDatetimeField( |
|
75 | + 'user_registered', |
|
76 | + __('Date User Registered', 'event_espresso'), |
|
77 | + $timezone |
|
78 | + ), |
|
79 | + 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
80 | + 'user_activation_key', |
|
81 | + __('User Activation Key', 'event_espresso'), |
|
82 | + false |
|
83 | + ), |
|
84 | + 'user_status' => $model_field_factory->createIntegerField( |
|
85 | + 'user_status', |
|
86 | + __('User Status', 'event_espresso') |
|
87 | + ), |
|
88 | + 'display_name' => $model_field_factory->createPlainTextField( |
|
89 | + 'display_name', |
|
90 | + __('Display Name', 'event_espresso'), |
|
91 | + false |
|
92 | + ), |
|
93 | + ), |
|
94 | + ); |
|
95 | + $this->_model_relations = array( |
|
96 | + 'Attendee' => new EE_Has_Many_Relation(), |
|
97 | + // all models are related to the change log |
|
98 | + // 'Change_Log' => new EE_Has_Many_Relation(), |
|
99 | + 'Event' => new EE_Has_Many_Relation(), |
|
100 | + 'Payment_Method' => new EE_Has_Many_Relation(), |
|
101 | + 'Price' => new EE_Has_Many_Relation(), |
|
102 | + 'Price_Type' => new EE_Has_Many_Relation(), |
|
103 | + 'Question' => new EE_Has_Many_Relation(), |
|
104 | + 'Question_Group' => new EE_Has_Many_Relation(), |
|
105 | + 'Ticket' => new EE_Has_Many_Relation(), |
|
106 | + 'Venue' => new EE_Has_Many_Relation(), |
|
107 | + 'Message' => new EE_Has_Many_Relation(), |
|
108 | + ); |
|
109 | + $this->_wp_core_model = true; |
|
110 | + $this->_caps_slug = 'users'; |
|
111 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list'; |
|
112 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list'; |
|
113 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
114 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User(); |
|
115 | + } |
|
116 | + //@todo: account for create_users controls whether they can create users at all |
|
117 | + parent::__construct($timezone); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * We don't need a foreign key to the WP_User model, we just need its primary key |
|
124 | + * |
|
125 | + * @return string |
|
126 | + * @throws EE_Error |
|
127 | + */ |
|
128 | + public function wp_user_field_name() |
|
129 | + { |
|
130 | + return $this->primary_key_name(); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
137 | + * |
|
138 | + * @return boolean |
|
139 | + */ |
|
140 | + public function is_owned() |
|
141 | + { |
|
142 | + return true; |
|
143 | + } |
|
144 | 144 | |
145 | 145 | |
146 | 146 |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | use EventEspresso\core\services\orm\ModelFieldFactory; |
4 | 4 | |
5 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | 6 | exit('No direct script access allowed'); |
7 | 7 | } |
8 | 8 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -17,632 +17,632 @@ discard block |
||
17 | 17 | class EEH_Debug_Tools |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * instance of the EEH_Autoloader object |
|
22 | - * |
|
23 | - * @var $_instance |
|
24 | - * @access private |
|
25 | - */ |
|
26 | - private static $_instance; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $_memory_usage_points = array(); |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @access public |
|
38 | - * @return EEH_Debug_Tools |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated, and instantiated properly |
|
43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - return self::$_instance; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * private class constructor |
|
53 | - */ |
|
54 | - private function __construct() |
|
55 | - { |
|
56 | - // load Kint PHP debugging library |
|
57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
58 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
59 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
60 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
61 | - // so we've moved it to our test folder so that it is not included with production releases |
|
62 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
64 | - } |
|
65 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
66 | - //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
67 | - // } |
|
68 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
69 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
71 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * show_db_name |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public static function show_db_name() |
|
82 | - { |
|
83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
85 | - . DB_NAME |
|
86 | - . '</p>'; |
|
87 | - } |
|
88 | - if (EE_DEBUG) { |
|
89 | - Benchmark::displayResults(); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * dump EE_Session object at bottom of page after everything else has happened |
|
97 | - * |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public function espresso_session_footer_dump() |
|
101 | - { |
|
102 | - if ( |
|
103 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
104 | - && ! defined('DOING_AJAX') |
|
105 | - && class_exists('Kint') |
|
106 | - && function_exists('wp_get_current_user') |
|
107 | - && current_user_can('update_core') |
|
108 | - && class_exists('EE_Registry') |
|
109 | - ) { |
|
110 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
111 | - Kint::dump(EE_Registry::instance()->SSN); |
|
112 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
113 | - $this->espresso_list_hooked_functions(); |
|
114 | - Benchmark::displayResults(); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * List All Hooked Functions |
|
122 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
123 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
124 | - * |
|
125 | - * @param string $tag |
|
126 | - * @return void |
|
127 | - */ |
|
128 | - public function espresso_list_hooked_functions($tag = '') |
|
129 | - { |
|
130 | - global $wp_filter; |
|
131 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
132 | - if ($tag) { |
|
133 | - $hook[$tag] = $wp_filter[$tag]; |
|
134 | - if (! is_array($hook[$tag])) { |
|
135 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
136 | - return; |
|
137 | - } |
|
138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
139 | - } else { |
|
140 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
141 | - ksort($hook); |
|
142 | - } |
|
143 | - foreach ($hook as $tag_name => $priorities) { |
|
144 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
145 | - ksort($priorities); |
|
146 | - foreach ($priorities as $priority => $function) { |
|
147 | - echo $priority; |
|
148 | - foreach ($function as $name => $properties) { |
|
149 | - echo "\t$name<br />"; |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * registered_filter_callbacks |
|
159 | - * |
|
160 | - * @param string $hook_name |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public static function registered_filter_callbacks($hook_name = '') |
|
164 | - { |
|
165 | - $filters = array(); |
|
166 | - global $wp_filter; |
|
167 | - if (isset($wp_filter[$hook_name])) { |
|
168 | - $filters[$hook_name] = array(); |
|
169 | - foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | - $filters[$hook_name][$priority] = array(); |
|
171 | - foreach ($callbacks as $callback) { |
|
172 | - $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - return $filters; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * captures plugin activation errors for debugging |
|
183 | - * |
|
184 | - * @return void |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public static function ee_plugin_activation_errors() |
|
188 | - { |
|
189 | - if (WP_DEBUG) { |
|
190 | - $activation_errors = ob_get_contents(); |
|
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | - } |
|
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | - if (class_exists('EEH_File')) { |
|
196 | - try { |
|
197 | - EEH_File::ensure_file_exists_and_is_writable( |
|
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
199 | - ); |
|
200 | - EEH_File::write_to_file( |
|
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
202 | - $activation_errors |
|
203 | - ); |
|
204 | - } catch (EE_Error $e) { |
|
205 | - EE_Error::add_error( |
|
206 | - sprintf( |
|
207 | - __( |
|
208 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | - 'event_espresso' |
|
210 | - ), |
|
211 | - $e->getMessage() |
|
212 | - ), |
|
213 | - __FILE__, __FUNCTION__, __LINE__ |
|
214 | - ); |
|
215 | - } |
|
216 | - } else { |
|
217 | - // old school attempt |
|
218 | - file_put_contents( |
|
219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
220 | - $activation_errors |
|
221 | - ); |
|
222 | - } |
|
223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
224 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
232 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
233 | - * or we want to make sure they use something the right way. |
|
234 | - * |
|
235 | - * @access public |
|
236 | - * @param string $function The function that was called |
|
237 | - * @param string $message A message explaining what has been done incorrectly |
|
238 | - * @param string $version The version of Event Espresso where the error was added |
|
239 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
240 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
241 | - * but not have any notices appear until a later version. This allows developers |
|
242 | - * extra time to update their code before notices appear. |
|
243 | - * @param int $error_type |
|
244 | - * @uses trigger_error() |
|
245 | - */ |
|
246 | - public function doing_it_wrong( |
|
247 | - $function, |
|
248 | - $message, |
|
249 | - $version, |
|
250 | - $applies_when = '', |
|
251 | - $error_type = null |
|
252 | - ) { |
|
253 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
254 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
255 | - // because we swapped the parameter order around for the last two params, |
|
256 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
257 | - if (is_int($applies_when)) { |
|
258 | - $error_type = $applies_when; |
|
259 | - $applies_when = espresso_version(); |
|
260 | - } |
|
261 | - // if not displaying notices yet, then just leave |
|
262 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
263 | - return; |
|
264 | - } |
|
265 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
266 | - $version = $version === null |
|
267 | - ? '' |
|
268 | - : sprintf( |
|
269 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
270 | - $version |
|
271 | - ); |
|
272 | - $error_message = sprintf( |
|
273 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
274 | - $function, |
|
275 | - '<strong>', |
|
276 | - '</strong>', |
|
277 | - $message, |
|
278 | - $version |
|
279 | - ); |
|
280 | - // don't trigger error if doing ajax, |
|
281 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
282 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
283 | - $error_message .= ' ' . esc_html__( |
|
284 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
285 | - 'event_espresso' |
|
286 | - ); |
|
287 | - $error_message .= '<ul><li>'; |
|
288 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
289 | - $error_message .= '</ul>'; |
|
290 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
291 | - //now we set this on the transient so it shows up on the next request. |
|
292 | - EE_Error::get_notices(false, true); |
|
293 | - } else { |
|
294 | - trigger_error($error_message, $error_type); |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Logger helpers |
|
303 | - */ |
|
304 | - /** |
|
305 | - * debug |
|
306 | - * |
|
307 | - * @param string $class |
|
308 | - * @param string $func |
|
309 | - * @param string $line |
|
310 | - * @param array $info |
|
311 | - * @param bool $display_request |
|
312 | - * @param string $debug_index |
|
313 | - * @param string $debug_key |
|
314 | - * @throws EE_Error |
|
315 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
316 | - */ |
|
317 | - public static function log( |
|
318 | - $class = '', |
|
319 | - $func = '', |
|
320 | - $line = '', |
|
321 | - $info = array(), |
|
322 | - $display_request = false, |
|
323 | - $debug_index = '', |
|
324 | - $debug_key = 'EE_DEBUG_SPCO' |
|
325 | - ) { |
|
326 | - if (WP_DEBUG) { |
|
327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | - $debug_data = get_option($debug_key, array()); |
|
329 | - $default_data = array( |
|
330 | - $class => $func . '() : ' . $line, |
|
331 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
332 | - ); |
|
333 | - // don't serialize objects |
|
334 | - $info = self::strip_objects($info); |
|
335 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | - if (! isset($debug_data[$index])) { |
|
337 | - $debug_data[$index] = array(); |
|
338 | - } |
|
339 | - $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | - update_option($debug_key, $debug_data); |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * strip_objects |
|
348 | - * |
|
349 | - * @param array $info |
|
350 | - * @return array |
|
351 | - */ |
|
352 | - public static function strip_objects($info = array()) |
|
353 | - { |
|
354 | - foreach ($info as $key => $value) { |
|
355 | - if (is_array($value)) { |
|
356 | - $info[$key] = self::strip_objects($value); |
|
357 | - } else if (is_object($value)) { |
|
358 | - $object_class = get_class($value); |
|
359 | - $info[$object_class] = array(); |
|
360 | - $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | - if (method_exists($value, 'ID')) { |
|
362 | - $info[$object_class]['ID'] = $value->ID(); |
|
363 | - } |
|
364 | - if (method_exists($value, 'status')) { |
|
365 | - $info[$object_class]['status'] = $value->status(); |
|
366 | - } else if (method_exists($value, 'status_ID')) { |
|
367 | - $info[$object_class]['status'] = $value->status_ID(); |
|
368 | - } |
|
369 | - unset($info[$key]); |
|
370 | - } |
|
371 | - } |
|
372 | - return (array)$info; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @param mixed $var |
|
379 | - * @param string $var_name |
|
380 | - * @param string $file |
|
381 | - * @param int|string $line |
|
382 | - * @param int $heading_tag |
|
383 | - * @param bool $die |
|
384 | - * @param string $margin |
|
385 | - */ |
|
386 | - public static function printv( |
|
387 | - $var, |
|
388 | - $var_name = '', |
|
389 | - $file = '', |
|
390 | - $line = '', |
|
391 | - $heading_tag = 5, |
|
392 | - $die = false, |
|
393 | - $margin = '' |
|
394 | - ) { |
|
395 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | - $is_method = method_exists($var_name, $var); |
|
398 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
400 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
401 | - $result .= $is_method |
|
402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
404 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
405 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
406 | - if ($die) { |
|
407 | - die($result); |
|
408 | - } |
|
409 | - echo $result; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @param string $var_name |
|
416 | - * @param string $heading_tag |
|
417 | - * @param string $margin |
|
418 | - * @return string |
|
419 | - */ |
|
420 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
421 | - { |
|
422 | - if (defined('EE_TESTS_DIR')) { |
|
423 | - return "\n{$var_name}"; |
|
424 | - } |
|
425 | - $margin = "25px 0 0 {$margin}"; |
|
426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * @param string $heading_tag |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - protected static function headingX($heading_tag = 'h5') |
|
436 | - { |
|
437 | - if (defined('EE_TESTS_DIR')) { |
|
438 | - return ''; |
|
439 | - } |
|
440 | - return '</' . $heading_tag . '>'; |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * @param string $content |
|
447 | - * @return string |
|
448 | - */ |
|
449 | - protected static function grey_span($content = '') |
|
450 | - { |
|
451 | - if (defined('EE_TESTS_DIR')) { |
|
452 | - return $content; |
|
453 | - } |
|
454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * @param string $file |
|
461 | - * @param int $line |
|
462 | - * @return string |
|
463 | - */ |
|
464 | - protected static function file_and_line($file, $line) |
|
465 | - { |
|
466 | - if ($file === '' || $line === '') { |
|
467 | - return ''; |
|
468 | - } |
|
469 | - if (defined('EE_TESTS_DIR')) { |
|
470 | - return "\n\t(" . $file . ' line no: ' . $line . ' ) '; |
|
471 | - } |
|
472 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
473 | - . $file |
|
474 | - . '<br />line no: ' |
|
475 | - . $line |
|
476 | - . '</span>'; |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * @param string $content |
|
483 | - * @return string |
|
484 | - */ |
|
485 | - protected static function orange_span($content = '') |
|
486 | - { |
|
487 | - if (defined('EE_TESTS_DIR')) { |
|
488 | - return $content; |
|
489 | - } |
|
490 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * @param mixed $var |
|
497 | - * @return string |
|
498 | - */ |
|
499 | - protected static function pre_span($var) |
|
500 | - { |
|
501 | - ob_start(); |
|
502 | - var_dump($var); |
|
503 | - $var = ob_get_clean(); |
|
504 | - if (defined('EE_TESTS_DIR')) { |
|
505 | - return "\n" . $var; |
|
506 | - } |
|
507 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * @param mixed $var |
|
514 | - * @param string $var_name |
|
515 | - * @param string $file |
|
516 | - * @param int|string $line |
|
517 | - * @param int $heading_tag |
|
518 | - * @param bool $die |
|
519 | - */ |
|
520 | - public static function printr( |
|
521 | - $var, |
|
522 | - $var_name = '', |
|
523 | - $file = '', |
|
524 | - $line = '', |
|
525 | - $heading_tag = 5, |
|
526 | - $die = false |
|
527 | - ) { |
|
528 | - // return; |
|
529 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
530 | - $margin = is_admin() ? ' 180px' : '0'; |
|
531 | - //$print_r = false; |
|
532 | - if (is_string($var)) { |
|
533 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
534 | - return; |
|
535 | - } |
|
536 | - if (is_object($var)) { |
|
537 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
538 | - //$print_r = true; |
|
539 | - } else if (is_array($var)) { |
|
540 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
541 | - //$print_r = true; |
|
542 | - } else if (is_numeric($var)) { |
|
543 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
544 | - } else if ($var === null) { |
|
545 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
546 | - } |
|
547 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
548 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
549 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
550 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
551 | - EEH_Debug_Tools::pre_span($var) |
|
552 | - ); |
|
553 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
554 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
555 | - if ($die) { |
|
556 | - die($result); |
|
557 | - } |
|
558 | - echo $result; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - |
|
563 | - /******************** deprecated ********************/ |
|
564 | - |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * @deprecated 4.9.39.rc.034 |
|
569 | - */ |
|
570 | - public function reset_times() |
|
571 | - { |
|
572 | - Benchmark::resetTimes(); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * @deprecated 4.9.39.rc.034 |
|
579 | - * @param null $timer_name |
|
580 | - */ |
|
581 | - public function start_timer($timer_name = null) |
|
582 | - { |
|
583 | - Benchmark::startTimer($timer_name); |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * @deprecated 4.9.39.rc.034 |
|
590 | - * @param string $timer_name |
|
591 | - */ |
|
592 | - public function stop_timer($timer_name = '') |
|
593 | - { |
|
594 | - Benchmark::stopTimer($timer_name); |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * @deprecated 4.9.39.rc.034 |
|
601 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
602 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
603 | - * @return void |
|
604 | - */ |
|
605 | - public function measure_memory($label, $output_now = false) |
|
606 | - { |
|
607 | - Benchmark::measureMemory($label, $output_now); |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * @deprecated 4.9.39.rc.034 |
|
614 | - * @param int $size |
|
615 | - * @return string |
|
616 | - */ |
|
617 | - public function convert($size) |
|
618 | - { |
|
619 | - return Benchmark::convert($size); |
|
620 | - } |
|
621 | - |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * @deprecated 4.9.39.rc.034 |
|
626 | - * @param bool $output_now |
|
627 | - * @return string |
|
628 | - */ |
|
629 | - public function show_times($output_now = true) |
|
630 | - { |
|
631 | - return Benchmark::displayResults($output_now); |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - |
|
636 | - /** |
|
637 | - * @deprecated 4.9.39.rc.034 |
|
638 | - * @param string $timer_name |
|
639 | - * @param float $total_time |
|
640 | - * @return string |
|
641 | - */ |
|
642 | - public function format_time($timer_name, $total_time) |
|
643 | - { |
|
644 | - return Benchmark::formatTime($timer_name, $total_time); |
|
645 | - } |
|
20 | + /** |
|
21 | + * instance of the EEH_Autoloader object |
|
22 | + * |
|
23 | + * @var $_instance |
|
24 | + * @access private |
|
25 | + */ |
|
26 | + private static $_instance; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $_memory_usage_points = array(); |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @access public |
|
38 | + * @return EEH_Debug_Tools |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated, and instantiated properly |
|
43 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + return self::$_instance; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * private class constructor |
|
53 | + */ |
|
54 | + private function __construct() |
|
55 | + { |
|
56 | + // load Kint PHP debugging library |
|
57 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
58 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
59 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
60 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
61 | + // so we've moved it to our test folder so that it is not included with production releases |
|
62 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
63 | + require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
64 | + } |
|
65 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
66 | + //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
67 | + // } |
|
68 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
69 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
71 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * show_db_name |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public static function show_db_name() |
|
82 | + { |
|
83 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
85 | + . DB_NAME |
|
86 | + . '</p>'; |
|
87 | + } |
|
88 | + if (EE_DEBUG) { |
|
89 | + Benchmark::displayResults(); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * dump EE_Session object at bottom of page after everything else has happened |
|
97 | + * |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public function espresso_session_footer_dump() |
|
101 | + { |
|
102 | + if ( |
|
103 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
104 | + && ! defined('DOING_AJAX') |
|
105 | + && class_exists('Kint') |
|
106 | + && function_exists('wp_get_current_user') |
|
107 | + && current_user_can('update_core') |
|
108 | + && class_exists('EE_Registry') |
|
109 | + ) { |
|
110 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
111 | + Kint::dump(EE_Registry::instance()->SSN); |
|
112 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
113 | + $this->espresso_list_hooked_functions(); |
|
114 | + Benchmark::displayResults(); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * List All Hooked Functions |
|
122 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
123 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
124 | + * |
|
125 | + * @param string $tag |
|
126 | + * @return void |
|
127 | + */ |
|
128 | + public function espresso_list_hooked_functions($tag = '') |
|
129 | + { |
|
130 | + global $wp_filter; |
|
131 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
132 | + if ($tag) { |
|
133 | + $hook[$tag] = $wp_filter[$tag]; |
|
134 | + if (! is_array($hook[$tag])) { |
|
135 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
136 | + return; |
|
137 | + } |
|
138 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
139 | + } else { |
|
140 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
141 | + ksort($hook); |
|
142 | + } |
|
143 | + foreach ($hook as $tag_name => $priorities) { |
|
144 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
145 | + ksort($priorities); |
|
146 | + foreach ($priorities as $priority => $function) { |
|
147 | + echo $priority; |
|
148 | + foreach ($function as $name => $properties) { |
|
149 | + echo "\t$name<br />"; |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * registered_filter_callbacks |
|
159 | + * |
|
160 | + * @param string $hook_name |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public static function registered_filter_callbacks($hook_name = '') |
|
164 | + { |
|
165 | + $filters = array(); |
|
166 | + global $wp_filter; |
|
167 | + if (isset($wp_filter[$hook_name])) { |
|
168 | + $filters[$hook_name] = array(); |
|
169 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | + $filters[$hook_name][$priority] = array(); |
|
171 | + foreach ($callbacks as $callback) { |
|
172 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + return $filters; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * captures plugin activation errors for debugging |
|
183 | + * |
|
184 | + * @return void |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public static function ee_plugin_activation_errors() |
|
188 | + { |
|
189 | + if (WP_DEBUG) { |
|
190 | + $activation_errors = ob_get_contents(); |
|
191 | + if (! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | + } |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | + if (class_exists('EEH_File')) { |
|
196 | + try { |
|
197 | + EEH_File::ensure_file_exists_and_is_writable( |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
199 | + ); |
|
200 | + EEH_File::write_to_file( |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
202 | + $activation_errors |
|
203 | + ); |
|
204 | + } catch (EE_Error $e) { |
|
205 | + EE_Error::add_error( |
|
206 | + sprintf( |
|
207 | + __( |
|
208 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | + 'event_espresso' |
|
210 | + ), |
|
211 | + $e->getMessage() |
|
212 | + ), |
|
213 | + __FILE__, __FUNCTION__, __LINE__ |
|
214 | + ); |
|
215 | + } |
|
216 | + } else { |
|
217 | + // old school attempt |
|
218 | + file_put_contents( |
|
219 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
220 | + $activation_errors |
|
221 | + ); |
|
222 | + } |
|
223 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
224 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
232 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
233 | + * or we want to make sure they use something the right way. |
|
234 | + * |
|
235 | + * @access public |
|
236 | + * @param string $function The function that was called |
|
237 | + * @param string $message A message explaining what has been done incorrectly |
|
238 | + * @param string $version The version of Event Espresso where the error was added |
|
239 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
240 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
241 | + * but not have any notices appear until a later version. This allows developers |
|
242 | + * extra time to update their code before notices appear. |
|
243 | + * @param int $error_type |
|
244 | + * @uses trigger_error() |
|
245 | + */ |
|
246 | + public function doing_it_wrong( |
|
247 | + $function, |
|
248 | + $message, |
|
249 | + $version, |
|
250 | + $applies_when = '', |
|
251 | + $error_type = null |
|
252 | + ) { |
|
253 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
254 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
255 | + // because we swapped the parameter order around for the last two params, |
|
256 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
257 | + if (is_int($applies_when)) { |
|
258 | + $error_type = $applies_when; |
|
259 | + $applies_when = espresso_version(); |
|
260 | + } |
|
261 | + // if not displaying notices yet, then just leave |
|
262 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
263 | + return; |
|
264 | + } |
|
265 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
266 | + $version = $version === null |
|
267 | + ? '' |
|
268 | + : sprintf( |
|
269 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
270 | + $version |
|
271 | + ); |
|
272 | + $error_message = sprintf( |
|
273 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
274 | + $function, |
|
275 | + '<strong>', |
|
276 | + '</strong>', |
|
277 | + $message, |
|
278 | + $version |
|
279 | + ); |
|
280 | + // don't trigger error if doing ajax, |
|
281 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
282 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
283 | + $error_message .= ' ' . esc_html__( |
|
284 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
285 | + 'event_espresso' |
|
286 | + ); |
|
287 | + $error_message .= '<ul><li>'; |
|
288 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
289 | + $error_message .= '</ul>'; |
|
290 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
291 | + //now we set this on the transient so it shows up on the next request. |
|
292 | + EE_Error::get_notices(false, true); |
|
293 | + } else { |
|
294 | + trigger_error($error_message, $error_type); |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Logger helpers |
|
303 | + */ |
|
304 | + /** |
|
305 | + * debug |
|
306 | + * |
|
307 | + * @param string $class |
|
308 | + * @param string $func |
|
309 | + * @param string $line |
|
310 | + * @param array $info |
|
311 | + * @param bool $display_request |
|
312 | + * @param string $debug_index |
|
313 | + * @param string $debug_key |
|
314 | + * @throws EE_Error |
|
315 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
316 | + */ |
|
317 | + public static function log( |
|
318 | + $class = '', |
|
319 | + $func = '', |
|
320 | + $line = '', |
|
321 | + $info = array(), |
|
322 | + $display_request = false, |
|
323 | + $debug_index = '', |
|
324 | + $debug_key = 'EE_DEBUG_SPCO' |
|
325 | + ) { |
|
326 | + if (WP_DEBUG) { |
|
327 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | + $debug_data = get_option($debug_key, array()); |
|
329 | + $default_data = array( |
|
330 | + $class => $func . '() : ' . $line, |
|
331 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
332 | + ); |
|
333 | + // don't serialize objects |
|
334 | + $info = self::strip_objects($info); |
|
335 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | + if (! isset($debug_data[$index])) { |
|
337 | + $debug_data[$index] = array(); |
|
338 | + } |
|
339 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | + update_option($debug_key, $debug_data); |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * strip_objects |
|
348 | + * |
|
349 | + * @param array $info |
|
350 | + * @return array |
|
351 | + */ |
|
352 | + public static function strip_objects($info = array()) |
|
353 | + { |
|
354 | + foreach ($info as $key => $value) { |
|
355 | + if (is_array($value)) { |
|
356 | + $info[$key] = self::strip_objects($value); |
|
357 | + } else if (is_object($value)) { |
|
358 | + $object_class = get_class($value); |
|
359 | + $info[$object_class] = array(); |
|
360 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | + if (method_exists($value, 'ID')) { |
|
362 | + $info[$object_class]['ID'] = $value->ID(); |
|
363 | + } |
|
364 | + if (method_exists($value, 'status')) { |
|
365 | + $info[$object_class]['status'] = $value->status(); |
|
366 | + } else if (method_exists($value, 'status_ID')) { |
|
367 | + $info[$object_class]['status'] = $value->status_ID(); |
|
368 | + } |
|
369 | + unset($info[$key]); |
|
370 | + } |
|
371 | + } |
|
372 | + return (array)$info; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @param mixed $var |
|
379 | + * @param string $var_name |
|
380 | + * @param string $file |
|
381 | + * @param int|string $line |
|
382 | + * @param int $heading_tag |
|
383 | + * @param bool $die |
|
384 | + * @param string $margin |
|
385 | + */ |
|
386 | + public static function printv( |
|
387 | + $var, |
|
388 | + $var_name = '', |
|
389 | + $file = '', |
|
390 | + $line = '', |
|
391 | + $heading_tag = 5, |
|
392 | + $die = false, |
|
393 | + $margin = '' |
|
394 | + ) { |
|
395 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | + $is_method = method_exists($var_name, $var); |
|
398 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
400 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
401 | + $result .= $is_method |
|
402 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
403 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
404 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
405 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
406 | + if ($die) { |
|
407 | + die($result); |
|
408 | + } |
|
409 | + echo $result; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @param string $var_name |
|
416 | + * @param string $heading_tag |
|
417 | + * @param string $margin |
|
418 | + * @return string |
|
419 | + */ |
|
420 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
421 | + { |
|
422 | + if (defined('EE_TESTS_DIR')) { |
|
423 | + return "\n{$var_name}"; |
|
424 | + } |
|
425 | + $margin = "25px 0 0 {$margin}"; |
|
426 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * @param string $heading_tag |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + protected static function headingX($heading_tag = 'h5') |
|
436 | + { |
|
437 | + if (defined('EE_TESTS_DIR')) { |
|
438 | + return ''; |
|
439 | + } |
|
440 | + return '</' . $heading_tag . '>'; |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * @param string $content |
|
447 | + * @return string |
|
448 | + */ |
|
449 | + protected static function grey_span($content = '') |
|
450 | + { |
|
451 | + if (defined('EE_TESTS_DIR')) { |
|
452 | + return $content; |
|
453 | + } |
|
454 | + return '<span style="color:#999">' . $content . '</span>'; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * @param string $file |
|
461 | + * @param int $line |
|
462 | + * @return string |
|
463 | + */ |
|
464 | + protected static function file_and_line($file, $line) |
|
465 | + { |
|
466 | + if ($file === '' || $line === '') { |
|
467 | + return ''; |
|
468 | + } |
|
469 | + if (defined('EE_TESTS_DIR')) { |
|
470 | + return "\n\t(" . $file . ' line no: ' . $line . ' ) '; |
|
471 | + } |
|
472 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
473 | + . $file |
|
474 | + . '<br />line no: ' |
|
475 | + . $line |
|
476 | + . '</span>'; |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * @param string $content |
|
483 | + * @return string |
|
484 | + */ |
|
485 | + protected static function orange_span($content = '') |
|
486 | + { |
|
487 | + if (defined('EE_TESTS_DIR')) { |
|
488 | + return $content; |
|
489 | + } |
|
490 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * @param mixed $var |
|
497 | + * @return string |
|
498 | + */ |
|
499 | + protected static function pre_span($var) |
|
500 | + { |
|
501 | + ob_start(); |
|
502 | + var_dump($var); |
|
503 | + $var = ob_get_clean(); |
|
504 | + if (defined('EE_TESTS_DIR')) { |
|
505 | + return "\n" . $var; |
|
506 | + } |
|
507 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * @param mixed $var |
|
514 | + * @param string $var_name |
|
515 | + * @param string $file |
|
516 | + * @param int|string $line |
|
517 | + * @param int $heading_tag |
|
518 | + * @param bool $die |
|
519 | + */ |
|
520 | + public static function printr( |
|
521 | + $var, |
|
522 | + $var_name = '', |
|
523 | + $file = '', |
|
524 | + $line = '', |
|
525 | + $heading_tag = 5, |
|
526 | + $die = false |
|
527 | + ) { |
|
528 | + // return; |
|
529 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
530 | + $margin = is_admin() ? ' 180px' : '0'; |
|
531 | + //$print_r = false; |
|
532 | + if (is_string($var)) { |
|
533 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
534 | + return; |
|
535 | + } |
|
536 | + if (is_object($var)) { |
|
537 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
538 | + //$print_r = true; |
|
539 | + } else if (is_array($var)) { |
|
540 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
541 | + //$print_r = true; |
|
542 | + } else if (is_numeric($var)) { |
|
543 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
544 | + } else if ($var === null) { |
|
545 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
546 | + } |
|
547 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
548 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
549 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
550 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
551 | + EEH_Debug_Tools::pre_span($var) |
|
552 | + ); |
|
553 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
554 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
555 | + if ($die) { |
|
556 | + die($result); |
|
557 | + } |
|
558 | + echo $result; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + |
|
563 | + /******************** deprecated ********************/ |
|
564 | + |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * @deprecated 4.9.39.rc.034 |
|
569 | + */ |
|
570 | + public function reset_times() |
|
571 | + { |
|
572 | + Benchmark::resetTimes(); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * @deprecated 4.9.39.rc.034 |
|
579 | + * @param null $timer_name |
|
580 | + */ |
|
581 | + public function start_timer($timer_name = null) |
|
582 | + { |
|
583 | + Benchmark::startTimer($timer_name); |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * @deprecated 4.9.39.rc.034 |
|
590 | + * @param string $timer_name |
|
591 | + */ |
|
592 | + public function stop_timer($timer_name = '') |
|
593 | + { |
|
594 | + Benchmark::stopTimer($timer_name); |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * @deprecated 4.9.39.rc.034 |
|
601 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
602 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
603 | + * @return void |
|
604 | + */ |
|
605 | + public function measure_memory($label, $output_now = false) |
|
606 | + { |
|
607 | + Benchmark::measureMemory($label, $output_now); |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * @deprecated 4.9.39.rc.034 |
|
614 | + * @param int $size |
|
615 | + * @return string |
|
616 | + */ |
|
617 | + public function convert($size) |
|
618 | + { |
|
619 | + return Benchmark::convert($size); |
|
620 | + } |
|
621 | + |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * @deprecated 4.9.39.rc.034 |
|
626 | + * @param bool $output_now |
|
627 | + * @return string |
|
628 | + */ |
|
629 | + public function show_times($output_now = true) |
|
630 | + { |
|
631 | + return Benchmark::displayResults($output_now); |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + |
|
636 | + /** |
|
637 | + * @deprecated 4.9.39.rc.034 |
|
638 | + * @param string $timer_name |
|
639 | + * @param float $total_time |
|
640 | + * @return string |
|
641 | + */ |
|
642 | + public function format_time($timer_name, $total_time) |
|
643 | + { |
|
644 | + return Benchmark::formatTime($timer_name, $total_time); |
|
645 | + } |
|
646 | 646 | |
647 | 647 | |
648 | 648 | |
@@ -655,31 +655,31 @@ discard block |
||
655 | 655 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
656 | 656 | */ |
657 | 657 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
658 | - function dump_wp_query() |
|
659 | - { |
|
660 | - global $wp_query; |
|
661 | - d($wp_query); |
|
662 | - } |
|
658 | + function dump_wp_query() |
|
659 | + { |
|
660 | + global $wp_query; |
|
661 | + d($wp_query); |
|
662 | + } |
|
663 | 663 | } |
664 | 664 | /** |
665 | 665 | * borrowed from Kint Debugger |
666 | 666 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
667 | 667 | */ |
668 | 668 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
669 | - function dump_wp() |
|
670 | - { |
|
671 | - global $wp; |
|
672 | - d($wp); |
|
673 | - } |
|
669 | + function dump_wp() |
|
670 | + { |
|
671 | + global $wp; |
|
672 | + d($wp); |
|
673 | + } |
|
674 | 674 | } |
675 | 675 | /** |
676 | 676 | * borrowed from Kint Debugger |
677 | 677 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
678 | 678 | */ |
679 | 679 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
680 | - function dump_post() |
|
681 | - { |
|
682 | - global $post; |
|
683 | - d($post); |
|
684 | - } |
|
680 | + function dump_post() |
|
681 | + { |
|
682 | + global $post; |
|
683 | + d($post); |
|
684 | + } |
|
685 | 685 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public static function instance() |
41 | 41 | { |
42 | 42 | // check if class object is instantiated, and instantiated properly |
43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
43 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | 44 | self::$_instance = new self(); |
45 | 45 | } |
46 | 46 | return self::$_instance; |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | private function __construct() |
55 | 55 | { |
56 | 56 | // load Kint PHP debugging library |
57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
57 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
58 | 58 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
59 | 59 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
60 | 60 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
61 | 61 | // so we've moved it to our test folder so that it is not included with production releases |
62 | 62 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
63 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
64 | 64 | } |
65 | 65 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
66 | 66 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public static function show_db_name() |
82 | 82 | { |
83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
83 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | 84 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
85 | 85 | . DB_NAME |
86 | 86 | . '</p>'; |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
132 | 132 | if ($tag) { |
133 | 133 | $hook[$tag] = $wp_filter[$tag]; |
134 | - if (! is_array($hook[$tag])) { |
|
134 | + if ( ! is_array($hook[$tag])) { |
|
135 | 135 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
136 | 136 | return; |
137 | 137 | } |
138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
138 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
139 | 139 | } else { |
140 | 140 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
141 | 141 | ksort($hook); |
@@ -188,17 +188,17 @@ discard block |
||
188 | 188 | { |
189 | 189 | if (WP_DEBUG) { |
190 | 190 | $activation_errors = ob_get_contents(); |
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
191 | + if ( ! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
193 | 193 | } |
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
195 | 195 | if (class_exists('EEH_File')) { |
196 | 196 | try { |
197 | 197 | EEH_File::ensure_file_exists_and_is_writable( |
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html' |
|
199 | 199 | ); |
200 | 200 | EEH_File::write_to_file( |
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
202 | 202 | $activation_errors |
203 | 203 | ); |
204 | 204 | } catch (EE_Error $e) { |
@@ -216,11 +216,11 @@ discard block |
||
216 | 216 | } else { |
217 | 217 | // old school attempt |
218 | 218 | file_put_contents( |
219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
219 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
220 | 220 | $activation_errors |
221 | 221 | ); |
222 | 222 | } |
223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
223 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
224 | 224 | update_option('ee_plugin_activation_errors', $activation_errors); |
225 | 225 | } |
226 | 226 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | // don't trigger error if doing ajax, |
281 | 281 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
282 | 282 | if (defined('DOING_AJAX') && DOING_AJAX) { |
283 | - $error_message .= ' ' . esc_html__( |
|
283 | + $error_message .= ' '.esc_html__( |
|
284 | 284 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
285 | 285 | 'event_espresso' |
286 | 286 | ); |
@@ -324,16 +324,16 @@ discard block |
||
324 | 324 | $debug_key = 'EE_DEBUG_SPCO' |
325 | 325 | ) { |
326 | 326 | if (WP_DEBUG) { |
327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
327 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
328 | 328 | $debug_data = get_option($debug_key, array()); |
329 | 329 | $default_data = array( |
330 | - $class => $func . '() : ' . $line, |
|
330 | + $class => $func.'() : '.$line, |
|
331 | 331 | 'REQ' => $display_request ? $_REQUEST : '', |
332 | 332 | ); |
333 | 333 | // don't serialize objects |
334 | 334 | $info = self::strip_objects($info); |
335 | 335 | $index = ! empty($debug_index) ? $debug_index : 0; |
336 | - if (! isset($debug_data[$index])) { |
|
336 | + if ( ! isset($debug_data[$index])) { |
|
337 | 337 | $debug_data[$index] = array(); |
338 | 338 | } |
339 | 339 | $debug_data[$index][microtime()] = array_merge($default_data, $info); |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | unset($info[$key]); |
370 | 370 | } |
371 | 371 | } |
372 | - return (array)$info; |
|
372 | + return (array) $info; |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
@@ -399,8 +399,8 @@ discard block |
||
399 | 399 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
400 | 400 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
401 | 401 | $result .= $is_method |
402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
402 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
403 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
404 | 404 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
405 | 405 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
406 | 406 | if ($die) { |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | return "\n{$var_name}"; |
424 | 424 | } |
425 | 425 | $margin = "25px 0 0 {$margin}"; |
426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
426 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | if (defined('EE_TESTS_DIR')) { |
438 | 438 | return ''; |
439 | 439 | } |
440 | - return '</' . $heading_tag . '>'; |
|
440 | + return '</'.$heading_tag.'>'; |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | if (defined('EE_TESTS_DIR')) { |
452 | 452 | return $content; |
453 | 453 | } |
454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
454 | + return '<span style="color:#999">'.$content.'</span>'; |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | return ''; |
468 | 468 | } |
469 | 469 | if (defined('EE_TESTS_DIR')) { |
470 | - return "\n\t(" . $file . ' line no: ' . $line . ' ) '; |
|
470 | + return "\n\t(".$file.' line no: '.$line.' ) '; |
|
471 | 471 | } |
472 | 472 | return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
473 | 473 | . $file |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | if (defined('EE_TESTS_DIR')) { |
488 | 488 | return $content; |
489 | 489 | } |
490 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
490 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | |
@@ -502,9 +502,9 @@ discard block |
||
502 | 502 | var_dump($var); |
503 | 503 | $var = ob_get_clean(); |
504 | 504 | if (defined('EE_TESTS_DIR')) { |
505 | - return "\n" . $var; |
|
505 | + return "\n".$var; |
|
506 | 506 | } |
507 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
507 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
548 | 548 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
549 | 549 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
550 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
550 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
551 | 551 | EEH_Debug_Tools::pre_span($var) |
552 | 552 | ); |
553 | 553 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter; |
3 | 3 | |
4 | 4 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -19,480 +19,480 @@ discard block |
||
19 | 19 | abstract class EE_Form_Section_Base |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * the URL the form is submitted to |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $_action; |
|
28 | - |
|
29 | - /** |
|
30 | - * POST (default) or GET |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $_method; |
|
35 | - |
|
36 | - /** |
|
37 | - * html_id and html_name are derived from this by default |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $_name; |
|
42 | - |
|
43 | - /** |
|
44 | - * $_html_id |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - protected $_html_id; |
|
48 | - |
|
49 | - /** |
|
50 | - * $_html_class |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $_html_class; |
|
54 | - |
|
55 | - /** |
|
56 | - * $_html_style |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - protected $_html_style; |
|
60 | - |
|
61 | - /** |
|
62 | - * $_other_html_attributes |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - protected $_other_html_attributes; |
|
66 | - |
|
67 | - /** |
|
68 | - * The form section of which this form section is a part |
|
69 | - * |
|
70 | - * @var EE_Form_Section_Proper |
|
71 | - */ |
|
72 | - protected $_parent_section; |
|
73 | - |
|
74 | - /** |
|
75 | - * flag indicating that _construct_finalize has been called. |
|
76 | - * If it has not been called and we try to use functions which require it, we call it |
|
77 | - * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
78 | - * |
|
79 | - * @var boolean |
|
80 | - */ |
|
81 | - protected $_construction_finalized; |
|
82 | - |
|
83 | - /** |
|
84 | - * Strategy for parsing the form HTML upon display |
|
85 | - * |
|
86 | - * @var FormHtmlFilter |
|
87 | - */ |
|
88 | - protected $_form_html_filter; |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @param array $options_array { |
|
94 | - * @type $name string the name for this form section, if you want to explicitly define it |
|
95 | - * } |
|
96 | - */ |
|
97 | - public function __construct($options_array = array()) |
|
98 | - { |
|
99 | - // used by display strategies |
|
100 | - // assign incoming values to properties |
|
101 | - foreach ($options_array as $key => $value) { |
|
102 | - $key = '_' . $key; |
|
103 | - if (property_exists($this, $key) && empty($this->{$key})) { |
|
104 | - $this->{$key} = $value; |
|
105 | - } |
|
106 | - } |
|
107 | - // set parser which allows the form section's rendered HTML to be filtered |
|
108 | - if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
109 | - $this->_form_html_filter = $options_array['form_html_filter']; |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @param $parent_form_section |
|
117 | - * @param $name |
|
118 | - * @throws \EE_Error |
|
119 | - */ |
|
120 | - protected function _construct_finalize($parent_form_section, $name) |
|
121 | - { |
|
122 | - $this->_construction_finalized = true; |
|
123 | - $this->_parent_section = $parent_form_section; |
|
124 | - if ($name !== null) { |
|
125 | - $this->_name = $name; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * make sure construction finalized was called, otherwise children might not be ready |
|
133 | - * |
|
134 | - * @return void |
|
135 | - * @throws \EE_Error |
|
136 | - */ |
|
137 | - public function ensure_construct_finalized_called() |
|
138 | - { |
|
139 | - if (! $this->_construction_finalized) { |
|
140 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function action() |
|
150 | - { |
|
151 | - return $this->_action; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @param string $action |
|
158 | - */ |
|
159 | - public function set_action($action) |
|
160 | - { |
|
161 | - $this->_action = $action; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public function method() |
|
170 | - { |
|
171 | - return ! empty($this->_method) ? $this->_method : 'POST'; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $method |
|
178 | - */ |
|
179 | - public function set_method($method) |
|
180 | - { |
|
181 | - switch ($method) { |
|
182 | - case 'get' : |
|
183 | - case 'GET' : |
|
184 | - $this->_method = 'GET'; |
|
185 | - break; |
|
186 | - default : |
|
187 | - $this->_method = 'POST'; |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * Sets the html_id to its default value, if none was specified in the constructor. |
|
195 | - * Calculation involves using the name and the parent's html id |
|
196 | - * return void |
|
197 | - * |
|
198 | - * @throws \EE_Error |
|
199 | - */ |
|
200 | - protected function _set_default_html_id_if_empty() |
|
201 | - { |
|
202 | - if (! $this->_html_id) { |
|
203 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
204 | - $this->_html_id = $this->_parent_section->html_id() |
|
205 | - . '-' |
|
206 | - . $this->_prep_name_for_html_id($this->name()); |
|
207 | - } else { |
|
208 | - $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
209 | - } |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * _prep_name_for_html_id |
|
217 | - * |
|
218 | - * @param $name |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - private function _prep_name_for_html_id($name) |
|
222 | - { |
|
223 | - return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
224 | - } |
|
22 | + /** |
|
23 | + * the URL the form is submitted to |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $_action; |
|
28 | + |
|
29 | + /** |
|
30 | + * POST (default) or GET |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $_method; |
|
35 | + |
|
36 | + /** |
|
37 | + * html_id and html_name are derived from this by default |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $_name; |
|
42 | + |
|
43 | + /** |
|
44 | + * $_html_id |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + protected $_html_id; |
|
48 | + |
|
49 | + /** |
|
50 | + * $_html_class |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $_html_class; |
|
54 | + |
|
55 | + /** |
|
56 | + * $_html_style |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + protected $_html_style; |
|
60 | + |
|
61 | + /** |
|
62 | + * $_other_html_attributes |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + protected $_other_html_attributes; |
|
66 | + |
|
67 | + /** |
|
68 | + * The form section of which this form section is a part |
|
69 | + * |
|
70 | + * @var EE_Form_Section_Proper |
|
71 | + */ |
|
72 | + protected $_parent_section; |
|
73 | + |
|
74 | + /** |
|
75 | + * flag indicating that _construct_finalize has been called. |
|
76 | + * If it has not been called and we try to use functions which require it, we call it |
|
77 | + * with no parameters. But normally, _construct_finalize should be called by the instantiating class |
|
78 | + * |
|
79 | + * @var boolean |
|
80 | + */ |
|
81 | + protected $_construction_finalized; |
|
82 | + |
|
83 | + /** |
|
84 | + * Strategy for parsing the form HTML upon display |
|
85 | + * |
|
86 | + * @var FormHtmlFilter |
|
87 | + */ |
|
88 | + protected $_form_html_filter; |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @param array $options_array { |
|
94 | + * @type $name string the name for this form section, if you want to explicitly define it |
|
95 | + * } |
|
96 | + */ |
|
97 | + public function __construct($options_array = array()) |
|
98 | + { |
|
99 | + // used by display strategies |
|
100 | + // assign incoming values to properties |
|
101 | + foreach ($options_array as $key => $value) { |
|
102 | + $key = '_' . $key; |
|
103 | + if (property_exists($this, $key) && empty($this->{$key})) { |
|
104 | + $this->{$key} = $value; |
|
105 | + } |
|
106 | + } |
|
107 | + // set parser which allows the form section's rendered HTML to be filtered |
|
108 | + if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) { |
|
109 | + $this->_form_html_filter = $options_array['form_html_filter']; |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @param $parent_form_section |
|
117 | + * @param $name |
|
118 | + * @throws \EE_Error |
|
119 | + */ |
|
120 | + protected function _construct_finalize($parent_form_section, $name) |
|
121 | + { |
|
122 | + $this->_construction_finalized = true; |
|
123 | + $this->_parent_section = $parent_form_section; |
|
124 | + if ($name !== null) { |
|
125 | + $this->_name = $name; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * make sure construction finalized was called, otherwise children might not be ready |
|
133 | + * |
|
134 | + * @return void |
|
135 | + * @throws \EE_Error |
|
136 | + */ |
|
137 | + public function ensure_construct_finalized_called() |
|
138 | + { |
|
139 | + if (! $this->_construction_finalized) { |
|
140 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function action() |
|
150 | + { |
|
151 | + return $this->_action; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @param string $action |
|
158 | + */ |
|
159 | + public function set_action($action) |
|
160 | + { |
|
161 | + $this->_action = $action; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public function method() |
|
170 | + { |
|
171 | + return ! empty($this->_method) ? $this->_method : 'POST'; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $method |
|
178 | + */ |
|
179 | + public function set_method($method) |
|
180 | + { |
|
181 | + switch ($method) { |
|
182 | + case 'get' : |
|
183 | + case 'GET' : |
|
184 | + $this->_method = 'GET'; |
|
185 | + break; |
|
186 | + default : |
|
187 | + $this->_method = 'POST'; |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * Sets the html_id to its default value, if none was specified in the constructor. |
|
195 | + * Calculation involves using the name and the parent's html id |
|
196 | + * return void |
|
197 | + * |
|
198 | + * @throws \EE_Error |
|
199 | + */ |
|
200 | + protected function _set_default_html_id_if_empty() |
|
201 | + { |
|
202 | + if (! $this->_html_id) { |
|
203 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
204 | + $this->_html_id = $this->_parent_section->html_id() |
|
205 | + . '-' |
|
206 | + . $this->_prep_name_for_html_id($this->name()); |
|
207 | + } else { |
|
208 | + $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
209 | + } |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * _prep_name_for_html_id |
|
217 | + * |
|
218 | + * @param $name |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + private function _prep_name_for_html_id($name) |
|
222 | + { |
|
223 | + return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
224 | + } |
|
225 | 225 | |
226 | 226 | |
227 | 227 | |
228 | - /** |
|
229 | - * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
230 | - * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
231 | - * and call get_html when you want to output the html. Calling get_html_and_js after |
|
232 | - * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
233 | - * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
234 | - * and so might stop working anytime. |
|
235 | - * |
|
236 | - * @return string |
|
237 | - */ |
|
238 | - public function get_html_and_js() |
|
239 | - { |
|
240 | - return $this->get_html(); |
|
241 | - } |
|
228 | + /** |
|
229 | + * Returns the HTML, JS, and CSS necessary to display this form section on a page. |
|
230 | + * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action, |
|
231 | + * and call get_html when you want to output the html. Calling get_html_and_js after |
|
232 | + * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary |
|
233 | + * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/ |
|
234 | + * and so might stop working anytime. |
|
235 | + * |
|
236 | + * @return string |
|
237 | + */ |
|
238 | + public function get_html_and_js() |
|
239 | + { |
|
240 | + return $this->get_html(); |
|
241 | + } |
|
242 | 242 | |
243 | 243 | |
244 | 244 | |
245 | - /** |
|
246 | - * Gets the HTML for displaying this form section |
|
247 | - * |
|
248 | - * @return string |
|
249 | - */ |
|
250 | - public abstract function get_html(); |
|
245 | + /** |
|
246 | + * Gets the HTML for displaying this form section |
|
247 | + * |
|
248 | + * @return string |
|
249 | + */ |
|
250 | + public abstract function get_html(); |
|
251 | 251 | |
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * @param bool $add_pound_sign |
|
256 | - * @return string |
|
257 | - */ |
|
258 | - public function html_id($add_pound_sign = false) |
|
259 | - { |
|
260 | - $this->_set_default_html_id_if_empty(); |
|
261 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
262 | - } |
|
254 | + /** |
|
255 | + * @param bool $add_pound_sign |
|
256 | + * @return string |
|
257 | + */ |
|
258 | + public function html_id($add_pound_sign = false) |
|
259 | + { |
|
260 | + $this->_set_default_html_id_if_empty(); |
|
261 | + return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
262 | + } |
|
263 | 263 | |
264 | 264 | |
265 | - |
|
266 | - /** |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function html_class() |
|
270 | - { |
|
271 | - return $this->_html_class; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - public function html_style() |
|
280 | - { |
|
281 | - return $this->_html_style; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @param mixed $html_class |
|
288 | - */ |
|
289 | - public function set_html_class($html_class) |
|
290 | - { |
|
291 | - $this->_html_class = $html_class; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * @param mixed $html_id |
|
298 | - */ |
|
299 | - public function set_html_id($html_id) |
|
300 | - { |
|
301 | - $this->_html_id = $html_id; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * @param mixed $html_style |
|
308 | - */ |
|
309 | - public function set_html_style($html_style) |
|
310 | - { |
|
311 | - $this->_html_style = $html_style; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * @param string $other_html_attributes |
|
318 | - */ |
|
319 | - public function set_other_html_attributes($other_html_attributes) |
|
320 | - { |
|
321 | - $this->_other_html_attributes = $other_html_attributes; |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @return string |
|
328 | - */ |
|
329 | - public function other_html_attributes() |
|
330 | - { |
|
331 | - return $this->_other_html_attributes; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * Gets the name of the form section. This is not the same as the HTML name. |
|
338 | - * |
|
339 | - * @throws EE_Error |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public function name() |
|
343 | - { |
|
344 | - if (! $this->_construction_finalized) { |
|
345 | - throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
|
346 | - 'event_espresso'), get_class($this))); |
|
347 | - } |
|
348 | - return $this->_name; |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * Gets the parent section |
|
355 | - * |
|
356 | - * @return EE_Form_Section_Proper |
|
357 | - */ |
|
358 | - public function parent_section() |
|
359 | - { |
|
360 | - return $this->_parent_section; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * returns HTML for generating the opening form HTML tag (<form>) |
|
367 | - * |
|
368 | - * @param string $action the URL the form is submitted to |
|
369 | - * @param string $method POST (default) or GET |
|
370 | - * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
371 | - * @return string |
|
372 | - */ |
|
373 | - public function form_open($action = '', $method = '', $other_attributes = '') |
|
374 | - { |
|
375 | - if (! empty($action)) { |
|
376 | - $this->set_action($action); |
|
377 | - } |
|
378 | - if (! empty($method)) { |
|
379 | - $this->set_method($method); |
|
380 | - } |
|
381 | - $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
382 | - $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
383 | - $html .= ' action="' . $this->action() . '"'; |
|
384 | - $html .= ' method="' . $this->method() . '"'; |
|
385 | - $html .= $other_attributes . '>'; |
|
386 | - return $html; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * ensures that html id for form either ends in "-form" or "-frm" |
|
393 | - * so that id doesn't conflict/collide with other elements |
|
394 | - * |
|
395 | - * @param string $html_id |
|
396 | - * @return string |
|
397 | - */ |
|
398 | - protected function get_html_id_for_form($html_id) |
|
399 | - { |
|
400 | - $strlen = strlen($html_id); |
|
401 | - $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4 |
|
402 | - ? $html_id |
|
403 | - : $html_id . '-frm'; |
|
404 | - return $html_id; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * returns HTML for generating the closing form HTML tag (</form>) |
|
411 | - * |
|
412 | - * @return string |
|
413 | - */ |
|
414 | - public function form_close() |
|
415 | - { |
|
416 | - return EEH_HTML::nl(-1, 'form') |
|
417 | - . '</form>' |
|
418 | - . EEH_HTML::nl() |
|
419 | - . '<!-- end of ee-' |
|
420 | - . $this->html_id() |
|
421 | - . '-form -->' |
|
422 | - . EEH_HTML::nl(); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
429 | - * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
430 | - * Default does nothing, but child classes can override |
|
431 | - * |
|
432 | - * @return void |
|
433 | - */ |
|
434 | - public function enqueue_js() |
|
435 | - { |
|
436 | - //defaults to enqueue NO js or css |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
443 | - * with it, and it will be on each form section's 'other_data' property. |
|
444 | - * By default nothing is added, but child classes can extend this method to add something. |
|
445 | - * Eg, if you have an input that will cause a modal dialog to appear, |
|
446 | - * here you could add an entry like 'modal_dialog_inputs' to this array |
|
447 | - * to map between the input's html ID and the modal dialogue's ID, so that |
|
448 | - * your JS code will know where to find the modal dialog when the input is pressed. |
|
449 | - * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
450 | - * |
|
451 | - * @param array $form_other_js_data |
|
452 | - * @return array |
|
453 | - */ |
|
454 | - public function get_other_js_data($form_other_js_data = array()) |
|
455 | - { |
|
456 | - return $form_other_js_data; |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
463 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
464 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
465 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
466 | - * which will be returned. |
|
467 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
468 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
469 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
470 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
471 | - * Etc |
|
472 | - * |
|
473 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
474 | - * @return EE_Form_Section_Base |
|
475 | - */ |
|
476 | - public function find_section_from_path($form_section_path) |
|
477 | - { |
|
478 | - if (strpos($form_section_path, '/') === 0) { |
|
479 | - $form_section_path = substr($form_section_path, strlen('/')); |
|
480 | - } |
|
481 | - if (empty($form_section_path)) { |
|
482 | - return $this; |
|
483 | - } |
|
484 | - if (strpos($form_section_path, '../') === 0) { |
|
485 | - $parent = $this->parent_section(); |
|
486 | - $form_section_path = substr($form_section_path, strlen('../')); |
|
487 | - if ($parent instanceof EE_Form_Section_Base) { |
|
488 | - return $parent->find_section_from_path($form_section_path); |
|
489 | - } elseif (empty($form_section_path)) { |
|
490 | - return $this; |
|
491 | - } |
|
492 | - } |
|
493 | - //couldn't find it using simple parent following |
|
494 | - return null; |
|
495 | - } |
|
265 | + |
|
266 | + /** |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function html_class() |
|
270 | + { |
|
271 | + return $this->_html_class; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + public function html_style() |
|
280 | + { |
|
281 | + return $this->_html_style; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @param mixed $html_class |
|
288 | + */ |
|
289 | + public function set_html_class($html_class) |
|
290 | + { |
|
291 | + $this->_html_class = $html_class; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * @param mixed $html_id |
|
298 | + */ |
|
299 | + public function set_html_id($html_id) |
|
300 | + { |
|
301 | + $this->_html_id = $html_id; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * @param mixed $html_style |
|
308 | + */ |
|
309 | + public function set_html_style($html_style) |
|
310 | + { |
|
311 | + $this->_html_style = $html_style; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * @param string $other_html_attributes |
|
318 | + */ |
|
319 | + public function set_other_html_attributes($other_html_attributes) |
|
320 | + { |
|
321 | + $this->_other_html_attributes = $other_html_attributes; |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @return string |
|
328 | + */ |
|
329 | + public function other_html_attributes() |
|
330 | + { |
|
331 | + return $this->_other_html_attributes; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * Gets the name of the form section. This is not the same as the HTML name. |
|
338 | + * |
|
339 | + * @throws EE_Error |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public function name() |
|
343 | + { |
|
344 | + if (! $this->_construction_finalized) { |
|
345 | + throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', |
|
346 | + 'event_espresso'), get_class($this))); |
|
347 | + } |
|
348 | + return $this->_name; |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * Gets the parent section |
|
355 | + * |
|
356 | + * @return EE_Form_Section_Proper |
|
357 | + */ |
|
358 | + public function parent_section() |
|
359 | + { |
|
360 | + return $this->_parent_section; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * returns HTML for generating the opening form HTML tag (<form>) |
|
367 | + * |
|
368 | + * @param string $action the URL the form is submitted to |
|
369 | + * @param string $method POST (default) or GET |
|
370 | + * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
|
371 | + * @return string |
|
372 | + */ |
|
373 | + public function form_open($action = '', $method = '', $other_attributes = '') |
|
374 | + { |
|
375 | + if (! empty($action)) { |
|
376 | + $this->set_action($action); |
|
377 | + } |
|
378 | + if (! empty($method)) { |
|
379 | + $this->set_method($method); |
|
380 | + } |
|
381 | + $html = EEH_HTML::nl(1, 'form') . '<form'; |
|
382 | + $html .= $this->html_id() !== '' ? ' id="' . $this->get_html_id_for_form($this->html_id()) . '"' : ''; |
|
383 | + $html .= ' action="' . $this->action() . '"'; |
|
384 | + $html .= ' method="' . $this->method() . '"'; |
|
385 | + $html .= $other_attributes . '>'; |
|
386 | + return $html; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * ensures that html id for form either ends in "-form" or "-frm" |
|
393 | + * so that id doesn't conflict/collide with other elements |
|
394 | + * |
|
395 | + * @param string $html_id |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + protected function get_html_id_for_form($html_id) |
|
399 | + { |
|
400 | + $strlen = strlen($html_id); |
|
401 | + $html_id = strpos($html_id, '-form') === $strlen-5 || strpos($html_id, '-frm') === $strlen - 4 |
|
402 | + ? $html_id |
|
403 | + : $html_id . '-frm'; |
|
404 | + return $html_id; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * returns HTML for generating the closing form HTML tag (</form>) |
|
411 | + * |
|
412 | + * @return string |
|
413 | + */ |
|
414 | + public function form_close() |
|
415 | + { |
|
416 | + return EEH_HTML::nl(-1, 'form') |
|
417 | + . '</form>' |
|
418 | + . EEH_HTML::nl() |
|
419 | + . '<!-- end of ee-' |
|
420 | + . $this->html_id() |
|
421 | + . '-form -->' |
|
422 | + . EEH_HTML::nl(); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and |
|
429 | + * wp_enqueue_style; the scripts could have optionally been registered earlier) |
|
430 | + * Default does nothing, but child classes can override |
|
431 | + * |
|
432 | + * @return void |
|
433 | + */ |
|
434 | + public function enqueue_js() |
|
435 | + { |
|
436 | + //defaults to enqueue NO js or css |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * Adds any extra data needed by js. Eventually we'll call wp_localize_script |
|
443 | + * with it, and it will be on each form section's 'other_data' property. |
|
444 | + * By default nothing is added, but child classes can extend this method to add something. |
|
445 | + * Eg, if you have an input that will cause a modal dialog to appear, |
|
446 | + * here you could add an entry like 'modal_dialog_inputs' to this array |
|
447 | + * to map between the input's html ID and the modal dialogue's ID, so that |
|
448 | + * your JS code will know where to find the modal dialog when the input is pressed. |
|
449 | + * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id'; |
|
450 | + * |
|
451 | + * @param array $form_other_js_data |
|
452 | + * @return array |
|
453 | + */ |
|
454 | + public function get_other_js_data($form_other_js_data = array()) |
|
455 | + { |
|
456 | + return $form_other_js_data; |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
463 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
464 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
465 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
466 | + * which will be returned. |
|
467 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
468 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
469 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
470 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
471 | + * Etc |
|
472 | + * |
|
473 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
474 | + * @return EE_Form_Section_Base |
|
475 | + */ |
|
476 | + public function find_section_from_path($form_section_path) |
|
477 | + { |
|
478 | + if (strpos($form_section_path, '/') === 0) { |
|
479 | + $form_section_path = substr($form_section_path, strlen('/')); |
|
480 | + } |
|
481 | + if (empty($form_section_path)) { |
|
482 | + return $this; |
|
483 | + } |
|
484 | + if (strpos($form_section_path, '../') === 0) { |
|
485 | + $parent = $this->parent_section(); |
|
486 | + $form_section_path = substr($form_section_path, strlen('../')); |
|
487 | + if ($parent instanceof EE_Form_Section_Base) { |
|
488 | + return $parent->find_section_from_path($form_section_path); |
|
489 | + } elseif (empty($form_section_path)) { |
|
490 | + return $this; |
|
491 | + } |
|
492 | + } |
|
493 | + //couldn't find it using simple parent following |
|
494 | + return null; |
|
495 | + } |
|
496 | 496 | |
497 | 497 | |
498 | 498 | } |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | { |
36 | 36 | parent::__construct($routing); |
37 | 37 | if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
38 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
39 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
40 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
38 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/'); |
|
39 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/'); |
|
40 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/'); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | protected function _extend_page_config() |
47 | 47 | { |
48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations'; |
|
49 | 49 | $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
50 | 50 | ? $this->_req_data['_REG_ID'] |
51 | 51 | : 0; |
@@ -178,14 +178,14 @@ discard block |
||
178 | 178 | //enqueue newsletter js |
179 | 179 | wp_enqueue_script( |
180 | 180 | 'ee-newsletter-trigger', |
181 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
181 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js', |
|
182 | 182 | array('ee-dialog'), |
183 | 183 | EVENT_ESPRESSO_VERSION, |
184 | 184 | true |
185 | 185 | ); |
186 | 186 | wp_enqueue_style( |
187 | 187 | 'ee-newsletter-trigger-css', |
188 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
188 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css', |
|
189 | 189 | array(), |
190 | 190 | EVENT_ESPRESSO_VERSION |
191 | 191 | ); |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | { |
205 | 205 | wp_register_script( |
206 | 206 | 'ee-reg-reports-js', |
207 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
207 | + REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js', |
|
208 | 208 | array('google-charts'), |
209 | 209 | EVENT_ESPRESSO_VERSION, |
210 | 210 | true |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | $codes[$field] = implode(', ', array_keys($shortcode_array)); |
410 | 410 | } |
411 | 411 | $shortcodes = $codes; |
412 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
412 | + $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php'; |
|
413 | 413 | $form_template_args = array( |
414 | 414 | 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
415 | 415 | 'form_route' => 'newsletter_selected_send', |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | */ |
571 | 571 | protected function _registration_reports() |
572 | 572 | { |
573 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
573 | + $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php'; |
|
574 | 574 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
575 | 575 | $template_path, |
576 | 576 | $this->_reports_template_data, |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | { |
593 | 593 | $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
594 | 594 | $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
595 | - $results = (array)$results; |
|
595 | + $results = (array) $results; |
|
596 | 596 | $regs = array(); |
597 | 597 | $subtitle = ''; |
598 | 598 | if ($results) { |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | $report_column_values = array(); |
603 | 603 | foreach ($result as $property_name => $property_value) { |
604 | 604 | $property_value = $property_name === 'Registration_REG_date' ? $property_value |
605 | - : (int)$property_value; |
|
605 | + : (int) $property_value; |
|
606 | 606 | $report_column_values[] = $property_value; |
607 | 607 | if ($tracker === 0) { |
608 | 608 | if ($property_name === 'Registration_REG_date') { |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | array_unshift($regs, $column_titles); |
620 | 620 | //setup the date range. |
621 | 621 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
622 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
622 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
623 | 623 | $ending_date = new DateTime("now", $DateTimeZone); |
624 | 624 | $subtitle = sprintf( |
625 | 625 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | '%sThere are currently no registration records in the last month for this report.%s', |
640 | 640 | 'event_espresso' |
641 | 641 | ), |
642 | - '<h2>' . $report_title . '</h2><p>', |
|
642 | + '<h2>'.$report_title.'</h2><p>', |
|
643 | 643 | '</p>' |
644 | 644 | ), |
645 | 645 | ); |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | { |
660 | 660 | $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
661 | 661 | $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
662 | - $results = (array)$results; |
|
662 | + $results = (array) $results; |
|
663 | 663 | $regs = array(); |
664 | 664 | $subtitle = ''; |
665 | 665 | if ($results) { |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | $property_value, |
673 | 673 | 4, |
674 | 674 | '...' |
675 | - ) : (int)$property_value; |
|
675 | + ) : (int) $property_value; |
|
676 | 676 | $report_column_values[] = $property_value; |
677 | 677 | if ($tracker === 0) { |
678 | 678 | if ($property_name === 'Registration_Event') { |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | array_unshift($regs, $column_titles); |
690 | 690 | //setup the date range. |
691 | 691 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
692 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
692 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
693 | 693 | $ending_date = new DateTime("now", $DateTimeZone); |
694 | 694 | $subtitle = sprintf( |
695 | 695 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | '%sThere are currently no registration records in the last month for this report.%s', |
710 | 710 | 'event_espresso' |
711 | 711 | ), |
712 | - '<h2>' . $report_title . '</h2><p>', |
|
712 | + '<h2>'.$report_title.'</h2><p>', |
|
713 | 713 | '</p>' |
714 | 714 | ), |
715 | 715 | ); |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | if ($datetime instanceof EE_Datetime) { |
758 | 758 | $datetime_label = $datetime->get_dtt_display_name(true); |
759 | 759 | $datetime_label .= ! empty($datetime_label) |
760 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
760 | + ? ' ('.$datetime->get_dtt_display_name().')' |
|
761 | 761 | : $datetime->get_dtt_display_name(); |
762 | 762 | } |
763 | 763 | $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | ) |
772 | 772 | : ''; |
773 | 773 | $datetime_link = ! empty($datetime_link) |
774 | - ? '<a href="' . $datetime_link . '">' |
|
774 | + ? '<a href="'.$datetime_link.'">' |
|
775 | 775 | . '<span id="checkin-dtt">' |
776 | 776 | . $datetime_label |
777 | 777 | . '</span></a>' |
@@ -783,8 +783,8 @@ discard block |
||
783 | 783 | ? $attendee->get_admin_details_link() |
784 | 784 | : ''; |
785 | 785 | $attendee_link = ! empty($attendee_link) |
786 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
787 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
786 | + ? '<a href="'.$attendee->get_admin_details_link().'"' |
|
787 | + . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">' |
|
788 | 788 | . '<span id="checkin-attendee-name">' |
789 | 789 | . $attendee_name |
790 | 790 | . '</span></a>' |
@@ -793,25 +793,25 @@ discard block |
||
793 | 793 | ? $registration->event()->get_admin_details_link() |
794 | 794 | : ''; |
795 | 795 | $event_link = ! empty($event_link) |
796 | - ? '<a href="' . $event_link . '"' |
|
797 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
796 | + ? '<a href="'.$event_link.'"' |
|
797 | + . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">' |
|
798 | 798 | . '<span id="checkin-event-name">' |
799 | 799 | . $registration->event_name() |
800 | 800 | . '</span>' |
801 | 801 | . '</a>' |
802 | 802 | : ''; |
803 | 803 | $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
804 | - ? '<h2>' . sprintf( |
|
804 | + ? '<h2>'.sprintf( |
|
805 | 805 | esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
806 | 806 | $attendee_link, |
807 | 807 | $datetime_link, |
808 | 808 | $event_link |
809 | - ) . '</h2>' |
|
809 | + ).'</h2>' |
|
810 | 810 | : ''; |
811 | 811 | $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
812 | - ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : ''; |
|
812 | + ? '<input type="hidden" name="_REGID" value="'.$reg_id.'">' : ''; |
|
813 | 813 | $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
814 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
814 | + ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : ''; |
|
815 | 815 | $this->display_admin_list_table_page_with_no_sidebar(); |
816 | 816 | } |
817 | 817 | |
@@ -1052,37 +1052,37 @@ discard block |
||
1052 | 1052 | 'desc' => __('View All Check-in Records for this Registrant', 'event_espresso'), |
1053 | 1053 | ), |
1054 | 1054 | 'approved_status' => array( |
1055 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1055 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved, |
|
1056 | 1056 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
1057 | 1057 | ), |
1058 | 1058 | 'cancelled_status' => array( |
1059 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1059 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled, |
|
1060 | 1060 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
1061 | 1061 | ), |
1062 | 1062 | 'declined_status' => array( |
1063 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1063 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined, |
|
1064 | 1064 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
1065 | 1065 | ), |
1066 | 1066 | 'not_approved' => array( |
1067 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1067 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved, |
|
1068 | 1068 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
1069 | 1069 | ), |
1070 | 1070 | 'pending_status' => array( |
1071 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1071 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment, |
|
1072 | 1072 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
1073 | 1073 | ), |
1074 | 1074 | 'wait_list' => array( |
1075 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1075 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list, |
|
1076 | 1076 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
1077 | 1077 | ), |
1078 | 1078 | ); |
1079 | 1079 | $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
1080 | 1080 | $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
1081 | 1081 | $this->_template_args['before_list_table'] = ! empty($event_id) |
1082 | - ? '<h2>' . sprintf( |
|
1082 | + ? '<h2>'.sprintf( |
|
1083 | 1083 | __('Viewing Registrations for Event: %s', 'event_espresso'), |
1084 | 1084 | EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
1085 | - ) . '</h2>' |
|
1085 | + ).'</h2>' |
|
1086 | 1086 | : ''; |
1087 | 1087 | //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event. |
1088 | 1088 | /** @var EE_Event $event */ |
@@ -1101,7 +1101,7 @@ discard block |
||
1101 | 1101 | $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
1102 | 1102 | $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
1103 | 1103 | $this->_template_args['before_list_table'] .= $datetime->name(); |
1104 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1104 | + $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )'; |
|
1105 | 1105 | $this->_template_args['before_list_table'] .= '</span></h2>'; |
1106 | 1106 | } |
1107 | 1107 | //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column |
@@ -1168,11 +1168,11 @@ discard block |
||
1168 | 1168 | //normalize some request params that get setup by the parent `get_registrations` method. |
1169 | 1169 | $request = $this->_req_data; |
1170 | 1170 | $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
1171 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1172 | - if($trash){ |
|
1171 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1172 | + if ($trash) { |
|
1173 | 1173 | $request['status'] = 'trash'; |
1174 | 1174 | } |
1175 | - $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count ); |
|
1175 | + $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
1176 | 1176 | /** |
1177 | 1177 | * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
1178 | 1178 | * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -17,1177 +17,1177 @@ discard block |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * This is used to hold the reports template data which is setup early in the request. |
|
22 | - * |
|
23 | - * @type array |
|
24 | - */ |
|
25 | - protected $_reports_template_data = array(); |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * Extend_Registrations_Admin_Page constructor. |
|
31 | - * |
|
32 | - * @param bool $routing |
|
33 | - */ |
|
34 | - public function __construct($routing = true) |
|
35 | - { |
|
36 | - parent::__construct($routing); |
|
37 | - if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
38 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
39 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
40 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
41 | - } |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - |
|
46 | - protected function _extend_page_config() |
|
47 | - { |
|
48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
49 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
50 | - ? $this->_req_data['_REG_ID'] |
|
51 | - : 0; |
|
52 | - // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0; |
|
53 | - // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) |
|
54 | - // ? $this->_req_data['post'] : $att_id; |
|
55 | - $new_page_routes = array( |
|
56 | - 'reports' => array( |
|
57 | - 'func' => '_registration_reports', |
|
58 | - 'capability' => 'ee_read_registrations', |
|
59 | - ), |
|
60 | - 'registration_checkins' => array( |
|
61 | - 'func' => '_registration_checkin_list_table', |
|
62 | - 'capability' => 'ee_read_checkins', |
|
63 | - ), |
|
64 | - 'newsletter_selected_send' => array( |
|
65 | - 'func' => '_newsletter_selected_send', |
|
66 | - 'noheader' => true, |
|
67 | - 'capability' => 'ee_send_message', |
|
68 | - ), |
|
69 | - 'delete_checkin_rows' => array( |
|
70 | - 'func' => '_delete_checkin_rows', |
|
71 | - 'noheader' => true, |
|
72 | - 'capability' => 'ee_delete_checkins', |
|
73 | - ), |
|
74 | - 'delete_checkin_row' => array( |
|
75 | - 'func' => '_delete_checkin_row', |
|
76 | - 'noheader' => true, |
|
77 | - 'capability' => 'ee_delete_checkin', |
|
78 | - 'obj_id' => $reg_id, |
|
79 | - ), |
|
80 | - 'toggle_checkin_status' => array( |
|
81 | - 'func' => '_toggle_checkin_status', |
|
82 | - 'noheader' => true, |
|
83 | - 'capability' => 'ee_edit_checkin', |
|
84 | - 'obj_id' => $reg_id, |
|
85 | - ), |
|
86 | - 'toggle_checkin_status_bulk' => array( |
|
87 | - 'func' => '_toggle_checkin_status', |
|
88 | - 'noheader' => true, |
|
89 | - 'capability' => 'ee_edit_checkins' |
|
90 | - ), |
|
91 | - 'event_registrations' => array( |
|
92 | - 'func' => '_event_registrations_list_table', |
|
93 | - 'capability' => 'ee_read_checkins', |
|
94 | - ), |
|
95 | - 'registrations_checkin_report' => array( |
|
96 | - 'func' => '_registrations_checkin_report', |
|
97 | - 'noheader' => true, |
|
98 | - 'capability' => 'ee_read_registrations', |
|
99 | - ), |
|
100 | - ); |
|
101 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
102 | - $new_page_config = array( |
|
103 | - 'reports' => array( |
|
104 | - 'nav' => array( |
|
105 | - 'label' => __('Reports', 'event_espresso'), |
|
106 | - 'order' => 30, |
|
107 | - ), |
|
108 | - 'help_tabs' => array( |
|
109 | - 'registrations_reports_help_tab' => array( |
|
110 | - 'title' => __('Registration Reports', 'event_espresso'), |
|
111 | - 'filename' => 'registrations_reports', |
|
112 | - ), |
|
113 | - ), |
|
114 | - /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
115 | - 'require_nonce' => false, |
|
116 | - ), |
|
117 | - 'event_registrations' => array( |
|
118 | - 'nav' => array( |
|
119 | - 'label' => __('Event Check-In', 'event_espresso'), |
|
120 | - 'order' => 10, |
|
121 | - 'persistent' => true, |
|
122 | - ), |
|
123 | - 'help_tabs' => array( |
|
124 | - 'registrations_event_checkin_help_tab' => array( |
|
125 | - 'title' => __('Registrations Event Check-In', 'event_espresso'), |
|
126 | - 'filename' => 'registrations_event_checkin', |
|
127 | - ), |
|
128 | - 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
129 | - 'title' => __('Event Check-In Table Column Headings', 'event_espresso'), |
|
130 | - 'filename' => 'registrations_event_checkin_table_column_headings', |
|
131 | - ), |
|
132 | - 'registrations_event_checkin_filters_help_tab' => array( |
|
133 | - 'title' => __('Event Check-In Filters', 'event_espresso'), |
|
134 | - 'filename' => 'registrations_event_checkin_filters', |
|
135 | - ), |
|
136 | - 'registrations_event_checkin_views_help_tab' => array( |
|
137 | - 'title' => __('Event Check-In Views', 'event_espresso'), |
|
138 | - 'filename' => 'registrations_event_checkin_views', |
|
139 | - ), |
|
140 | - 'registrations_event_checkin_other_help_tab' => array( |
|
141 | - 'title' => __('Event Check-In Other', 'event_espresso'), |
|
142 | - 'filename' => 'registrations_event_checkin_other', |
|
143 | - ), |
|
144 | - ), |
|
145 | - 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
146 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
147 | - 'list_table' => 'EE_Event_Registrations_List_Table', |
|
148 | - 'metaboxes' => array(), |
|
149 | - 'require_nonce' => false, |
|
150 | - ), |
|
151 | - 'registration_checkins' => array( |
|
152 | - 'nav' => array( |
|
153 | - 'label' => __('Check-In Records', 'event_espresso'), |
|
154 | - 'order' => 15, |
|
155 | - 'persistent' => false, |
|
156 | - ), |
|
157 | - 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
158 | - //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
159 | - 'metaboxes' => array(), |
|
160 | - 'require_nonce' => false, |
|
161 | - ), |
|
162 | - ); |
|
163 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
164 | - $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
165 | - $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - protected function _ajax_hooks() |
|
171 | - { |
|
172 | - parent::_ajax_hooks(); |
|
173 | - add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - public function load_scripts_styles() |
|
179 | - { |
|
180 | - parent::load_scripts_styles(); |
|
181 | - //if newsletter message type is active then let's add filter and load js for it. |
|
182 | - if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
183 | - //enqueue newsletter js |
|
184 | - wp_enqueue_script( |
|
185 | - 'ee-newsletter-trigger', |
|
186 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
187 | - array('ee-dialog'), |
|
188 | - EVENT_ESPRESSO_VERSION, |
|
189 | - true |
|
190 | - ); |
|
191 | - wp_enqueue_style( |
|
192 | - 'ee-newsletter-trigger-css', |
|
193 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
194 | - array(), |
|
195 | - EVENT_ESPRESSO_VERSION |
|
196 | - ); |
|
197 | - //hook in buttons for newsletter message type trigger. |
|
198 | - add_action( |
|
199 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
200 | - array($this, 'add_newsletter_action_buttons'), |
|
201 | - 10 |
|
202 | - ); |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - public function load_scripts_styles_reports() |
|
209 | - { |
|
210 | - wp_register_script( |
|
211 | - 'ee-reg-reports-js', |
|
212 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
213 | - array('google-charts'), |
|
214 | - EVENT_ESPRESSO_VERSION, |
|
215 | - true |
|
216 | - ); |
|
217 | - wp_enqueue_script('ee-reg-reports-js'); |
|
218 | - $this->_registration_reports_js_setup(); |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - |
|
223 | - protected function _add_screen_options_event_registrations() |
|
224 | - { |
|
225 | - $this->_per_page_screen_option(); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - protected function _add_screen_options_registration_checkins() |
|
231 | - { |
|
232 | - $page_title = $this->_admin_page_title; |
|
233 | - $this->_admin_page_title = __('Check-In Records', 'event_espresso'); |
|
234 | - $this->_per_page_screen_option(); |
|
235 | - $this->_admin_page_title = $page_title; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - |
|
240 | - protected function _set_list_table_views_event_registrations() |
|
241 | - { |
|
242 | - $this->_views = array( |
|
243 | - 'all' => array( |
|
244 | - 'slug' => 'all', |
|
245 | - 'label' => __('All', 'event_espresso'), |
|
246 | - 'count' => 0, |
|
247 | - 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
248 | - ? array() |
|
249 | - : array( |
|
250 | - 'toggle_checkin_status_bulk' => __('Toggle Check-In', 'event_espresso'), |
|
251 | - ), |
|
252 | - ), |
|
253 | - ); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - |
|
258 | - protected function _set_list_table_views_registration_checkins() |
|
259 | - { |
|
260 | - $this->_views = array( |
|
261 | - 'all' => array( |
|
262 | - 'slug' => 'all', |
|
263 | - 'label' => __('All', 'event_espresso'), |
|
264 | - 'count' => 0, |
|
265 | - 'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')), |
|
266 | - ), |
|
267 | - ); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * callback for ajax action. |
|
274 | - * |
|
275 | - * @since 4.3.0 |
|
276 | - * @return void (JSON) |
|
277 | - * @throws \EE_Error |
|
278 | - */ |
|
279 | - public function get_newsletter_form_content() |
|
280 | - { |
|
281 | - //do a nonce check cause we're not coming in from an normal route here. |
|
282 | - $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
283 | - $this->_req_data['get_newsletter_form_content_nonce'] |
|
284 | - ) : ''; |
|
285 | - $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
286 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
287 | - //let's get the mtp for the incoming MTP_ ID |
|
288 | - if ( ! isset($this->_req_data['GRP_ID'])) { |
|
289 | - EE_Error::add_error( |
|
290 | - __( |
|
291 | - 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
292 | - 'event_espresso' |
|
293 | - ), |
|
294 | - __FILE__, |
|
295 | - __FUNCTION__, |
|
296 | - __LINE__ |
|
297 | - ); |
|
298 | - $this->_template_args['success'] = false; |
|
299 | - $this->_template_args['error'] = true; |
|
300 | - $this->_return_json(); |
|
301 | - } |
|
302 | - $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
303 | - if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
304 | - EE_Error::add_error( |
|
305 | - sprintf( |
|
306 | - __( |
|
307 | - 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
308 | - 'event_espresso' |
|
309 | - ), |
|
310 | - $this->_req_data['GRP_ID'] |
|
311 | - ), |
|
312 | - __FILE__, |
|
313 | - __FUNCTION__, |
|
314 | - __LINE__ |
|
315 | - ); |
|
316 | - $this->_template_args['success'] = false; |
|
317 | - $this->_template_args['error'] = true; |
|
318 | - $this->_return_json(); |
|
319 | - } |
|
320 | - $MTPs = $MTPG->context_templates(); |
|
321 | - $MTPs = $MTPs['attendee']; |
|
322 | - $template_fields = array(); |
|
323 | - /** @var EE_Message_Template $MTP */ |
|
324 | - foreach ($MTPs as $MTP) { |
|
325 | - $field = $MTP->get('MTP_template_field'); |
|
326 | - if ($field === 'content') { |
|
327 | - $content = $MTP->get('MTP_content'); |
|
328 | - if ( ! empty($content['newsletter_content'])) { |
|
329 | - $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
330 | - } |
|
331 | - continue; |
|
332 | - } |
|
333 | - $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
334 | - } |
|
335 | - $this->_template_args['success'] = true; |
|
336 | - $this->_template_args['error'] = false; |
|
337 | - $this->_template_args['data'] = array( |
|
338 | - 'batch_message_from' => isset($template_fields['from']) |
|
339 | - ? $template_fields['from'] |
|
340 | - : '', |
|
341 | - 'batch_message_subject' => isset($template_fields['subject']) |
|
342 | - ? $template_fields['subject'] |
|
343 | - : '', |
|
344 | - 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
345 | - ? $template_fields['newsletter_content'] |
|
346 | - : '', |
|
347 | - ); |
|
348 | - $this->_return_json(); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
355 | - * |
|
356 | - * @since 4.3.0 |
|
357 | - * @param EE_Admin_List_Table $list_table |
|
358 | - * @return void |
|
359 | - */ |
|
360 | - public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
361 | - { |
|
362 | - if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
363 | - 'ee_send_message', |
|
364 | - 'espresso_registrations_newsletter_selected_send' |
|
365 | - ) |
|
366 | - ) { |
|
367 | - return; |
|
368 | - } |
|
369 | - $routes_to_add_to = array( |
|
370 | - 'contact_list', |
|
371 | - 'event_registrations', |
|
372 | - 'default', |
|
373 | - ); |
|
374 | - if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
375 | - if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
376 | - || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
377 | - ) { |
|
378 | - echo ''; |
|
379 | - } else { |
|
380 | - $button_text = sprintf( |
|
381 | - __('Send Batch Message (%s selected)', 'event_espresso'), |
|
382 | - '<span class="send-selected-newsletter-count">0</span>' |
|
383 | - ); |
|
384 | - echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>' |
|
385 | - . $button_text |
|
386 | - . '</button>'; |
|
387 | - add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
388 | - } |
|
389 | - } |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - public function newsletter_send_form_skeleton() |
|
395 | - { |
|
396 | - $list_table = $this->_list_table_object; |
|
397 | - $codes = array(); |
|
398 | - //need to templates for the newsletter message type for the template selector. |
|
399 | - $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
400 | - $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
401 | - array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
402 | - ); |
|
403 | - foreach ($mtps as $mtp) { |
|
404 | - $name = $mtp->name(); |
|
405 | - $values[] = array( |
|
406 | - 'text' => empty($name) ? __('Global', 'event_espresso') : $name, |
|
407 | - 'id' => $mtp->ID(), |
|
408 | - ); |
|
409 | - } |
|
410 | - //need to get a list of shortcodes that are available for the newsletter message type. |
|
411 | - $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false); |
|
412 | - foreach ($shortcodes as $field => $shortcode_array) { |
|
413 | - $codes[$field] = implode(', ', array_keys($shortcode_array)); |
|
414 | - } |
|
415 | - $shortcodes = $codes; |
|
416 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
417 | - $form_template_args = array( |
|
418 | - 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
419 | - 'form_route' => 'newsletter_selected_send', |
|
420 | - 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
421 | - 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
422 | - 'redirect_back_to' => $this->_req_action, |
|
423 | - 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
424 | - 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
425 | - 'shortcodes' => $shortcodes, |
|
426 | - 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
427 | - ); |
|
428 | - EEH_Template::display_template($form_template, $form_template_args); |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * Handles sending selected registrations/contacts a newsletter. |
|
435 | - * |
|
436 | - * @since 4.3.0 |
|
437 | - * @return void |
|
438 | - * @throws \EE_Error |
|
439 | - */ |
|
440 | - protected function _newsletter_selected_send() |
|
441 | - { |
|
442 | - $success = true; |
|
443 | - //first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
444 | - if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
445 | - EE_Error::add_error( |
|
446 | - __( |
|
447 | - 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
448 | - 'event_espresso' |
|
449 | - ), |
|
450 | - __FILE__, |
|
451 | - __FUNCTION__, |
|
452 | - __LINE__ |
|
453 | - ); |
|
454 | - $success = false; |
|
455 | - } |
|
456 | - if ($success) { |
|
457 | - //update Message template in case there are any changes |
|
458 | - $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
459 | - $this->_req_data['newsletter_mtp_selected'] |
|
460 | - ); |
|
461 | - $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
462 | - ? $Message_Template_Group->context_templates() |
|
463 | - : array(); |
|
464 | - if (empty($Message_Templates)) { |
|
465 | - EE_Error::add_error( |
|
466 | - __( |
|
467 | - 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
468 | - 'event_espresso' |
|
469 | - ), |
|
470 | - __FILE__, |
|
471 | - __FUNCTION__, |
|
472 | - __LINE__ |
|
473 | - ); |
|
474 | - } |
|
475 | - //let's just update the specific fields |
|
476 | - foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
477 | - if ($Message_Template instanceof EE_Message_Template) { |
|
478 | - $field = $Message_Template->get('MTP_template_field'); |
|
479 | - $content = $Message_Template->get('MTP_content'); |
|
480 | - $new_content = $content; |
|
481 | - switch ($field) { |
|
482 | - case 'from' : |
|
483 | - $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
484 | - ? $this->_req_data['batch_message']['from'] |
|
485 | - : $content; |
|
486 | - break; |
|
487 | - case 'subject' : |
|
488 | - $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
489 | - ? $this->_req_data['batch_message']['subject'] |
|
490 | - : $content; |
|
491 | - break; |
|
492 | - case 'content' : |
|
493 | - $new_content = $content; |
|
494 | - $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
495 | - ? $this->_req_data['batch_message']['content'] |
|
496 | - : $content['newsletter_content']; |
|
497 | - break; |
|
498 | - default : |
|
499 | - //continue the foreach loop, we don't want to set $new_content nor save. |
|
500 | - continue 2; |
|
501 | - } |
|
502 | - $Message_Template->set('MTP_content', $new_content); |
|
503 | - $Message_Template->save(); |
|
504 | - } |
|
505 | - } |
|
506 | - //great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
507 | - $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
508 | - ? $this->_req_data['batch_message']['id_type'] |
|
509 | - : 'registration'; |
|
510 | - //id_type will affect how we assemble the ids. |
|
511 | - $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
512 | - ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
513 | - : array(); |
|
514 | - $registrations_used_for_contact_data = array(); |
|
515 | - //using switch because eventually we'll have other contexts that will be used for generating messages. |
|
516 | - switch ($id_type) { |
|
517 | - case 'registration' : |
|
518 | - $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
519 | - array( |
|
520 | - array( |
|
521 | - 'REG_ID' => array('IN', $ids), |
|
522 | - ), |
|
523 | - ) |
|
524 | - ); |
|
525 | - break; |
|
526 | - case 'contact' : |
|
527 | - $registrations_used_for_contact_data = EEM_Registration::instance() |
|
528 | - ->get_latest_registration_for_each_of_given_contacts($ids); |
|
529 | - break; |
|
530 | - } |
|
531 | - do_action( |
|
532 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
533 | - $registrations_used_for_contact_data, |
|
534 | - $Message_Template_Group->ID() |
|
535 | - ); |
|
536 | - //kept for backward compat, internally we no longer use this action. |
|
537 | - //@deprecated 4.8.36.rc.002 |
|
538 | - $contacts = $id_type === 'registration' |
|
539 | - ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
540 | - : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
541 | - do_action( |
|
542 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
543 | - $contacts, |
|
544 | - $Message_Template_Group->ID() |
|
545 | - ); |
|
546 | - } |
|
547 | - $query_args = array( |
|
548 | - 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
549 | - ? $this->_req_data['redirect_back_to'] |
|
550 | - : 'default', |
|
551 | - ); |
|
552 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
559 | - * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
560 | - */ |
|
561 | - protected function _registration_reports_js_setup() |
|
562 | - { |
|
563 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
564 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * generates Business Reports regarding Registrations |
|
571 | - * |
|
572 | - * @access protected |
|
573 | - * @return void |
|
574 | - */ |
|
575 | - protected function _registration_reports() |
|
576 | - { |
|
577 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
578 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
579 | - $template_path, |
|
580 | - $this->_reports_template_data, |
|
581 | - true |
|
582 | - ); |
|
583 | - // the final template wrapper |
|
584 | - $this->display_admin_page_with_no_sidebar(); |
|
585 | - } |
|
586 | - |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * Generates Business Report showing total registrations per day. |
|
591 | - * |
|
592 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
593 | - * @return string |
|
594 | - */ |
|
595 | - private function _registrations_per_day_report($period = '-1 month') |
|
596 | - { |
|
597 | - $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
598 | - $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
599 | - $results = (array)$results; |
|
600 | - $regs = array(); |
|
601 | - $subtitle = ''; |
|
602 | - if ($results) { |
|
603 | - $column_titles = array(); |
|
604 | - $tracker = 0; |
|
605 | - foreach ($results as $result) { |
|
606 | - $report_column_values = array(); |
|
607 | - foreach ($result as $property_name => $property_value) { |
|
608 | - $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
609 | - : (int)$property_value; |
|
610 | - $report_column_values[] = $property_value; |
|
611 | - if ($tracker === 0) { |
|
612 | - if ($property_name === 'Registration_REG_date') { |
|
613 | - $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso'); |
|
614 | - } else { |
|
615 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
616 | - } |
|
617 | - } |
|
618 | - } |
|
619 | - $tracker++; |
|
620 | - $regs[] = $report_column_values; |
|
621 | - } |
|
622 | - //make sure the column_titles is pushed to the beginning of the array |
|
623 | - array_unshift($regs, $column_titles); |
|
624 | - //setup the date range. |
|
625 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
626 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
627 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
628 | - $subtitle = sprintf( |
|
629 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
630 | - $beginning_date->format('Y-m-d'), |
|
631 | - $ending_date->format('Y-m-d') |
|
632 | - ); |
|
633 | - } |
|
634 | - $report_title = __('Total Registrations per Day', 'event_espresso'); |
|
635 | - $report_params = array( |
|
636 | - 'title' => $report_title, |
|
637 | - 'subtitle' => $subtitle, |
|
638 | - 'id' => $report_ID, |
|
639 | - 'regs' => $regs, |
|
640 | - 'noResults' => empty($regs), |
|
641 | - 'noRegsMsg' => sprintf( |
|
642 | - __( |
|
643 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
644 | - 'event_espresso' |
|
645 | - ), |
|
646 | - '<h2>' . $report_title . '</h2><p>', |
|
647 | - '</p>' |
|
648 | - ), |
|
649 | - ); |
|
650 | - wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
651 | - return $report_ID; |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * Generates Business Report showing total registrations per event. |
|
658 | - * |
|
659 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
660 | - * @return string |
|
661 | - */ |
|
662 | - private function _registrations_per_event_report($period = '-1 month') |
|
663 | - { |
|
664 | - $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
665 | - $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
666 | - $results = (array)$results; |
|
667 | - $regs = array(); |
|
668 | - $subtitle = ''; |
|
669 | - if ($results) { |
|
670 | - $column_titles = array(); |
|
671 | - $tracker = 0; |
|
672 | - foreach ($results as $result) { |
|
673 | - $report_column_values = array(); |
|
674 | - foreach ($result as $property_name => $property_value) { |
|
675 | - $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
676 | - $property_value, |
|
677 | - 4, |
|
678 | - '...' |
|
679 | - ) : (int)$property_value; |
|
680 | - $report_column_values[] = $property_value; |
|
681 | - if ($tracker === 0) { |
|
682 | - if ($property_name === 'Registration_Event') { |
|
683 | - $column_titles[] = __('Event', 'event_espresso'); |
|
684 | - } else { |
|
685 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
686 | - } |
|
687 | - } |
|
688 | - } |
|
689 | - $tracker++; |
|
690 | - $regs[] = $report_column_values; |
|
691 | - } |
|
692 | - //make sure the column_titles is pushed to the beginning of the array |
|
693 | - array_unshift($regs, $column_titles); |
|
694 | - //setup the date range. |
|
695 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
696 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
697 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
698 | - $subtitle = sprintf( |
|
699 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
700 | - $beginning_date->format('Y-m-d'), |
|
701 | - $ending_date->format('Y-m-d') |
|
702 | - ); |
|
703 | - } |
|
704 | - $report_title = __('Total Registrations per Event', 'event_espresso'); |
|
705 | - $report_params = array( |
|
706 | - 'title' => $report_title, |
|
707 | - 'subtitle' => $subtitle, |
|
708 | - 'id' => $report_ID, |
|
709 | - 'regs' => $regs, |
|
710 | - 'noResults' => empty($regs), |
|
711 | - 'noRegsMsg' => sprintf( |
|
712 | - __( |
|
713 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
714 | - 'event_espresso' |
|
715 | - ), |
|
716 | - '<h2>' . $report_title . '</h2><p>', |
|
717 | - '</p>' |
|
718 | - ), |
|
719 | - ); |
|
720 | - wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
721 | - return $report_ID; |
|
722 | - } |
|
723 | - |
|
724 | - |
|
725 | - |
|
726 | - /** |
|
727 | - * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
728 | - * |
|
729 | - * @access protected |
|
730 | - * @return void |
|
731 | - * @throws \EE_Error |
|
732 | - */ |
|
733 | - protected function _registration_checkin_list_table() |
|
734 | - { |
|
735 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
736 | - $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null; |
|
737 | - /** @var EE_Registration $registration */ |
|
738 | - $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
739 | - $attendee = $registration->attendee(); |
|
740 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
741 | - 'new_registration', |
|
742 | - 'add-registrant', |
|
743 | - array('event_id' => $registration->event_ID()), |
|
744 | - 'add-new-h2' |
|
745 | - ); |
|
746 | - $legend_items = array( |
|
747 | - 'checkin' => array( |
|
748 | - 'class' => 'ee-icon ee-icon-check-in', |
|
749 | - 'desc' => __('This indicates the attendee has been checked in', 'event_espresso'), |
|
750 | - ), |
|
751 | - 'checkout' => array( |
|
752 | - 'class' => 'ee-icon ee-icon-check-out', |
|
753 | - 'desc' => __('This indicates the attendee has been checked out', 'event_espresso'), |
|
754 | - ), |
|
755 | - ); |
|
756 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
757 | - $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
758 | - /** @var EE_Datetime $datetime */ |
|
759 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
760 | - $datetime_label = ''; |
|
761 | - if ($datetime instanceof EE_Datetime) { |
|
762 | - $datetime_label = $datetime->get_dtt_display_name(true); |
|
763 | - $datetime_label .= ! empty($datetime_label) |
|
764 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
765 | - : $datetime->get_dtt_display_name(); |
|
766 | - } |
|
767 | - $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
768 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
769 | - array( |
|
770 | - 'action' => 'event_registrations', |
|
771 | - 'event_id' => $registration->event_ID(), |
|
772 | - 'DTT_ID' => $dtt_id, |
|
773 | - ), |
|
774 | - $this->_admin_base_url |
|
775 | - ) |
|
776 | - : ''; |
|
777 | - $datetime_link = ! empty($datetime_link) |
|
778 | - ? '<a href="' . $datetime_link . '">' |
|
779 | - . '<span id="checkin-dtt">' |
|
780 | - . $datetime_label |
|
781 | - . '</span></a>' |
|
782 | - : $datetime_label; |
|
783 | - $attendee_name = $attendee instanceof EE_Attendee |
|
784 | - ? $attendee->full_name() |
|
785 | - : ''; |
|
786 | - $attendee_link = $attendee instanceof EE_Attendee |
|
787 | - ? $attendee->get_admin_details_link() |
|
788 | - : ''; |
|
789 | - $attendee_link = ! empty($attendee_link) |
|
790 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
791 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
792 | - . '<span id="checkin-attendee-name">' |
|
793 | - . $attendee_name |
|
794 | - . '</span></a>' |
|
795 | - : ''; |
|
796 | - $event_link = $registration->event() instanceof EE_Event |
|
797 | - ? $registration->event()->get_admin_details_link() |
|
798 | - : ''; |
|
799 | - $event_link = ! empty($event_link) |
|
800 | - ? '<a href="' . $event_link . '"' |
|
801 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
802 | - . '<span id="checkin-event-name">' |
|
803 | - . $registration->event_name() |
|
804 | - . '</span>' |
|
805 | - . '</a>' |
|
806 | - : ''; |
|
807 | - $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
808 | - ? '<h2>' . sprintf( |
|
809 | - esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
810 | - $attendee_link, |
|
811 | - $datetime_link, |
|
812 | - $event_link |
|
813 | - ) . '</h2>' |
|
814 | - : ''; |
|
815 | - $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
816 | - ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : ''; |
|
817 | - $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
818 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
819 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
820 | - } |
|
821 | - |
|
822 | - |
|
823 | - |
|
824 | - /** |
|
825 | - * toggle the Check-in status for the given registration (coming from ajax) |
|
826 | - * |
|
827 | - * @return void (JSON) |
|
828 | - */ |
|
829 | - public function toggle_checkin_status() |
|
830 | - { |
|
831 | - //first make sure we have the necessary data |
|
832 | - if ( ! isset($this->_req_data['_regid'])) { |
|
833 | - EE_Error::add_error( |
|
834 | - __( |
|
835 | - 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
836 | - 'event_espresso' |
|
837 | - ), |
|
838 | - __FILE__, |
|
839 | - __FUNCTION__, |
|
840 | - __LINE__ |
|
841 | - ); |
|
842 | - $this->_template_args['success'] = false; |
|
843 | - $this->_template_args['error'] = true; |
|
844 | - $this->_return_json(); |
|
845 | - }; |
|
846 | - //do a nonce check cause we're not coming in from an normal route here. |
|
847 | - $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
848 | - : ''; |
|
849 | - $nonce_ref = 'checkin_nonce'; |
|
850 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
851 | - //beautiful! Made it this far so let's get the status. |
|
852 | - $new_status = $this->_toggle_checkin_status(); |
|
853 | - //setup new class to return via ajax |
|
854 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-' |
|
855 | - . $new_status; |
|
856 | - $this->_template_args['success'] = true; |
|
857 | - $this->_return_json(); |
|
858 | - } |
|
859 | - |
|
860 | - |
|
861 | - |
|
862 | - /** |
|
863 | - * handles toggling the checkin status for the registration, |
|
864 | - * |
|
865 | - * @access protected |
|
866 | - * @return int|void |
|
867 | - */ |
|
868 | - protected function _toggle_checkin_status() |
|
869 | - { |
|
870 | - //first let's get the query args out of the way for the redirect |
|
871 | - $query_args = array( |
|
872 | - 'action' => 'event_registrations', |
|
873 | - 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
874 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
875 | - ); |
|
876 | - $new_status = false; |
|
877 | - // bulk action check in toggle |
|
878 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
879 | - // cycle thru checkboxes |
|
880 | - while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
881 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
882 | - $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
883 | - } |
|
884 | - } elseif (isset($this->_req_data['_regid'])) { |
|
885 | - //coming from ajax request |
|
886 | - $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
887 | - $query_args['DTT_ID'] = $DTT_ID; |
|
888 | - $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
889 | - } else { |
|
890 | - EE_Error::add_error( |
|
891 | - __('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
892 | - __FILE__, |
|
893 | - __FUNCTION__, |
|
894 | - __LINE__ |
|
895 | - ); |
|
896 | - } |
|
897 | - if (defined('DOING_AJAX')) { |
|
898 | - return $new_status; |
|
899 | - } |
|
900 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
901 | - } |
|
902 | - |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * This is toggles a single Check-in for the given registration and datetime. |
|
907 | - * |
|
908 | - * @param int $REG_ID The registration we're toggling |
|
909 | - * @param int $DTT_ID The datetime we're toggling |
|
910 | - * @return int The new status toggled to. |
|
911 | - * @throws \EE_Error |
|
912 | - */ |
|
913 | - private function _toggle_checkin($REG_ID, $DTT_ID) |
|
914 | - { |
|
915 | - /** @var EE_Registration $REG */ |
|
916 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
917 | - $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
918 | - if ($new_status !== false) { |
|
919 | - EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
920 | - } else { |
|
921 | - EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
922 | - $new_status = false; |
|
923 | - } |
|
924 | - return $new_status; |
|
925 | - } |
|
926 | - |
|
927 | - |
|
928 | - |
|
929 | - /** |
|
930 | - * Takes care of deleting multiple EE_Checkin table rows |
|
931 | - * |
|
932 | - * @access protected |
|
933 | - * @return void |
|
934 | - * @throws \EE_Error |
|
935 | - */ |
|
936 | - protected function _delete_checkin_rows() |
|
937 | - { |
|
938 | - $query_args = array( |
|
939 | - 'action' => 'registration_checkins', |
|
940 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
941 | - '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
942 | - ); |
|
943 | - $errors = 0; |
|
944 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
945 | - while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
946 | - if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
947 | - $errors++; |
|
948 | - } |
|
949 | - } |
|
950 | - } else { |
|
951 | - EE_Error::add_error( |
|
952 | - __( |
|
953 | - 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
954 | - 'event_espresso' |
|
955 | - ), |
|
956 | - __FILE__, |
|
957 | - __FUNCTION__, |
|
958 | - __LINE__ |
|
959 | - ); |
|
960 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
961 | - } |
|
962 | - if ($errors > 0) { |
|
963 | - EE_Error::add_error( |
|
964 | - sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
965 | - __FILE__, |
|
966 | - __FUNCTION__, |
|
967 | - __LINE__ |
|
968 | - ); |
|
969 | - } else { |
|
970 | - EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
971 | - } |
|
972 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
973 | - } |
|
974 | - |
|
975 | - |
|
976 | - |
|
977 | - /** |
|
978 | - * Deletes a single EE_Checkin row |
|
979 | - * |
|
980 | - * @return void |
|
981 | - * @throws \EE_Error |
|
982 | - */ |
|
983 | - protected function _delete_checkin_row() |
|
984 | - { |
|
985 | - $query_args = array( |
|
986 | - 'action' => 'registration_checkins', |
|
987 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
988 | - '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
989 | - ); |
|
990 | - if ( ! empty($this->_req_data['CHK_ID'])) { |
|
991 | - if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
992 | - EE_Error::add_error( |
|
993 | - __('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
994 | - __FILE__, |
|
995 | - __FUNCTION__, |
|
996 | - __LINE__ |
|
997 | - ); |
|
998 | - } else { |
|
999 | - EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
1000 | - } |
|
1001 | - } else { |
|
1002 | - EE_Error::add_error( |
|
1003 | - __( |
|
1004 | - 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1005 | - 'event_espresso' |
|
1006 | - ), |
|
1007 | - __FILE__, |
|
1008 | - __FUNCTION__, |
|
1009 | - __LINE__ |
|
1010 | - ); |
|
1011 | - } |
|
1012 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1013 | - } |
|
1014 | - |
|
1015 | - |
|
1016 | - |
|
1017 | - /** |
|
1018 | - * generates HTML for the Event Registrations List Table |
|
1019 | - * |
|
1020 | - * @access protected |
|
1021 | - * @return void |
|
1022 | - * @throws \EE_Error |
|
1023 | - */ |
|
1024 | - protected function _event_registrations_list_table() |
|
1025 | - { |
|
1026 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1027 | - $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1028 | - ? $this->get_action_link_or_button( |
|
1029 | - 'new_registration', |
|
1030 | - 'add-registrant', |
|
1031 | - array('event_id' => $this->_req_data['event_id']), |
|
1032 | - 'add-new-h2', |
|
1033 | - '', |
|
1034 | - false |
|
1035 | - ) |
|
1036 | - : ''; |
|
1037 | - $legend_items = array( |
|
1038 | - 'star-icon' => array( |
|
1039 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1040 | - 'desc' => __('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1041 | - ), |
|
1042 | - 'checkin' => array( |
|
1043 | - 'class' => 'ee-icon ee-icon-check-in', |
|
1044 | - 'desc' => __('This Registrant has been Checked In', 'event_espresso'), |
|
1045 | - ), |
|
1046 | - 'checkout' => array( |
|
1047 | - 'class' => 'ee-icon ee-icon-check-out', |
|
1048 | - 'desc' => __('This Registrant has been Checked Out', 'event_espresso'), |
|
1049 | - ), |
|
1050 | - 'nocheckinrecord' => array( |
|
1051 | - 'class' => 'dashicons dashicons-no', |
|
1052 | - 'desc' => __('No Check-in Record has been Created for this Registrant', 'event_espresso'), |
|
1053 | - ), |
|
1054 | - 'view_details' => array( |
|
1055 | - 'class' => 'dashicons dashicons-search', |
|
1056 | - 'desc' => __('View All Check-in Records for this Registrant', 'event_espresso'), |
|
1057 | - ), |
|
1058 | - 'approved_status' => array( |
|
1059 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1060 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1061 | - ), |
|
1062 | - 'cancelled_status' => array( |
|
1063 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1064 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1065 | - ), |
|
1066 | - 'declined_status' => array( |
|
1067 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1068 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1069 | - ), |
|
1070 | - 'not_approved' => array( |
|
1071 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1072 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1073 | - ), |
|
1074 | - 'pending_status' => array( |
|
1075 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1076 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1077 | - ), |
|
1078 | - 'wait_list' => array( |
|
1079 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1080 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1081 | - ), |
|
1082 | - ); |
|
1083 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1084 | - $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1085 | - $this->_template_args['before_list_table'] = ! empty($event_id) |
|
1086 | - ? '<h2>' . sprintf( |
|
1087 | - __('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1088 | - EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1089 | - ) . '</h2>' |
|
1090 | - : ''; |
|
1091 | - //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event. |
|
1092 | - /** @var EE_Event $event */ |
|
1093 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1094 | - $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1095 | - $datetime = null; |
|
1096 | - if ($event instanceof EE_Event) { |
|
1097 | - $datetimes_on_event = $event->datetimes(); |
|
1098 | - if (count($datetimes_on_event) === 1) { |
|
1099 | - $datetime = reset($datetimes_on_event); |
|
1100 | - } |
|
1101 | - } |
|
1102 | - $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1103 | - if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1104 | - $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1105 | - $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1106 | - $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1107 | - $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1108 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1109 | - $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1110 | - } |
|
1111 | - //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column |
|
1112 | - //represents |
|
1113 | - if ( ! $datetime instanceof EE_Datetime) { |
|
1114 | - $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1115 | - . __('In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1116 | - 'event_espresso') |
|
1117 | - . '</p>'; |
|
1118 | - } |
|
1119 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1120 | - } |
|
1121 | - |
|
1122 | - /** |
|
1123 | - * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1124 | - * conditions) |
|
1125 | - * |
|
1126 | - * @return void ends the request by a redirect or download |
|
1127 | - */ |
|
1128 | - public function _registrations_checkin_report() |
|
1129 | - { |
|
1130 | - $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1131 | - } |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1135 | - * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1136 | - * |
|
1137 | - * @param array $request |
|
1138 | - * @param int $per_page |
|
1139 | - * @param bool $count |
|
1140 | - * @return array |
|
1141 | - */ |
|
1142 | - protected function _get_checkin_query_params_from_request( |
|
1143 | - $request, |
|
1144 | - $per_page = 10, |
|
1145 | - $count = false |
|
1146 | - ) { |
|
1147 | - $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1148 | - //unlike the regular registrations list table, |
|
1149 | - $status_ids_array = apply_filters( |
|
1150 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1151 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1152 | - ); |
|
1153 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1154 | - return $query_params; |
|
1155 | - } |
|
1156 | - |
|
1157 | - |
|
1158 | - |
|
1159 | - |
|
1160 | - /** |
|
1161 | - * Gets registrations for an event |
|
1162 | - * |
|
1163 | - * @param int $per_page |
|
1164 | - * @param bool $count whether to return count or data. |
|
1165 | - * @param bool $trash |
|
1166 | - * @param string $orderby |
|
1167 | - * @return EE_Registration[]|int |
|
1168 | - * @throws \EE_Error |
|
1169 | - */ |
|
1170 | - public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1171 | - { |
|
1172 | - //normalize some request params that get setup by the parent `get_registrations` method. |
|
1173 | - $request = $this->_req_data; |
|
1174 | - $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1175 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1176 | - if($trash){ |
|
1177 | - $request['status'] = 'trash'; |
|
1178 | - } |
|
1179 | - $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count ); |
|
1180 | - /** |
|
1181 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1182 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1183 | - * @see EEM_Base::get_all() |
|
1184 | - */ |
|
1185 | - $query_params['group_by'] = ''; |
|
1186 | - |
|
1187 | - return $count |
|
1188 | - ? EEM_Registration::instance()->count($query_params) |
|
1189 | - /** @type EE_Registration[] */ |
|
1190 | - : EEM_Registration::instance()->get_all($query_params); |
|
1191 | - } |
|
20 | + /** |
|
21 | + * This is used to hold the reports template data which is setup early in the request. |
|
22 | + * |
|
23 | + * @type array |
|
24 | + */ |
|
25 | + protected $_reports_template_data = array(); |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * Extend_Registrations_Admin_Page constructor. |
|
31 | + * |
|
32 | + * @param bool $routing |
|
33 | + */ |
|
34 | + public function __construct($routing = true) |
|
35 | + { |
|
36 | + parent::__construct($routing); |
|
37 | + if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
38 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
39 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
40 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
41 | + } |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + |
|
46 | + protected function _extend_page_config() |
|
47 | + { |
|
48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
49 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
50 | + ? $this->_req_data['_REG_ID'] |
|
51 | + : 0; |
|
52 | + // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0; |
|
53 | + // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) |
|
54 | + // ? $this->_req_data['post'] : $att_id; |
|
55 | + $new_page_routes = array( |
|
56 | + 'reports' => array( |
|
57 | + 'func' => '_registration_reports', |
|
58 | + 'capability' => 'ee_read_registrations', |
|
59 | + ), |
|
60 | + 'registration_checkins' => array( |
|
61 | + 'func' => '_registration_checkin_list_table', |
|
62 | + 'capability' => 'ee_read_checkins', |
|
63 | + ), |
|
64 | + 'newsletter_selected_send' => array( |
|
65 | + 'func' => '_newsletter_selected_send', |
|
66 | + 'noheader' => true, |
|
67 | + 'capability' => 'ee_send_message', |
|
68 | + ), |
|
69 | + 'delete_checkin_rows' => array( |
|
70 | + 'func' => '_delete_checkin_rows', |
|
71 | + 'noheader' => true, |
|
72 | + 'capability' => 'ee_delete_checkins', |
|
73 | + ), |
|
74 | + 'delete_checkin_row' => array( |
|
75 | + 'func' => '_delete_checkin_row', |
|
76 | + 'noheader' => true, |
|
77 | + 'capability' => 'ee_delete_checkin', |
|
78 | + 'obj_id' => $reg_id, |
|
79 | + ), |
|
80 | + 'toggle_checkin_status' => array( |
|
81 | + 'func' => '_toggle_checkin_status', |
|
82 | + 'noheader' => true, |
|
83 | + 'capability' => 'ee_edit_checkin', |
|
84 | + 'obj_id' => $reg_id, |
|
85 | + ), |
|
86 | + 'toggle_checkin_status_bulk' => array( |
|
87 | + 'func' => '_toggle_checkin_status', |
|
88 | + 'noheader' => true, |
|
89 | + 'capability' => 'ee_edit_checkins' |
|
90 | + ), |
|
91 | + 'event_registrations' => array( |
|
92 | + 'func' => '_event_registrations_list_table', |
|
93 | + 'capability' => 'ee_read_checkins', |
|
94 | + ), |
|
95 | + 'registrations_checkin_report' => array( |
|
96 | + 'func' => '_registrations_checkin_report', |
|
97 | + 'noheader' => true, |
|
98 | + 'capability' => 'ee_read_registrations', |
|
99 | + ), |
|
100 | + ); |
|
101 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
102 | + $new_page_config = array( |
|
103 | + 'reports' => array( |
|
104 | + 'nav' => array( |
|
105 | + 'label' => __('Reports', 'event_espresso'), |
|
106 | + 'order' => 30, |
|
107 | + ), |
|
108 | + 'help_tabs' => array( |
|
109 | + 'registrations_reports_help_tab' => array( |
|
110 | + 'title' => __('Registration Reports', 'event_espresso'), |
|
111 | + 'filename' => 'registrations_reports', |
|
112 | + ), |
|
113 | + ), |
|
114 | + /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
115 | + 'require_nonce' => false, |
|
116 | + ), |
|
117 | + 'event_registrations' => array( |
|
118 | + 'nav' => array( |
|
119 | + 'label' => __('Event Check-In', 'event_espresso'), |
|
120 | + 'order' => 10, |
|
121 | + 'persistent' => true, |
|
122 | + ), |
|
123 | + 'help_tabs' => array( |
|
124 | + 'registrations_event_checkin_help_tab' => array( |
|
125 | + 'title' => __('Registrations Event Check-In', 'event_espresso'), |
|
126 | + 'filename' => 'registrations_event_checkin', |
|
127 | + ), |
|
128 | + 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
129 | + 'title' => __('Event Check-In Table Column Headings', 'event_espresso'), |
|
130 | + 'filename' => 'registrations_event_checkin_table_column_headings', |
|
131 | + ), |
|
132 | + 'registrations_event_checkin_filters_help_tab' => array( |
|
133 | + 'title' => __('Event Check-In Filters', 'event_espresso'), |
|
134 | + 'filename' => 'registrations_event_checkin_filters', |
|
135 | + ), |
|
136 | + 'registrations_event_checkin_views_help_tab' => array( |
|
137 | + 'title' => __('Event Check-In Views', 'event_espresso'), |
|
138 | + 'filename' => 'registrations_event_checkin_views', |
|
139 | + ), |
|
140 | + 'registrations_event_checkin_other_help_tab' => array( |
|
141 | + 'title' => __('Event Check-In Other', 'event_espresso'), |
|
142 | + 'filename' => 'registrations_event_checkin_other', |
|
143 | + ), |
|
144 | + ), |
|
145 | + 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
146 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
147 | + 'list_table' => 'EE_Event_Registrations_List_Table', |
|
148 | + 'metaboxes' => array(), |
|
149 | + 'require_nonce' => false, |
|
150 | + ), |
|
151 | + 'registration_checkins' => array( |
|
152 | + 'nav' => array( |
|
153 | + 'label' => __('Check-In Records', 'event_espresso'), |
|
154 | + 'order' => 15, |
|
155 | + 'persistent' => false, |
|
156 | + ), |
|
157 | + 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
158 | + //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
159 | + 'metaboxes' => array(), |
|
160 | + 'require_nonce' => false, |
|
161 | + ), |
|
162 | + ); |
|
163 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
164 | + $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
165 | + $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + protected function _ajax_hooks() |
|
171 | + { |
|
172 | + parent::_ajax_hooks(); |
|
173 | + add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + public function load_scripts_styles() |
|
179 | + { |
|
180 | + parent::load_scripts_styles(); |
|
181 | + //if newsletter message type is active then let's add filter and load js for it. |
|
182 | + if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
183 | + //enqueue newsletter js |
|
184 | + wp_enqueue_script( |
|
185 | + 'ee-newsletter-trigger', |
|
186 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
187 | + array('ee-dialog'), |
|
188 | + EVENT_ESPRESSO_VERSION, |
|
189 | + true |
|
190 | + ); |
|
191 | + wp_enqueue_style( |
|
192 | + 'ee-newsletter-trigger-css', |
|
193 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
194 | + array(), |
|
195 | + EVENT_ESPRESSO_VERSION |
|
196 | + ); |
|
197 | + //hook in buttons for newsletter message type trigger. |
|
198 | + add_action( |
|
199 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
200 | + array($this, 'add_newsletter_action_buttons'), |
|
201 | + 10 |
|
202 | + ); |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + public function load_scripts_styles_reports() |
|
209 | + { |
|
210 | + wp_register_script( |
|
211 | + 'ee-reg-reports-js', |
|
212 | + REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
213 | + array('google-charts'), |
|
214 | + EVENT_ESPRESSO_VERSION, |
|
215 | + true |
|
216 | + ); |
|
217 | + wp_enqueue_script('ee-reg-reports-js'); |
|
218 | + $this->_registration_reports_js_setup(); |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + |
|
223 | + protected function _add_screen_options_event_registrations() |
|
224 | + { |
|
225 | + $this->_per_page_screen_option(); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + protected function _add_screen_options_registration_checkins() |
|
231 | + { |
|
232 | + $page_title = $this->_admin_page_title; |
|
233 | + $this->_admin_page_title = __('Check-In Records', 'event_espresso'); |
|
234 | + $this->_per_page_screen_option(); |
|
235 | + $this->_admin_page_title = $page_title; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + protected function _set_list_table_views_event_registrations() |
|
241 | + { |
|
242 | + $this->_views = array( |
|
243 | + 'all' => array( |
|
244 | + 'slug' => 'all', |
|
245 | + 'label' => __('All', 'event_espresso'), |
|
246 | + 'count' => 0, |
|
247 | + 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
248 | + ? array() |
|
249 | + : array( |
|
250 | + 'toggle_checkin_status_bulk' => __('Toggle Check-In', 'event_espresso'), |
|
251 | + ), |
|
252 | + ), |
|
253 | + ); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + |
|
258 | + protected function _set_list_table_views_registration_checkins() |
|
259 | + { |
|
260 | + $this->_views = array( |
|
261 | + 'all' => array( |
|
262 | + 'slug' => 'all', |
|
263 | + 'label' => __('All', 'event_espresso'), |
|
264 | + 'count' => 0, |
|
265 | + 'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')), |
|
266 | + ), |
|
267 | + ); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * callback for ajax action. |
|
274 | + * |
|
275 | + * @since 4.3.0 |
|
276 | + * @return void (JSON) |
|
277 | + * @throws \EE_Error |
|
278 | + */ |
|
279 | + public function get_newsletter_form_content() |
|
280 | + { |
|
281 | + //do a nonce check cause we're not coming in from an normal route here. |
|
282 | + $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
283 | + $this->_req_data['get_newsletter_form_content_nonce'] |
|
284 | + ) : ''; |
|
285 | + $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
286 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
287 | + //let's get the mtp for the incoming MTP_ ID |
|
288 | + if ( ! isset($this->_req_data['GRP_ID'])) { |
|
289 | + EE_Error::add_error( |
|
290 | + __( |
|
291 | + 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
292 | + 'event_espresso' |
|
293 | + ), |
|
294 | + __FILE__, |
|
295 | + __FUNCTION__, |
|
296 | + __LINE__ |
|
297 | + ); |
|
298 | + $this->_template_args['success'] = false; |
|
299 | + $this->_template_args['error'] = true; |
|
300 | + $this->_return_json(); |
|
301 | + } |
|
302 | + $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
303 | + if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
304 | + EE_Error::add_error( |
|
305 | + sprintf( |
|
306 | + __( |
|
307 | + 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
308 | + 'event_espresso' |
|
309 | + ), |
|
310 | + $this->_req_data['GRP_ID'] |
|
311 | + ), |
|
312 | + __FILE__, |
|
313 | + __FUNCTION__, |
|
314 | + __LINE__ |
|
315 | + ); |
|
316 | + $this->_template_args['success'] = false; |
|
317 | + $this->_template_args['error'] = true; |
|
318 | + $this->_return_json(); |
|
319 | + } |
|
320 | + $MTPs = $MTPG->context_templates(); |
|
321 | + $MTPs = $MTPs['attendee']; |
|
322 | + $template_fields = array(); |
|
323 | + /** @var EE_Message_Template $MTP */ |
|
324 | + foreach ($MTPs as $MTP) { |
|
325 | + $field = $MTP->get('MTP_template_field'); |
|
326 | + if ($field === 'content') { |
|
327 | + $content = $MTP->get('MTP_content'); |
|
328 | + if ( ! empty($content['newsletter_content'])) { |
|
329 | + $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
330 | + } |
|
331 | + continue; |
|
332 | + } |
|
333 | + $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
334 | + } |
|
335 | + $this->_template_args['success'] = true; |
|
336 | + $this->_template_args['error'] = false; |
|
337 | + $this->_template_args['data'] = array( |
|
338 | + 'batch_message_from' => isset($template_fields['from']) |
|
339 | + ? $template_fields['from'] |
|
340 | + : '', |
|
341 | + 'batch_message_subject' => isset($template_fields['subject']) |
|
342 | + ? $template_fields['subject'] |
|
343 | + : '', |
|
344 | + 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
345 | + ? $template_fields['newsletter_content'] |
|
346 | + : '', |
|
347 | + ); |
|
348 | + $this->_return_json(); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
355 | + * |
|
356 | + * @since 4.3.0 |
|
357 | + * @param EE_Admin_List_Table $list_table |
|
358 | + * @return void |
|
359 | + */ |
|
360 | + public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
361 | + { |
|
362 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
363 | + 'ee_send_message', |
|
364 | + 'espresso_registrations_newsletter_selected_send' |
|
365 | + ) |
|
366 | + ) { |
|
367 | + return; |
|
368 | + } |
|
369 | + $routes_to_add_to = array( |
|
370 | + 'contact_list', |
|
371 | + 'event_registrations', |
|
372 | + 'default', |
|
373 | + ); |
|
374 | + if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
375 | + if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
376 | + || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
377 | + ) { |
|
378 | + echo ''; |
|
379 | + } else { |
|
380 | + $button_text = sprintf( |
|
381 | + __('Send Batch Message (%s selected)', 'event_espresso'), |
|
382 | + '<span class="send-selected-newsletter-count">0</span>' |
|
383 | + ); |
|
384 | + echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>' |
|
385 | + . $button_text |
|
386 | + . '</button>'; |
|
387 | + add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
388 | + } |
|
389 | + } |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + public function newsletter_send_form_skeleton() |
|
395 | + { |
|
396 | + $list_table = $this->_list_table_object; |
|
397 | + $codes = array(); |
|
398 | + //need to templates for the newsletter message type for the template selector. |
|
399 | + $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
400 | + $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
401 | + array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
402 | + ); |
|
403 | + foreach ($mtps as $mtp) { |
|
404 | + $name = $mtp->name(); |
|
405 | + $values[] = array( |
|
406 | + 'text' => empty($name) ? __('Global', 'event_espresso') : $name, |
|
407 | + 'id' => $mtp->ID(), |
|
408 | + ); |
|
409 | + } |
|
410 | + //need to get a list of shortcodes that are available for the newsletter message type. |
|
411 | + $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false); |
|
412 | + foreach ($shortcodes as $field => $shortcode_array) { |
|
413 | + $codes[$field] = implode(', ', array_keys($shortcode_array)); |
|
414 | + } |
|
415 | + $shortcodes = $codes; |
|
416 | + $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
417 | + $form_template_args = array( |
|
418 | + 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
419 | + 'form_route' => 'newsletter_selected_send', |
|
420 | + 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
421 | + 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
422 | + 'redirect_back_to' => $this->_req_action, |
|
423 | + 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
424 | + 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
425 | + 'shortcodes' => $shortcodes, |
|
426 | + 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
427 | + ); |
|
428 | + EEH_Template::display_template($form_template, $form_template_args); |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * Handles sending selected registrations/contacts a newsletter. |
|
435 | + * |
|
436 | + * @since 4.3.0 |
|
437 | + * @return void |
|
438 | + * @throws \EE_Error |
|
439 | + */ |
|
440 | + protected function _newsletter_selected_send() |
|
441 | + { |
|
442 | + $success = true; |
|
443 | + //first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
444 | + if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
445 | + EE_Error::add_error( |
|
446 | + __( |
|
447 | + 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
448 | + 'event_espresso' |
|
449 | + ), |
|
450 | + __FILE__, |
|
451 | + __FUNCTION__, |
|
452 | + __LINE__ |
|
453 | + ); |
|
454 | + $success = false; |
|
455 | + } |
|
456 | + if ($success) { |
|
457 | + //update Message template in case there are any changes |
|
458 | + $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
459 | + $this->_req_data['newsletter_mtp_selected'] |
|
460 | + ); |
|
461 | + $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
462 | + ? $Message_Template_Group->context_templates() |
|
463 | + : array(); |
|
464 | + if (empty($Message_Templates)) { |
|
465 | + EE_Error::add_error( |
|
466 | + __( |
|
467 | + 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
468 | + 'event_espresso' |
|
469 | + ), |
|
470 | + __FILE__, |
|
471 | + __FUNCTION__, |
|
472 | + __LINE__ |
|
473 | + ); |
|
474 | + } |
|
475 | + //let's just update the specific fields |
|
476 | + foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
477 | + if ($Message_Template instanceof EE_Message_Template) { |
|
478 | + $field = $Message_Template->get('MTP_template_field'); |
|
479 | + $content = $Message_Template->get('MTP_content'); |
|
480 | + $new_content = $content; |
|
481 | + switch ($field) { |
|
482 | + case 'from' : |
|
483 | + $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
484 | + ? $this->_req_data['batch_message']['from'] |
|
485 | + : $content; |
|
486 | + break; |
|
487 | + case 'subject' : |
|
488 | + $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
489 | + ? $this->_req_data['batch_message']['subject'] |
|
490 | + : $content; |
|
491 | + break; |
|
492 | + case 'content' : |
|
493 | + $new_content = $content; |
|
494 | + $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
495 | + ? $this->_req_data['batch_message']['content'] |
|
496 | + : $content['newsletter_content']; |
|
497 | + break; |
|
498 | + default : |
|
499 | + //continue the foreach loop, we don't want to set $new_content nor save. |
|
500 | + continue 2; |
|
501 | + } |
|
502 | + $Message_Template->set('MTP_content', $new_content); |
|
503 | + $Message_Template->save(); |
|
504 | + } |
|
505 | + } |
|
506 | + //great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
507 | + $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
508 | + ? $this->_req_data['batch_message']['id_type'] |
|
509 | + : 'registration'; |
|
510 | + //id_type will affect how we assemble the ids. |
|
511 | + $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
512 | + ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
513 | + : array(); |
|
514 | + $registrations_used_for_contact_data = array(); |
|
515 | + //using switch because eventually we'll have other contexts that will be used for generating messages. |
|
516 | + switch ($id_type) { |
|
517 | + case 'registration' : |
|
518 | + $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
519 | + array( |
|
520 | + array( |
|
521 | + 'REG_ID' => array('IN', $ids), |
|
522 | + ), |
|
523 | + ) |
|
524 | + ); |
|
525 | + break; |
|
526 | + case 'contact' : |
|
527 | + $registrations_used_for_contact_data = EEM_Registration::instance() |
|
528 | + ->get_latest_registration_for_each_of_given_contacts($ids); |
|
529 | + break; |
|
530 | + } |
|
531 | + do_action( |
|
532 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
533 | + $registrations_used_for_contact_data, |
|
534 | + $Message_Template_Group->ID() |
|
535 | + ); |
|
536 | + //kept for backward compat, internally we no longer use this action. |
|
537 | + //@deprecated 4.8.36.rc.002 |
|
538 | + $contacts = $id_type === 'registration' |
|
539 | + ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
540 | + : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
541 | + do_action( |
|
542 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
543 | + $contacts, |
|
544 | + $Message_Template_Group->ID() |
|
545 | + ); |
|
546 | + } |
|
547 | + $query_args = array( |
|
548 | + 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
549 | + ? $this->_req_data['redirect_back_to'] |
|
550 | + : 'default', |
|
551 | + ); |
|
552 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
559 | + * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
560 | + */ |
|
561 | + protected function _registration_reports_js_setup() |
|
562 | + { |
|
563 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
564 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * generates Business Reports regarding Registrations |
|
571 | + * |
|
572 | + * @access protected |
|
573 | + * @return void |
|
574 | + */ |
|
575 | + protected function _registration_reports() |
|
576 | + { |
|
577 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
578 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
579 | + $template_path, |
|
580 | + $this->_reports_template_data, |
|
581 | + true |
|
582 | + ); |
|
583 | + // the final template wrapper |
|
584 | + $this->display_admin_page_with_no_sidebar(); |
|
585 | + } |
|
586 | + |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * Generates Business Report showing total registrations per day. |
|
591 | + * |
|
592 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
593 | + * @return string |
|
594 | + */ |
|
595 | + private function _registrations_per_day_report($period = '-1 month') |
|
596 | + { |
|
597 | + $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
598 | + $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
599 | + $results = (array)$results; |
|
600 | + $regs = array(); |
|
601 | + $subtitle = ''; |
|
602 | + if ($results) { |
|
603 | + $column_titles = array(); |
|
604 | + $tracker = 0; |
|
605 | + foreach ($results as $result) { |
|
606 | + $report_column_values = array(); |
|
607 | + foreach ($result as $property_name => $property_value) { |
|
608 | + $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
609 | + : (int)$property_value; |
|
610 | + $report_column_values[] = $property_value; |
|
611 | + if ($tracker === 0) { |
|
612 | + if ($property_name === 'Registration_REG_date') { |
|
613 | + $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso'); |
|
614 | + } else { |
|
615 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
616 | + } |
|
617 | + } |
|
618 | + } |
|
619 | + $tracker++; |
|
620 | + $regs[] = $report_column_values; |
|
621 | + } |
|
622 | + //make sure the column_titles is pushed to the beginning of the array |
|
623 | + array_unshift($regs, $column_titles); |
|
624 | + //setup the date range. |
|
625 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
626 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
627 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
628 | + $subtitle = sprintf( |
|
629 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
630 | + $beginning_date->format('Y-m-d'), |
|
631 | + $ending_date->format('Y-m-d') |
|
632 | + ); |
|
633 | + } |
|
634 | + $report_title = __('Total Registrations per Day', 'event_espresso'); |
|
635 | + $report_params = array( |
|
636 | + 'title' => $report_title, |
|
637 | + 'subtitle' => $subtitle, |
|
638 | + 'id' => $report_ID, |
|
639 | + 'regs' => $regs, |
|
640 | + 'noResults' => empty($regs), |
|
641 | + 'noRegsMsg' => sprintf( |
|
642 | + __( |
|
643 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
644 | + 'event_espresso' |
|
645 | + ), |
|
646 | + '<h2>' . $report_title . '</h2><p>', |
|
647 | + '</p>' |
|
648 | + ), |
|
649 | + ); |
|
650 | + wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
651 | + return $report_ID; |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * Generates Business Report showing total registrations per event. |
|
658 | + * |
|
659 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
660 | + * @return string |
|
661 | + */ |
|
662 | + private function _registrations_per_event_report($period = '-1 month') |
|
663 | + { |
|
664 | + $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
665 | + $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
666 | + $results = (array)$results; |
|
667 | + $regs = array(); |
|
668 | + $subtitle = ''; |
|
669 | + if ($results) { |
|
670 | + $column_titles = array(); |
|
671 | + $tracker = 0; |
|
672 | + foreach ($results as $result) { |
|
673 | + $report_column_values = array(); |
|
674 | + foreach ($result as $property_name => $property_value) { |
|
675 | + $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
676 | + $property_value, |
|
677 | + 4, |
|
678 | + '...' |
|
679 | + ) : (int)$property_value; |
|
680 | + $report_column_values[] = $property_value; |
|
681 | + if ($tracker === 0) { |
|
682 | + if ($property_name === 'Registration_Event') { |
|
683 | + $column_titles[] = __('Event', 'event_espresso'); |
|
684 | + } else { |
|
685 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
686 | + } |
|
687 | + } |
|
688 | + } |
|
689 | + $tracker++; |
|
690 | + $regs[] = $report_column_values; |
|
691 | + } |
|
692 | + //make sure the column_titles is pushed to the beginning of the array |
|
693 | + array_unshift($regs, $column_titles); |
|
694 | + //setup the date range. |
|
695 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
696 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
697 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
698 | + $subtitle = sprintf( |
|
699 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
700 | + $beginning_date->format('Y-m-d'), |
|
701 | + $ending_date->format('Y-m-d') |
|
702 | + ); |
|
703 | + } |
|
704 | + $report_title = __('Total Registrations per Event', 'event_espresso'); |
|
705 | + $report_params = array( |
|
706 | + 'title' => $report_title, |
|
707 | + 'subtitle' => $subtitle, |
|
708 | + 'id' => $report_ID, |
|
709 | + 'regs' => $regs, |
|
710 | + 'noResults' => empty($regs), |
|
711 | + 'noRegsMsg' => sprintf( |
|
712 | + __( |
|
713 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
714 | + 'event_espresso' |
|
715 | + ), |
|
716 | + '<h2>' . $report_title . '</h2><p>', |
|
717 | + '</p>' |
|
718 | + ), |
|
719 | + ); |
|
720 | + wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
721 | + return $report_ID; |
|
722 | + } |
|
723 | + |
|
724 | + |
|
725 | + |
|
726 | + /** |
|
727 | + * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
728 | + * |
|
729 | + * @access protected |
|
730 | + * @return void |
|
731 | + * @throws \EE_Error |
|
732 | + */ |
|
733 | + protected function _registration_checkin_list_table() |
|
734 | + { |
|
735 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
736 | + $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null; |
|
737 | + /** @var EE_Registration $registration */ |
|
738 | + $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
739 | + $attendee = $registration->attendee(); |
|
740 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
741 | + 'new_registration', |
|
742 | + 'add-registrant', |
|
743 | + array('event_id' => $registration->event_ID()), |
|
744 | + 'add-new-h2' |
|
745 | + ); |
|
746 | + $legend_items = array( |
|
747 | + 'checkin' => array( |
|
748 | + 'class' => 'ee-icon ee-icon-check-in', |
|
749 | + 'desc' => __('This indicates the attendee has been checked in', 'event_espresso'), |
|
750 | + ), |
|
751 | + 'checkout' => array( |
|
752 | + 'class' => 'ee-icon ee-icon-check-out', |
|
753 | + 'desc' => __('This indicates the attendee has been checked out', 'event_espresso'), |
|
754 | + ), |
|
755 | + ); |
|
756 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
757 | + $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
758 | + /** @var EE_Datetime $datetime */ |
|
759 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
760 | + $datetime_label = ''; |
|
761 | + if ($datetime instanceof EE_Datetime) { |
|
762 | + $datetime_label = $datetime->get_dtt_display_name(true); |
|
763 | + $datetime_label .= ! empty($datetime_label) |
|
764 | + ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
765 | + : $datetime->get_dtt_display_name(); |
|
766 | + } |
|
767 | + $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
768 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
769 | + array( |
|
770 | + 'action' => 'event_registrations', |
|
771 | + 'event_id' => $registration->event_ID(), |
|
772 | + 'DTT_ID' => $dtt_id, |
|
773 | + ), |
|
774 | + $this->_admin_base_url |
|
775 | + ) |
|
776 | + : ''; |
|
777 | + $datetime_link = ! empty($datetime_link) |
|
778 | + ? '<a href="' . $datetime_link . '">' |
|
779 | + . '<span id="checkin-dtt">' |
|
780 | + . $datetime_label |
|
781 | + . '</span></a>' |
|
782 | + : $datetime_label; |
|
783 | + $attendee_name = $attendee instanceof EE_Attendee |
|
784 | + ? $attendee->full_name() |
|
785 | + : ''; |
|
786 | + $attendee_link = $attendee instanceof EE_Attendee |
|
787 | + ? $attendee->get_admin_details_link() |
|
788 | + : ''; |
|
789 | + $attendee_link = ! empty($attendee_link) |
|
790 | + ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
791 | + . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
792 | + . '<span id="checkin-attendee-name">' |
|
793 | + . $attendee_name |
|
794 | + . '</span></a>' |
|
795 | + : ''; |
|
796 | + $event_link = $registration->event() instanceof EE_Event |
|
797 | + ? $registration->event()->get_admin_details_link() |
|
798 | + : ''; |
|
799 | + $event_link = ! empty($event_link) |
|
800 | + ? '<a href="' . $event_link . '"' |
|
801 | + . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
802 | + . '<span id="checkin-event-name">' |
|
803 | + . $registration->event_name() |
|
804 | + . '</span>' |
|
805 | + . '</a>' |
|
806 | + : ''; |
|
807 | + $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
808 | + ? '<h2>' . sprintf( |
|
809 | + esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
810 | + $attendee_link, |
|
811 | + $datetime_link, |
|
812 | + $event_link |
|
813 | + ) . '</h2>' |
|
814 | + : ''; |
|
815 | + $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
816 | + ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : ''; |
|
817 | + $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
818 | + ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
819 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
820 | + } |
|
821 | + |
|
822 | + |
|
823 | + |
|
824 | + /** |
|
825 | + * toggle the Check-in status for the given registration (coming from ajax) |
|
826 | + * |
|
827 | + * @return void (JSON) |
|
828 | + */ |
|
829 | + public function toggle_checkin_status() |
|
830 | + { |
|
831 | + //first make sure we have the necessary data |
|
832 | + if ( ! isset($this->_req_data['_regid'])) { |
|
833 | + EE_Error::add_error( |
|
834 | + __( |
|
835 | + 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
836 | + 'event_espresso' |
|
837 | + ), |
|
838 | + __FILE__, |
|
839 | + __FUNCTION__, |
|
840 | + __LINE__ |
|
841 | + ); |
|
842 | + $this->_template_args['success'] = false; |
|
843 | + $this->_template_args['error'] = true; |
|
844 | + $this->_return_json(); |
|
845 | + }; |
|
846 | + //do a nonce check cause we're not coming in from an normal route here. |
|
847 | + $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
848 | + : ''; |
|
849 | + $nonce_ref = 'checkin_nonce'; |
|
850 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
851 | + //beautiful! Made it this far so let's get the status. |
|
852 | + $new_status = $this->_toggle_checkin_status(); |
|
853 | + //setup new class to return via ajax |
|
854 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin checkin-icons checkedin-status-' |
|
855 | + . $new_status; |
|
856 | + $this->_template_args['success'] = true; |
|
857 | + $this->_return_json(); |
|
858 | + } |
|
859 | + |
|
860 | + |
|
861 | + |
|
862 | + /** |
|
863 | + * handles toggling the checkin status for the registration, |
|
864 | + * |
|
865 | + * @access protected |
|
866 | + * @return int|void |
|
867 | + */ |
|
868 | + protected function _toggle_checkin_status() |
|
869 | + { |
|
870 | + //first let's get the query args out of the way for the redirect |
|
871 | + $query_args = array( |
|
872 | + 'action' => 'event_registrations', |
|
873 | + 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
874 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
875 | + ); |
|
876 | + $new_status = false; |
|
877 | + // bulk action check in toggle |
|
878 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
879 | + // cycle thru checkboxes |
|
880 | + while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
881 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
882 | + $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
883 | + } |
|
884 | + } elseif (isset($this->_req_data['_regid'])) { |
|
885 | + //coming from ajax request |
|
886 | + $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
887 | + $query_args['DTT_ID'] = $DTT_ID; |
|
888 | + $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
889 | + } else { |
|
890 | + EE_Error::add_error( |
|
891 | + __('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
892 | + __FILE__, |
|
893 | + __FUNCTION__, |
|
894 | + __LINE__ |
|
895 | + ); |
|
896 | + } |
|
897 | + if (defined('DOING_AJAX')) { |
|
898 | + return $new_status; |
|
899 | + } |
|
900 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
901 | + } |
|
902 | + |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * This is toggles a single Check-in for the given registration and datetime. |
|
907 | + * |
|
908 | + * @param int $REG_ID The registration we're toggling |
|
909 | + * @param int $DTT_ID The datetime we're toggling |
|
910 | + * @return int The new status toggled to. |
|
911 | + * @throws \EE_Error |
|
912 | + */ |
|
913 | + private function _toggle_checkin($REG_ID, $DTT_ID) |
|
914 | + { |
|
915 | + /** @var EE_Registration $REG */ |
|
916 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
917 | + $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
918 | + if ($new_status !== false) { |
|
919 | + EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
920 | + } else { |
|
921 | + EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
922 | + $new_status = false; |
|
923 | + } |
|
924 | + return $new_status; |
|
925 | + } |
|
926 | + |
|
927 | + |
|
928 | + |
|
929 | + /** |
|
930 | + * Takes care of deleting multiple EE_Checkin table rows |
|
931 | + * |
|
932 | + * @access protected |
|
933 | + * @return void |
|
934 | + * @throws \EE_Error |
|
935 | + */ |
|
936 | + protected function _delete_checkin_rows() |
|
937 | + { |
|
938 | + $query_args = array( |
|
939 | + 'action' => 'registration_checkins', |
|
940 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
941 | + '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
942 | + ); |
|
943 | + $errors = 0; |
|
944 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
945 | + while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
946 | + if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
947 | + $errors++; |
|
948 | + } |
|
949 | + } |
|
950 | + } else { |
|
951 | + EE_Error::add_error( |
|
952 | + __( |
|
953 | + 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
954 | + 'event_espresso' |
|
955 | + ), |
|
956 | + __FILE__, |
|
957 | + __FUNCTION__, |
|
958 | + __LINE__ |
|
959 | + ); |
|
960 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
961 | + } |
|
962 | + if ($errors > 0) { |
|
963 | + EE_Error::add_error( |
|
964 | + sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
965 | + __FILE__, |
|
966 | + __FUNCTION__, |
|
967 | + __LINE__ |
|
968 | + ); |
|
969 | + } else { |
|
970 | + EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
971 | + } |
|
972 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
973 | + } |
|
974 | + |
|
975 | + |
|
976 | + |
|
977 | + /** |
|
978 | + * Deletes a single EE_Checkin row |
|
979 | + * |
|
980 | + * @return void |
|
981 | + * @throws \EE_Error |
|
982 | + */ |
|
983 | + protected function _delete_checkin_row() |
|
984 | + { |
|
985 | + $query_args = array( |
|
986 | + 'action' => 'registration_checkins', |
|
987 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
988 | + '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
989 | + ); |
|
990 | + if ( ! empty($this->_req_data['CHK_ID'])) { |
|
991 | + if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
992 | + EE_Error::add_error( |
|
993 | + __('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
994 | + __FILE__, |
|
995 | + __FUNCTION__, |
|
996 | + __LINE__ |
|
997 | + ); |
|
998 | + } else { |
|
999 | + EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
1000 | + } |
|
1001 | + } else { |
|
1002 | + EE_Error::add_error( |
|
1003 | + __( |
|
1004 | + 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1005 | + 'event_espresso' |
|
1006 | + ), |
|
1007 | + __FILE__, |
|
1008 | + __FUNCTION__, |
|
1009 | + __LINE__ |
|
1010 | + ); |
|
1011 | + } |
|
1012 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1013 | + } |
|
1014 | + |
|
1015 | + |
|
1016 | + |
|
1017 | + /** |
|
1018 | + * generates HTML for the Event Registrations List Table |
|
1019 | + * |
|
1020 | + * @access protected |
|
1021 | + * @return void |
|
1022 | + * @throws \EE_Error |
|
1023 | + */ |
|
1024 | + protected function _event_registrations_list_table() |
|
1025 | + { |
|
1026 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1027 | + $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1028 | + ? $this->get_action_link_or_button( |
|
1029 | + 'new_registration', |
|
1030 | + 'add-registrant', |
|
1031 | + array('event_id' => $this->_req_data['event_id']), |
|
1032 | + 'add-new-h2', |
|
1033 | + '', |
|
1034 | + false |
|
1035 | + ) |
|
1036 | + : ''; |
|
1037 | + $legend_items = array( |
|
1038 | + 'star-icon' => array( |
|
1039 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1040 | + 'desc' => __('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1041 | + ), |
|
1042 | + 'checkin' => array( |
|
1043 | + 'class' => 'ee-icon ee-icon-check-in', |
|
1044 | + 'desc' => __('This Registrant has been Checked In', 'event_espresso'), |
|
1045 | + ), |
|
1046 | + 'checkout' => array( |
|
1047 | + 'class' => 'ee-icon ee-icon-check-out', |
|
1048 | + 'desc' => __('This Registrant has been Checked Out', 'event_espresso'), |
|
1049 | + ), |
|
1050 | + 'nocheckinrecord' => array( |
|
1051 | + 'class' => 'dashicons dashicons-no', |
|
1052 | + 'desc' => __('No Check-in Record has been Created for this Registrant', 'event_espresso'), |
|
1053 | + ), |
|
1054 | + 'view_details' => array( |
|
1055 | + 'class' => 'dashicons dashicons-search', |
|
1056 | + 'desc' => __('View All Check-in Records for this Registrant', 'event_espresso'), |
|
1057 | + ), |
|
1058 | + 'approved_status' => array( |
|
1059 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1060 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1061 | + ), |
|
1062 | + 'cancelled_status' => array( |
|
1063 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1064 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1065 | + ), |
|
1066 | + 'declined_status' => array( |
|
1067 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1068 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1069 | + ), |
|
1070 | + 'not_approved' => array( |
|
1071 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1072 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1073 | + ), |
|
1074 | + 'pending_status' => array( |
|
1075 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1076 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1077 | + ), |
|
1078 | + 'wait_list' => array( |
|
1079 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1080 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1081 | + ), |
|
1082 | + ); |
|
1083 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1084 | + $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1085 | + $this->_template_args['before_list_table'] = ! empty($event_id) |
|
1086 | + ? '<h2>' . sprintf( |
|
1087 | + __('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1088 | + EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1089 | + ) . '</h2>' |
|
1090 | + : ''; |
|
1091 | + //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event. |
|
1092 | + /** @var EE_Event $event */ |
|
1093 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1094 | + $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1095 | + $datetime = null; |
|
1096 | + if ($event instanceof EE_Event) { |
|
1097 | + $datetimes_on_event = $event->datetimes(); |
|
1098 | + if (count($datetimes_on_event) === 1) { |
|
1099 | + $datetime = reset($datetimes_on_event); |
|
1100 | + } |
|
1101 | + } |
|
1102 | + $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1103 | + if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1104 | + $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1105 | + $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1106 | + $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1107 | + $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1108 | + $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1109 | + $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1110 | + } |
|
1111 | + //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column |
|
1112 | + //represents |
|
1113 | + if ( ! $datetime instanceof EE_Datetime) { |
|
1114 | + $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1115 | + . __('In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1116 | + 'event_espresso') |
|
1117 | + . '</p>'; |
|
1118 | + } |
|
1119 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1120 | + } |
|
1121 | + |
|
1122 | + /** |
|
1123 | + * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1124 | + * conditions) |
|
1125 | + * |
|
1126 | + * @return void ends the request by a redirect or download |
|
1127 | + */ |
|
1128 | + public function _registrations_checkin_report() |
|
1129 | + { |
|
1130 | + $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1131 | + } |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1135 | + * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1136 | + * |
|
1137 | + * @param array $request |
|
1138 | + * @param int $per_page |
|
1139 | + * @param bool $count |
|
1140 | + * @return array |
|
1141 | + */ |
|
1142 | + protected function _get_checkin_query_params_from_request( |
|
1143 | + $request, |
|
1144 | + $per_page = 10, |
|
1145 | + $count = false |
|
1146 | + ) { |
|
1147 | + $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1148 | + //unlike the regular registrations list table, |
|
1149 | + $status_ids_array = apply_filters( |
|
1150 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1151 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1152 | + ); |
|
1153 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1154 | + return $query_params; |
|
1155 | + } |
|
1156 | + |
|
1157 | + |
|
1158 | + |
|
1159 | + |
|
1160 | + /** |
|
1161 | + * Gets registrations for an event |
|
1162 | + * |
|
1163 | + * @param int $per_page |
|
1164 | + * @param bool $count whether to return count or data. |
|
1165 | + * @param bool $trash |
|
1166 | + * @param string $orderby |
|
1167 | + * @return EE_Registration[]|int |
|
1168 | + * @throws \EE_Error |
|
1169 | + */ |
|
1170 | + public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1171 | + { |
|
1172 | + //normalize some request params that get setup by the parent `get_registrations` method. |
|
1173 | + $request = $this->_req_data; |
|
1174 | + $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1175 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1176 | + if($trash){ |
|
1177 | + $request['status'] = 'trash'; |
|
1178 | + } |
|
1179 | + $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count ); |
|
1180 | + /** |
|
1181 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1182 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1183 | + * @see EEM_Base::get_all() |
|
1184 | + */ |
|
1185 | + $query_params['group_by'] = ''; |
|
1186 | + |
|
1187 | + return $count |
|
1188 | + ? EEM_Registration::instance()->count($query_params) |
|
1189 | + /** @type EE_Registration[] */ |
|
1190 | + : EEM_Registration::instance()->get_all($query_params); |
|
1191 | + } |
|
1192 | 1192 | |
1193 | 1193 | } //end class Registrations Admin Page |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | |
277 | 277 | /** |
278 | - * @param $string |
|
278 | + * @param string $string |
|
279 | 279 | * @return void |
280 | 280 | */ |
281 | 281 | public function add_output($string) |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | |
329 | 329 | /** |
330 | - * @return mixed |
|
330 | + * @return boolean |
|
331 | 331 | */ |
332 | 332 | public function is_espresso_page() |
333 | 333 | { |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | /** |
390 | 390 | * remove param |
391 | 391 | * |
392 | - * @param $key |
|
392 | + * @param string $key |
|
393 | 393 | * @return void |
394 | 394 | */ |
395 | 395 | public function un_set($key) |
@@ -13,389 +13,389 @@ |
||
13 | 13 | final class EE_Request_Handler implements InterminableInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var EE_Request $request |
|
18 | - */ |
|
19 | - private $request; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var array $_notice |
|
23 | - */ |
|
24 | - private $_notice = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * rendered output to be returned to WP |
|
28 | - * |
|
29 | - * @var string $_output |
|
30 | - */ |
|
31 | - private $_output = ''; |
|
32 | - |
|
33 | - /** |
|
34 | - * whether current request is via AJAX |
|
35 | - * |
|
36 | - * @var boolean $ajax |
|
37 | - */ |
|
38 | - public $ajax = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * whether current request is via AJAX from the frontend of the site |
|
42 | - * |
|
43 | - * @var boolean $front_ajax |
|
44 | - */ |
|
45 | - public $front_ajax = false; |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @param EE_Request $request |
|
51 | - */ |
|
52 | - public function __construct(EE_Request $request) |
|
53 | - { |
|
54 | - $this->request = $request; |
|
55 | - $this->ajax = $this->request->ajax; |
|
56 | - $this->front_ajax = $this->request->front_ajax; |
|
57 | - do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @param WP $wp |
|
64 | - * @return void |
|
65 | - * @throws EE_Error |
|
66 | - * @throws ReflectionException |
|
67 | - */ |
|
68 | - public function parse_request($wp = null) |
|
69 | - { |
|
70 | - //if somebody forgot to provide us with WP, that's ok because its global |
|
71 | - if (! $wp instanceof WP) { |
|
72 | - global $wp; |
|
73 | - } |
|
74 | - $this->set_request_vars($wp); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param WP $wp |
|
81 | - * @return void |
|
82 | - * @throws EE_Error |
|
83 | - * @throws ReflectionException |
|
84 | - */ |
|
85 | - public function set_request_vars($wp = null) |
|
86 | - { |
|
87 | - if (! is_admin()) { |
|
88 | - // set request post_id |
|
89 | - $this->request->set('post_id', $this->get_post_id_from_request($wp)); |
|
90 | - // set request post name |
|
91 | - $this->request->set('post_name', $this->get_post_name_from_request($wp)); |
|
92 | - // set request post_type |
|
93 | - $this->request->set('post_type', $this->get_post_type_from_request($wp)); |
|
94 | - // true or false ? is this page being used by EE ? |
|
95 | - $this->set_espresso_page(); |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @param WP $wp |
|
103 | - * @return int |
|
104 | - */ |
|
105 | - public function get_post_id_from_request($wp = null) |
|
106 | - { |
|
107 | - if (! $wp instanceof WP) { |
|
108 | - global $wp; |
|
109 | - } |
|
110 | - $post_id = null; |
|
111 | - if (isset($wp->query_vars['p'])) { |
|
112 | - $post_id = $wp->query_vars['p']; |
|
113 | - } |
|
114 | - if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
115 | - $post_id = $wp->query_vars['page_id']; |
|
116 | - } |
|
117 | - if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
118 | - $post_id = basename($wp->request); |
|
119 | - } |
|
120 | - return $post_id; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param WP $wp |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function get_post_name_from_request($wp = null) |
|
130 | - { |
|
131 | - if (! $wp instanceof WP) { |
|
132 | - global $wp; |
|
133 | - } |
|
134 | - $post_name = null; |
|
135 | - if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
|
136 | - $post_name = $wp->query_vars['name']; |
|
137 | - } |
|
138 | - if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
139 | - $post_name = $wp->query_vars['pagename']; |
|
140 | - } |
|
141 | - if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
142 | - $possible_post_name = basename($wp->request); |
|
143 | - if (! is_numeric($possible_post_name)) { |
|
144 | - /** @type WPDB $wpdb */ |
|
145 | - global $wpdb; |
|
146 | - $SQL = |
|
147 | - "SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s"; |
|
148 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
149 | - if ($possible_post_name) { |
|
150 | - $post_name = $possible_post_name; |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - if (! $post_name && $this->get('post_id')) { |
|
155 | - /** @type WPDB $wpdb */ |
|
156 | - global $wpdb; |
|
157 | - $SQL = |
|
158 | - "SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d"; |
|
159 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id'))); |
|
160 | - if ($possible_post_name) { |
|
161 | - $post_name = $possible_post_name; |
|
162 | - } |
|
163 | - } |
|
164 | - return $post_name; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param WP $wp |
|
171 | - * @return mixed |
|
172 | - */ |
|
173 | - public function get_post_type_from_request($wp = null) |
|
174 | - { |
|
175 | - if (! $wp instanceof WP) { |
|
176 | - global $wp; |
|
177 | - } |
|
178 | - return isset($wp->query_vars['post_type']) |
|
179 | - ? $wp->query_vars['post_type'] |
|
180 | - : null; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Just a helper method for getting the url for the displayed page. |
|
187 | - * |
|
188 | - * @param WP $wp |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - public function get_current_page_permalink($wp = null) |
|
192 | - { |
|
193 | - $post_id = $this->get_post_id_from_request($wp); |
|
194 | - if ($post_id) { |
|
195 | - $current_page_permalink = get_permalink($post_id); |
|
196 | - } else { |
|
197 | - if (! $wp instanceof WP) { |
|
198 | - global $wp; |
|
199 | - } |
|
200 | - if ($wp->request) { |
|
201 | - $current_page_permalink = site_url($wp->request); |
|
202 | - } else { |
|
203 | - $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI'])); |
|
204 | - } |
|
205 | - } |
|
206 | - return $current_page_permalink; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @return bool |
|
213 | - * @throws EE_Error |
|
214 | - * @throws ReflectionException |
|
215 | - */ |
|
216 | - public function test_for_espresso_page() |
|
217 | - { |
|
218 | - global $wp; |
|
219 | - /** @type EE_CPT_Strategy $EE_CPT_Strategy */ |
|
220 | - $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy'); |
|
221 | - $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies(); |
|
222 | - if (is_array($espresso_CPT_taxonomies)) { |
|
223 | - foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
224 | - if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) { |
|
225 | - return true; |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - // load espresso CPT endpoints |
|
230 | - $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints(); |
|
231 | - $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
232 | - $post_types = (array)$this->get('post_type'); |
|
233 | - foreach ($post_types as $post_type) { |
|
234 | - // was a post name passed ? |
|
235 | - if (isset($post_type_CPT_endpoints[$post_type])) { |
|
236 | - // kk we know this is an espresso page, but is it a specific post ? |
|
237 | - if (! $this->get('post_name')) { |
|
238 | - // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
239 | - $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')]) |
|
240 | - ? $post_type_CPT_endpoints[$this->get('post_type')] |
|
241 | - : ''; |
|
242 | - // if the post type matches on of our then set the endpoint |
|
243 | - if ($post_name) { |
|
244 | - $this->set('post_name', $post_name); |
|
245 | - } |
|
246 | - } |
|
247 | - return true; |
|
248 | - } |
|
249 | - } |
|
250 | - return false; |
|
251 | - } |
|
252 | - /** |
|
253 | - * @param $key |
|
254 | - * @param $value |
|
255 | - * @return void |
|
256 | - */ |
|
257 | - public function set_notice($key, $value) |
|
258 | - { |
|
259 | - $this->_notice[$key] = $value; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @param $key |
|
266 | - * @return mixed |
|
267 | - */ |
|
268 | - public function get_notice($key) |
|
269 | - { |
|
270 | - return isset($this->_notice[$key]) |
|
271 | - ? $this->_notice[$key] |
|
272 | - : null; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * @param $string |
|
279 | - * @return void |
|
280 | - */ |
|
281 | - public function add_output($string) |
|
282 | - { |
|
283 | - $this->_output .= $string; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - public function get_output() |
|
292 | - { |
|
293 | - return $this->_output; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * @param $item |
|
300 | - * @param $key |
|
301 | - */ |
|
302 | - public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
303 | - { |
|
304 | - $item = strpos($item, 'email') !== false |
|
305 | - ? sanitize_email($item) |
|
306 | - : sanitize_text_field($item); |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * @param null|bool $value |
|
313 | - * @return void |
|
314 | - * @throws EE_Error |
|
315 | - * @throws ReflectionException |
|
316 | - */ |
|
317 | - public function set_espresso_page($value = null) |
|
318 | - { |
|
319 | - $this->request->set( |
|
320 | - 'is_espresso_page', |
|
321 | - ! empty($value) |
|
322 | - ? $value |
|
323 | - : $this->test_for_espresso_page() |
|
324 | - ); |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * @return mixed |
|
331 | - */ |
|
332 | - public function is_espresso_page() |
|
333 | - { |
|
334 | - return $this->request->is_set('is_espresso_page'); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * returns contents of $_REQUEST |
|
341 | - * |
|
342 | - * @return array |
|
343 | - */ |
|
344 | - public function params() |
|
345 | - { |
|
346 | - return $this->request->params(); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * @param $key |
|
353 | - * @param $value |
|
354 | - * @param bool $override_ee |
|
355 | - * @return void |
|
356 | - */ |
|
357 | - public function set($key, $value, $override_ee = false) |
|
358 | - { |
|
359 | - $this->request->set($key, $value, $override_ee); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * @param $key |
|
366 | - * @param null $default |
|
367 | - * @return mixed |
|
368 | - */ |
|
369 | - public function get($key, $default = null) |
|
370 | - { |
|
371 | - return $this->request->get($key, $default); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * check if param exists |
|
378 | - * |
|
379 | - * @param $key |
|
380 | - * @return boolean |
|
381 | - */ |
|
382 | - public function is_set($key) |
|
383 | - { |
|
384 | - return $this->request->is_set($key); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * remove param |
|
391 | - * |
|
392 | - * @param $key |
|
393 | - * @return void |
|
394 | - */ |
|
395 | - public function un_set($key) |
|
396 | - { |
|
397 | - $this->request->un_set($key); |
|
398 | - } |
|
16 | + /** |
|
17 | + * @var EE_Request $request |
|
18 | + */ |
|
19 | + private $request; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var array $_notice |
|
23 | + */ |
|
24 | + private $_notice = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * rendered output to be returned to WP |
|
28 | + * |
|
29 | + * @var string $_output |
|
30 | + */ |
|
31 | + private $_output = ''; |
|
32 | + |
|
33 | + /** |
|
34 | + * whether current request is via AJAX |
|
35 | + * |
|
36 | + * @var boolean $ajax |
|
37 | + */ |
|
38 | + public $ajax = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * whether current request is via AJAX from the frontend of the site |
|
42 | + * |
|
43 | + * @var boolean $front_ajax |
|
44 | + */ |
|
45 | + public $front_ajax = false; |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @param EE_Request $request |
|
51 | + */ |
|
52 | + public function __construct(EE_Request $request) |
|
53 | + { |
|
54 | + $this->request = $request; |
|
55 | + $this->ajax = $this->request->ajax; |
|
56 | + $this->front_ajax = $this->request->front_ajax; |
|
57 | + do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @param WP $wp |
|
64 | + * @return void |
|
65 | + * @throws EE_Error |
|
66 | + * @throws ReflectionException |
|
67 | + */ |
|
68 | + public function parse_request($wp = null) |
|
69 | + { |
|
70 | + //if somebody forgot to provide us with WP, that's ok because its global |
|
71 | + if (! $wp instanceof WP) { |
|
72 | + global $wp; |
|
73 | + } |
|
74 | + $this->set_request_vars($wp); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param WP $wp |
|
81 | + * @return void |
|
82 | + * @throws EE_Error |
|
83 | + * @throws ReflectionException |
|
84 | + */ |
|
85 | + public function set_request_vars($wp = null) |
|
86 | + { |
|
87 | + if (! is_admin()) { |
|
88 | + // set request post_id |
|
89 | + $this->request->set('post_id', $this->get_post_id_from_request($wp)); |
|
90 | + // set request post name |
|
91 | + $this->request->set('post_name', $this->get_post_name_from_request($wp)); |
|
92 | + // set request post_type |
|
93 | + $this->request->set('post_type', $this->get_post_type_from_request($wp)); |
|
94 | + // true or false ? is this page being used by EE ? |
|
95 | + $this->set_espresso_page(); |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @param WP $wp |
|
103 | + * @return int |
|
104 | + */ |
|
105 | + public function get_post_id_from_request($wp = null) |
|
106 | + { |
|
107 | + if (! $wp instanceof WP) { |
|
108 | + global $wp; |
|
109 | + } |
|
110 | + $post_id = null; |
|
111 | + if (isset($wp->query_vars['p'])) { |
|
112 | + $post_id = $wp->query_vars['p']; |
|
113 | + } |
|
114 | + if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
115 | + $post_id = $wp->query_vars['page_id']; |
|
116 | + } |
|
117 | + if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
118 | + $post_id = basename($wp->request); |
|
119 | + } |
|
120 | + return $post_id; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @param WP $wp |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function get_post_name_from_request($wp = null) |
|
130 | + { |
|
131 | + if (! $wp instanceof WP) { |
|
132 | + global $wp; |
|
133 | + } |
|
134 | + $post_name = null; |
|
135 | + if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
|
136 | + $post_name = $wp->query_vars['name']; |
|
137 | + } |
|
138 | + if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
139 | + $post_name = $wp->query_vars['pagename']; |
|
140 | + } |
|
141 | + if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
142 | + $possible_post_name = basename($wp->request); |
|
143 | + if (! is_numeric($possible_post_name)) { |
|
144 | + /** @type WPDB $wpdb */ |
|
145 | + global $wpdb; |
|
146 | + $SQL = |
|
147 | + "SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s"; |
|
148 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
149 | + if ($possible_post_name) { |
|
150 | + $post_name = $possible_post_name; |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + if (! $post_name && $this->get('post_id')) { |
|
155 | + /** @type WPDB $wpdb */ |
|
156 | + global $wpdb; |
|
157 | + $SQL = |
|
158 | + "SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d"; |
|
159 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id'))); |
|
160 | + if ($possible_post_name) { |
|
161 | + $post_name = $possible_post_name; |
|
162 | + } |
|
163 | + } |
|
164 | + return $post_name; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param WP $wp |
|
171 | + * @return mixed |
|
172 | + */ |
|
173 | + public function get_post_type_from_request($wp = null) |
|
174 | + { |
|
175 | + if (! $wp instanceof WP) { |
|
176 | + global $wp; |
|
177 | + } |
|
178 | + return isset($wp->query_vars['post_type']) |
|
179 | + ? $wp->query_vars['post_type'] |
|
180 | + : null; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Just a helper method for getting the url for the displayed page. |
|
187 | + * |
|
188 | + * @param WP $wp |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + public function get_current_page_permalink($wp = null) |
|
192 | + { |
|
193 | + $post_id = $this->get_post_id_from_request($wp); |
|
194 | + if ($post_id) { |
|
195 | + $current_page_permalink = get_permalink($post_id); |
|
196 | + } else { |
|
197 | + if (! $wp instanceof WP) { |
|
198 | + global $wp; |
|
199 | + } |
|
200 | + if ($wp->request) { |
|
201 | + $current_page_permalink = site_url($wp->request); |
|
202 | + } else { |
|
203 | + $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI'])); |
|
204 | + } |
|
205 | + } |
|
206 | + return $current_page_permalink; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @return bool |
|
213 | + * @throws EE_Error |
|
214 | + * @throws ReflectionException |
|
215 | + */ |
|
216 | + public function test_for_espresso_page() |
|
217 | + { |
|
218 | + global $wp; |
|
219 | + /** @type EE_CPT_Strategy $EE_CPT_Strategy */ |
|
220 | + $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy'); |
|
221 | + $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies(); |
|
222 | + if (is_array($espresso_CPT_taxonomies)) { |
|
223 | + foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
224 | + if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) { |
|
225 | + return true; |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + // load espresso CPT endpoints |
|
230 | + $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints(); |
|
231 | + $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
232 | + $post_types = (array)$this->get('post_type'); |
|
233 | + foreach ($post_types as $post_type) { |
|
234 | + // was a post name passed ? |
|
235 | + if (isset($post_type_CPT_endpoints[$post_type])) { |
|
236 | + // kk we know this is an espresso page, but is it a specific post ? |
|
237 | + if (! $this->get('post_name')) { |
|
238 | + // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
239 | + $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')]) |
|
240 | + ? $post_type_CPT_endpoints[$this->get('post_type')] |
|
241 | + : ''; |
|
242 | + // if the post type matches on of our then set the endpoint |
|
243 | + if ($post_name) { |
|
244 | + $this->set('post_name', $post_name); |
|
245 | + } |
|
246 | + } |
|
247 | + return true; |
|
248 | + } |
|
249 | + } |
|
250 | + return false; |
|
251 | + } |
|
252 | + /** |
|
253 | + * @param $key |
|
254 | + * @param $value |
|
255 | + * @return void |
|
256 | + */ |
|
257 | + public function set_notice($key, $value) |
|
258 | + { |
|
259 | + $this->_notice[$key] = $value; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @param $key |
|
266 | + * @return mixed |
|
267 | + */ |
|
268 | + public function get_notice($key) |
|
269 | + { |
|
270 | + return isset($this->_notice[$key]) |
|
271 | + ? $this->_notice[$key] |
|
272 | + : null; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * @param $string |
|
279 | + * @return void |
|
280 | + */ |
|
281 | + public function add_output($string) |
|
282 | + { |
|
283 | + $this->_output .= $string; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + public function get_output() |
|
292 | + { |
|
293 | + return $this->_output; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * @param $item |
|
300 | + * @param $key |
|
301 | + */ |
|
302 | + public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
303 | + { |
|
304 | + $item = strpos($item, 'email') !== false |
|
305 | + ? sanitize_email($item) |
|
306 | + : sanitize_text_field($item); |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * @param null|bool $value |
|
313 | + * @return void |
|
314 | + * @throws EE_Error |
|
315 | + * @throws ReflectionException |
|
316 | + */ |
|
317 | + public function set_espresso_page($value = null) |
|
318 | + { |
|
319 | + $this->request->set( |
|
320 | + 'is_espresso_page', |
|
321 | + ! empty($value) |
|
322 | + ? $value |
|
323 | + : $this->test_for_espresso_page() |
|
324 | + ); |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * @return mixed |
|
331 | + */ |
|
332 | + public function is_espresso_page() |
|
333 | + { |
|
334 | + return $this->request->is_set('is_espresso_page'); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * returns contents of $_REQUEST |
|
341 | + * |
|
342 | + * @return array |
|
343 | + */ |
|
344 | + public function params() |
|
345 | + { |
|
346 | + return $this->request->params(); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * @param $key |
|
353 | + * @param $value |
|
354 | + * @param bool $override_ee |
|
355 | + * @return void |
|
356 | + */ |
|
357 | + public function set($key, $value, $override_ee = false) |
|
358 | + { |
|
359 | + $this->request->set($key, $value, $override_ee); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * @param $key |
|
366 | + * @param null $default |
|
367 | + * @return mixed |
|
368 | + */ |
|
369 | + public function get($key, $default = null) |
|
370 | + { |
|
371 | + return $this->request->get($key, $default); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * check if param exists |
|
378 | + * |
|
379 | + * @param $key |
|
380 | + * @return boolean |
|
381 | + */ |
|
382 | + public function is_set($key) |
|
383 | + { |
|
384 | + return $this->request->is_set($key); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * remove param |
|
391 | + * |
|
392 | + * @param $key |
|
393 | + * @return void |
|
394 | + */ |
|
395 | + public function un_set($key) |
|
396 | + { |
|
397 | + $this->request->un_set($key); |
|
398 | + } |
|
399 | 399 | |
400 | 400 | |
401 | 401 |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public function parse_request($wp = null) |
69 | 69 | { |
70 | 70 | //if somebody forgot to provide us with WP, that's ok because its global |
71 | - if (! $wp instanceof WP) { |
|
71 | + if ( ! $wp instanceof WP) { |
|
72 | 72 | global $wp; |
73 | 73 | } |
74 | 74 | $this->set_request_vars($wp); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function set_request_vars($wp = null) |
86 | 86 | { |
87 | - if (! is_admin()) { |
|
87 | + if ( ! is_admin()) { |
|
88 | 88 | // set request post_id |
89 | 89 | $this->request->set('post_id', $this->get_post_id_from_request($wp)); |
90 | 90 | // set request post name |
@@ -104,17 +104,17 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function get_post_id_from_request($wp = null) |
106 | 106 | { |
107 | - if (! $wp instanceof WP) { |
|
107 | + if ( ! $wp instanceof WP) { |
|
108 | 108 | global $wp; |
109 | 109 | } |
110 | 110 | $post_id = null; |
111 | 111 | if (isset($wp->query_vars['p'])) { |
112 | 112 | $post_id = $wp->query_vars['p']; |
113 | 113 | } |
114 | - if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
114 | + if ( ! $post_id && isset($wp->query_vars['page_id'])) { |
|
115 | 115 | $post_id = $wp->query_vars['page_id']; |
116 | 116 | } |
117 | - if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
117 | + if ( ! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
118 | 118 | $post_id = basename($wp->request); |
119 | 119 | } |
120 | 120 | return $post_id; |
@@ -128,19 +128,19 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function get_post_name_from_request($wp = null) |
130 | 130 | { |
131 | - if (! $wp instanceof WP) { |
|
131 | + if ( ! $wp instanceof WP) { |
|
132 | 132 | global $wp; |
133 | 133 | } |
134 | 134 | $post_name = null; |
135 | 135 | if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
136 | 136 | $post_name = $wp->query_vars['name']; |
137 | 137 | } |
138 | - if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
138 | + if ( ! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
139 | 139 | $post_name = $wp->query_vars['pagename']; |
140 | 140 | } |
141 | - if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
141 | + if ( ! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
142 | 142 | $possible_post_name = basename($wp->request); |
143 | - if (! is_numeric($possible_post_name)) { |
|
143 | + if ( ! is_numeric($possible_post_name)) { |
|
144 | 144 | /** @type WPDB $wpdb */ |
145 | 145 | global $wpdb; |
146 | 146 | $SQL = |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
154 | - if (! $post_name && $this->get('post_id')) { |
|
154 | + if ( ! $post_name && $this->get('post_id')) { |
|
155 | 155 | /** @type WPDB $wpdb */ |
156 | 156 | global $wpdb; |
157 | 157 | $SQL = |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | */ |
173 | 173 | public function get_post_type_from_request($wp = null) |
174 | 174 | { |
175 | - if (! $wp instanceof WP) { |
|
175 | + if ( ! $wp instanceof WP) { |
|
176 | 176 | global $wp; |
177 | 177 | } |
178 | 178 | return isset($wp->query_vars['post_type']) |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | if ($post_id) { |
195 | 195 | $current_page_permalink = get_permalink($post_id); |
196 | 196 | } else { |
197 | - if (! $wp instanceof WP) { |
|
197 | + if ( ! $wp instanceof WP) { |
|
198 | 198 | global $wp; |
199 | 199 | } |
200 | 200 | if ($wp->request) { |
@@ -229,12 +229,12 @@ discard block |
||
229 | 229 | // load espresso CPT endpoints |
230 | 230 | $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints(); |
231 | 231 | $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
232 | - $post_types = (array)$this->get('post_type'); |
|
232 | + $post_types = (array) $this->get('post_type'); |
|
233 | 233 | foreach ($post_types as $post_type) { |
234 | 234 | // was a post name passed ? |
235 | 235 | if (isset($post_type_CPT_endpoints[$post_type])) { |
236 | 236 | // kk we know this is an espresso page, but is it a specific post ? |
237 | - if (! $this->get('post_name')) { |
|
237 | + if ( ! $this->get('post_name')) { |
|
238 | 238 | // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
239 | 239 | $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')]) |
240 | 240 | ? $post_type_CPT_endpoints[$this->get('post_type')] |
@@ -17,248 +17,248 @@ |
||
17 | 17 | final class EE_Module_Request_Router implements InterminableInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var EE_Request $request |
|
22 | - */ |
|
23 | - private $request; |
|
20 | + /** |
|
21 | + * @var EE_Request $request |
|
22 | + */ |
|
23 | + private $request; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array $_previous_routes |
|
27 | - */ |
|
28 | - private static $_previous_routes = array(); |
|
25 | + /** |
|
26 | + * @var array $_previous_routes |
|
27 | + */ |
|
28 | + private static $_previous_routes = array(); |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var WP_Query $WP_Query |
|
32 | - */ |
|
33 | - public $WP_Query; |
|
30 | + /** |
|
31 | + * @var WP_Query $WP_Query |
|
32 | + */ |
|
33 | + public $WP_Query; |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * EE_Module_Request_Router constructor. |
|
39 | - * |
|
40 | - * @param EE_Request $request |
|
41 | - */ |
|
42 | - public function __construct(EE_Request $request) |
|
43 | - { |
|
44 | - $this->request = $request; |
|
45 | - } |
|
37 | + /** |
|
38 | + * EE_Module_Request_Router constructor. |
|
39 | + * |
|
40 | + * @param EE_Request $request |
|
41 | + */ |
|
42 | + public function __construct(EE_Request $request) |
|
43 | + { |
|
44 | + $this->request = $request; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
51 | - * on subsequent calls to this method, |
|
52 | - * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
53 | - * and checks if the last called route has any forwarding routes registered for it |
|
54 | - * |
|
55 | - * @param WP_Query $WP_Query |
|
56 | - * @return NULL|string |
|
57 | - * @throws EE_Error |
|
58 | - * @throws ReflectionException |
|
59 | - */ |
|
60 | - public function get_route(WP_Query $WP_Query) |
|
61 | - { |
|
62 | - $this->WP_Query = $WP_Query; |
|
63 | - // assume this if first route being called |
|
64 | - $previous_route = false; |
|
65 | - // but is it really ??? |
|
66 | - if (! empty(self::$_previous_routes)) { |
|
67 | - // get last run route |
|
68 | - $previous_routes = array_values(self::$_previous_routes); |
|
69 | - $previous_route = array_pop($previous_routes); |
|
70 | - } |
|
71 | - // has another route already been run ? |
|
72 | - if ($previous_route) { |
|
73 | - // check if forwarding has been set |
|
74 | - $current_route = $this->get_forward($previous_route); |
|
75 | - try { |
|
76 | - //check for recursive forwarding |
|
77 | - if (isset(self::$_previous_routes[$current_route])) { |
|
78 | - throw new EE_Error( |
|
79 | - sprintf( |
|
80 | - __( |
|
81 | - 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
82 | - 'event_espresso' |
|
83 | - ), |
|
84 | - $current_route |
|
85 | - ) |
|
86 | - ); |
|
87 | - } |
|
88 | - } catch (EE_Error $e) { |
|
89 | - $e->get_error(); |
|
90 | - return null; |
|
91 | - } |
|
92 | - } else { |
|
93 | - // first route called |
|
94 | - $current_route = null; |
|
95 | - // grab all routes |
|
96 | - $routes = EE_Config::get_routes(); |
|
97 | - //d( $routes ); |
|
98 | - foreach ($routes as $key => $route) { |
|
99 | - // check request for module route |
|
100 | - if ($this->request->is_set($key)) { |
|
101 | - $current_route = sanitize_text_field($this->request->get($key)); |
|
102 | - if ($current_route) { |
|
103 | - $current_route = array($key, $current_route); |
|
104 | - break; |
|
105 | - } |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
109 | - // sorry, but I can't read what you route ! |
|
110 | - if (empty($current_route)) { |
|
111 | - return null; |
|
112 | - } |
|
113 | - //add route to previous routes array |
|
114 | - self::$_previous_routes[] = $current_route; |
|
115 | - return $current_route; |
|
116 | - } |
|
49 | + /** |
|
50 | + * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
51 | + * on subsequent calls to this method, |
|
52 | + * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
53 | + * and checks if the last called route has any forwarding routes registered for it |
|
54 | + * |
|
55 | + * @param WP_Query $WP_Query |
|
56 | + * @return NULL|string |
|
57 | + * @throws EE_Error |
|
58 | + * @throws ReflectionException |
|
59 | + */ |
|
60 | + public function get_route(WP_Query $WP_Query) |
|
61 | + { |
|
62 | + $this->WP_Query = $WP_Query; |
|
63 | + // assume this if first route being called |
|
64 | + $previous_route = false; |
|
65 | + // but is it really ??? |
|
66 | + if (! empty(self::$_previous_routes)) { |
|
67 | + // get last run route |
|
68 | + $previous_routes = array_values(self::$_previous_routes); |
|
69 | + $previous_route = array_pop($previous_routes); |
|
70 | + } |
|
71 | + // has another route already been run ? |
|
72 | + if ($previous_route) { |
|
73 | + // check if forwarding has been set |
|
74 | + $current_route = $this->get_forward($previous_route); |
|
75 | + try { |
|
76 | + //check for recursive forwarding |
|
77 | + if (isset(self::$_previous_routes[$current_route])) { |
|
78 | + throw new EE_Error( |
|
79 | + sprintf( |
|
80 | + __( |
|
81 | + 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
82 | + 'event_espresso' |
|
83 | + ), |
|
84 | + $current_route |
|
85 | + ) |
|
86 | + ); |
|
87 | + } |
|
88 | + } catch (EE_Error $e) { |
|
89 | + $e->get_error(); |
|
90 | + return null; |
|
91 | + } |
|
92 | + } else { |
|
93 | + // first route called |
|
94 | + $current_route = null; |
|
95 | + // grab all routes |
|
96 | + $routes = EE_Config::get_routes(); |
|
97 | + //d( $routes ); |
|
98 | + foreach ($routes as $key => $route) { |
|
99 | + // check request for module route |
|
100 | + if ($this->request->is_set($key)) { |
|
101 | + $current_route = sanitize_text_field($this->request->get($key)); |
|
102 | + if ($current_route) { |
|
103 | + $current_route = array($key, $current_route); |
|
104 | + break; |
|
105 | + } |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | + // sorry, but I can't read what you route ! |
|
110 | + if (empty($current_route)) { |
|
111 | + return null; |
|
112 | + } |
|
113 | + //add route to previous routes array |
|
114 | + self::$_previous_routes[] = $current_route; |
|
115 | + return $current_route; |
|
116 | + } |
|
117 | 117 | |
118 | 118 | |
119 | 119 | |
120 | - /** |
|
121 | - * this method simply takes a valid route, and resolves what module class method the route points to |
|
122 | - * |
|
123 | - * @param string $key |
|
124 | - * @param string $current_route |
|
125 | - * @return mixed EED_Module | boolean |
|
126 | - * @throws EE_Error |
|
127 | - * @throws ReflectionException |
|
128 | - */ |
|
129 | - public function resolve_route($key, $current_route) |
|
130 | - { |
|
131 | - // get module method that route has been mapped to |
|
132 | - $module_method = EE_Config::get_route($current_route, $key); |
|
133 | - // verify result was returned |
|
134 | - if (empty($module_method)) { |
|
135 | - $msg = sprintf( |
|
136 | - __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
137 | - $current_route |
|
138 | - ); |
|
139 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
140 | - return false; |
|
141 | - } |
|
142 | - // verify that result is an array |
|
143 | - if (! is_array($module_method)) { |
|
144 | - $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
145 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
146 | - return false; |
|
147 | - } |
|
148 | - // grab module name |
|
149 | - $module_name = $module_method[0]; |
|
150 | - // verify that a class method was registered properly |
|
151 | - if (! isset($module_method[1])) { |
|
152 | - $msg = sprintf( |
|
153 | - __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
154 | - $current_route |
|
155 | - ); |
|
156 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
157 | - return false; |
|
158 | - } |
|
159 | - // grab method |
|
160 | - $method = $module_method[1]; |
|
161 | - // verify that class exists |
|
162 | - if (! class_exists($module_name)) { |
|
163 | - $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
164 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
165 | - return false; |
|
166 | - } |
|
167 | - // verify that method exists |
|
168 | - if (! method_exists($module_name, $method)) { |
|
169 | - $msg = sprintf( |
|
170 | - __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
171 | - ); |
|
172 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
173 | - return false; |
|
174 | - } |
|
175 | - // instantiate module and call route method |
|
176 | - return $this->_module_router($module_name, $method); |
|
177 | - } |
|
120 | + /** |
|
121 | + * this method simply takes a valid route, and resolves what module class method the route points to |
|
122 | + * |
|
123 | + * @param string $key |
|
124 | + * @param string $current_route |
|
125 | + * @return mixed EED_Module | boolean |
|
126 | + * @throws EE_Error |
|
127 | + * @throws ReflectionException |
|
128 | + */ |
|
129 | + public function resolve_route($key, $current_route) |
|
130 | + { |
|
131 | + // get module method that route has been mapped to |
|
132 | + $module_method = EE_Config::get_route($current_route, $key); |
|
133 | + // verify result was returned |
|
134 | + if (empty($module_method)) { |
|
135 | + $msg = sprintf( |
|
136 | + __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
137 | + $current_route |
|
138 | + ); |
|
139 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
140 | + return false; |
|
141 | + } |
|
142 | + // verify that result is an array |
|
143 | + if (! is_array($module_method)) { |
|
144 | + $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
145 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
146 | + return false; |
|
147 | + } |
|
148 | + // grab module name |
|
149 | + $module_name = $module_method[0]; |
|
150 | + // verify that a class method was registered properly |
|
151 | + if (! isset($module_method[1])) { |
|
152 | + $msg = sprintf( |
|
153 | + __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
154 | + $current_route |
|
155 | + ); |
|
156 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
157 | + return false; |
|
158 | + } |
|
159 | + // grab method |
|
160 | + $method = $module_method[1]; |
|
161 | + // verify that class exists |
|
162 | + if (! class_exists($module_name)) { |
|
163 | + $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
164 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
165 | + return false; |
|
166 | + } |
|
167 | + // verify that method exists |
|
168 | + if (! method_exists($module_name, $method)) { |
|
169 | + $msg = sprintf( |
|
170 | + __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
171 | + ); |
|
172 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
173 | + return false; |
|
174 | + } |
|
175 | + // instantiate module and call route method |
|
176 | + return $this->_module_router($module_name, $method); |
|
177 | + } |
|
178 | 178 | |
179 | 179 | |
180 | 180 | |
181 | - /** |
|
182 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
183 | - * |
|
184 | - * @param string $module_name |
|
185 | - * @return EED_Module|object|null |
|
186 | - * @throws ReflectionException |
|
187 | - */ |
|
188 | - public static function module_factory($module_name) |
|
189 | - { |
|
190 | - if ($module_name === 'EED_Module') { |
|
191 | - EE_Error::add_error( |
|
192 | - sprintf( |
|
193 | - __( |
|
194 | - 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
195 | - 'event_espresso' |
|
196 | - ), $module_name |
|
197 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
198 | - ); |
|
199 | - return null; |
|
200 | - } |
|
201 | - // instantiate module class |
|
202 | - $module = new $module_name(); |
|
203 | - // ensure that class is actually a module |
|
204 | - if (! $module instanceof EED_Module) { |
|
205 | - EE_Error::add_error( |
|
206 | - sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
207 | - __FILE__, __FUNCTION__, __LINE__ |
|
208 | - ); |
|
209 | - return null; |
|
210 | - } |
|
211 | - return $module; |
|
212 | - } |
|
181 | + /** |
|
182 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
183 | + * |
|
184 | + * @param string $module_name |
|
185 | + * @return EED_Module|object|null |
|
186 | + * @throws ReflectionException |
|
187 | + */ |
|
188 | + public static function module_factory($module_name) |
|
189 | + { |
|
190 | + if ($module_name === 'EED_Module') { |
|
191 | + EE_Error::add_error( |
|
192 | + sprintf( |
|
193 | + __( |
|
194 | + 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
195 | + 'event_espresso' |
|
196 | + ), $module_name |
|
197 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
198 | + ); |
|
199 | + return null; |
|
200 | + } |
|
201 | + // instantiate module class |
|
202 | + $module = new $module_name(); |
|
203 | + // ensure that class is actually a module |
|
204 | + if (! $module instanceof EED_Module) { |
|
205 | + EE_Error::add_error( |
|
206 | + sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
207 | + __FILE__, __FUNCTION__, __LINE__ |
|
208 | + ); |
|
209 | + return null; |
|
210 | + } |
|
211 | + return $module; |
|
212 | + } |
|
213 | 213 | |
214 | 214 | |
215 | 215 | |
216 | - /** |
|
217 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
218 | - * |
|
219 | - * @param string $module_name |
|
220 | - * @param string $method |
|
221 | - * @return EED_Module|null |
|
222 | - * @throws EE_Error |
|
223 | - * @throws ReflectionException |
|
224 | - */ |
|
225 | - private function _module_router($module_name, $method) |
|
226 | - { |
|
227 | - // instantiate module class |
|
228 | - $module = EE_Module_Request_Router::module_factory($module_name); |
|
229 | - if ($module instanceof EED_Module) { |
|
230 | - // and call whatever action the route was for |
|
231 | - try { |
|
232 | - call_user_func(array($module, $method), $this->WP_Query); |
|
233 | - } catch (EE_Error $e) { |
|
234 | - $e->get_error(); |
|
235 | - return null; |
|
236 | - } |
|
237 | - } |
|
238 | - return $module; |
|
239 | - } |
|
216 | + /** |
|
217 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
218 | + * |
|
219 | + * @param string $module_name |
|
220 | + * @param string $method |
|
221 | + * @return EED_Module|null |
|
222 | + * @throws EE_Error |
|
223 | + * @throws ReflectionException |
|
224 | + */ |
|
225 | + private function _module_router($module_name, $method) |
|
226 | + { |
|
227 | + // instantiate module class |
|
228 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
229 | + if ($module instanceof EED_Module) { |
|
230 | + // and call whatever action the route was for |
|
231 | + try { |
|
232 | + call_user_func(array($module, $method), $this->WP_Query); |
|
233 | + } catch (EE_Error $e) { |
|
234 | + $e->get_error(); |
|
235 | + return null; |
|
236 | + } |
|
237 | + } |
|
238 | + return $module; |
|
239 | + } |
|
240 | 240 | |
241 | 241 | |
242 | 242 | |
243 | - /** |
|
244 | - * @param $current_route |
|
245 | - * @return string |
|
246 | - */ |
|
247 | - public function get_forward($current_route) |
|
248 | - { |
|
249 | - return EE_Config::get_forward($current_route); |
|
250 | - } |
|
243 | + /** |
|
244 | + * @param $current_route |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + public function get_forward($current_route) |
|
248 | + { |
|
249 | + return EE_Config::get_forward($current_route); |
|
250 | + } |
|
251 | 251 | |
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * @param $current_route |
|
256 | - * @return string |
|
257 | - */ |
|
258 | - public function get_view($current_route) |
|
259 | - { |
|
260 | - return EE_Config::get_view($current_route); |
|
261 | - } |
|
254 | + /** |
|
255 | + * @param $current_route |
|
256 | + * @return string |
|
257 | + */ |
|
258 | + public function get_view($current_route) |
|
259 | + { |
|
260 | + return EE_Config::get_view($current_route); |
|
261 | + } |
|
262 | 262 | |
263 | 263 | |
264 | 264 | } |