@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
37 | 37 | //$this->_response->set_notice( 1, 'hey look at this' ); |
38 | 38 | // check required WP version |
39 | - if (! $this->_minimum_wp_version_required()) { |
|
39 | + if ( ! $this->_minimum_wp_version_required()) { |
|
40 | 40 | $this->_request->un_set('activate', true); |
41 | 41 | add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
42 | 42 | //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | $this->_response->deactivate_plugin(); |
45 | 45 | } |
46 | 46 | // check recommended PHP version |
47 | - if (! $this->_minimum_php_version_recommended()) { |
|
47 | + if ( ! $this->_minimum_php_version_recommended()) { |
|
48 | 48 | $this->_display_minimum_recommended_php_version_notice(); |
49 | 49 | } |
50 | 50 | |
51 | 51 | //upcoming required version |
52 | - if (! $this->upcomingRequiredPhpVersion()) { |
|
52 | + if ( ! $this->upcomingRequiredPhpVersion()) { |
|
53 | 53 | $this->displayUpcomingRequiredVersion(); |
54 | 54 | } |
55 | 55 | $this->_response = $this->process_request_stack($this->_request, $this->_response); |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | */ |
173 | 173 | private function _display_minimum_recommended_php_version_notice() |
174 | 174 | { |
175 | - if($this->_request->isAdmin()){ |
|
175 | + if ($this->_request->isAdmin()) { |
|
176 | 176 | new PersistentAdminNotice( |
177 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
177 | + 'php_version_'.str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED).'_recommended', |
|
178 | 178 | sprintf( |
179 | 179 | __( |
180 | 180 | 'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->_request) |
200 | 200 | && current_user_can('update_plugins') |
201 | 201 | ) { |
202 | - add_action('admin_notices', function () { |
|
202 | + add_action('admin_notices', function() { |
|
203 | 203 | echo '<div class="notice event-espresso-admin-notice notice-warning"><p>' |
204 | 204 | . sprintf( |
205 | 205 | esc_html__( |
@@ -21,199 +21,199 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * converts a Request to a Response |
|
26 | - * |
|
27 | - * @param EE_Request $request |
|
28 | - * @param EE_Response $response |
|
29 | - * @return EE_Response |
|
30 | - * @throws InvalidDataTypeException |
|
31 | - */ |
|
32 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
33 | - { |
|
34 | - $this->_request = $request; |
|
35 | - $this->_response = $response; |
|
36 | - //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
|
37 | - //$this->_response->set_notice( 1, 'hey look at this' ); |
|
38 | - // check required WP version |
|
39 | - if (! $this->_minimum_wp_version_required()) { |
|
40 | - $this->_request->un_set('activate', true); |
|
41 | - add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
42 | - //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
|
43 | - $this->_response->terminate_request(); |
|
44 | - $this->_response->deactivate_plugin(); |
|
45 | - } |
|
46 | - // check recommended PHP version |
|
47 | - if (! $this->_minimum_php_version_recommended()) { |
|
48 | - $this->_display_minimum_recommended_php_version_notice(); |
|
49 | - } |
|
50 | - |
|
51 | - //upcoming required version |
|
52 | - if (! $this->upcomingRequiredPhpVersion()) { |
|
53 | - $this->displayUpcomingRequiredVersion(); |
|
54 | - } |
|
55 | - $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
56 | - //$this->_response->add_output( "\n\t OUT << " . __CLASS__ ); |
|
57 | - return $this->_response; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * Helper method to assess installed wp version against given values. |
|
63 | - * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
64 | - * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked |
|
65 | - * against) so consider that when sending in your values. |
|
66 | - * |
|
67 | - * @param string $version_to_check |
|
68 | - * @param string $operator |
|
69 | - * @return bool |
|
70 | - */ |
|
71 | - public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
72 | - { |
|
73 | - global $wp_version; |
|
74 | - return version_compare( |
|
75 | - // first account for wp_version being pre-release |
|
76 | - // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519 |
|
77 | - strpos($wp_version, '-') > 0 |
|
78 | - ? substr($wp_version, 0, strpos($wp_version, '-')) |
|
79 | - : $wp_version, |
|
80 | - $version_to_check, |
|
81 | - $operator |
|
82 | - ); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * _minimum_wp_version_required |
|
89 | - * |
|
90 | - * @access private |
|
91 | - * @return boolean |
|
92 | - */ |
|
93 | - private function _minimum_wp_version_required() |
|
94 | - { |
|
95 | - return EE_Recommended_Versions::check_wp_version(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * _check_php_version |
|
102 | - * |
|
103 | - * @access private |
|
104 | - * @param string $min_version |
|
105 | - * @return boolean |
|
106 | - */ |
|
107 | - private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
108 | - { |
|
109 | - return version_compare(PHP_VERSION, $min_version, '>='); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * _minimum_php_version_recommended |
|
116 | - * |
|
117 | - * @access private |
|
118 | - * @return boolean |
|
119 | - */ |
|
120 | - private function _minimum_php_version_recommended() |
|
121 | - { |
|
122 | - return $this->_check_php_version(); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns whether the provided php version number is greater than the current version of php installed on the server. |
|
128 | - * @param string $version_required |
|
129 | - * @return bool |
|
130 | - */ |
|
131 | - private function upcomingRequiredPhpVersion($version_required = '5.5') |
|
132 | - { |
|
133 | - return $this->_check_php_version($version_required); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * minimum_wp_version_error |
|
140 | - * |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - public function minimum_wp_version_error() |
|
144 | - { |
|
145 | - global $wp_version; |
|
146 | - ?> |
|
24 | + /** |
|
25 | + * converts a Request to a Response |
|
26 | + * |
|
27 | + * @param EE_Request $request |
|
28 | + * @param EE_Response $response |
|
29 | + * @return EE_Response |
|
30 | + * @throws InvalidDataTypeException |
|
31 | + */ |
|
32 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
33 | + { |
|
34 | + $this->_request = $request; |
|
35 | + $this->_response = $response; |
|
36 | + //$this->_response->add_output( "\n\t IN >> " . __CLASS__ ); |
|
37 | + //$this->_response->set_notice( 1, 'hey look at this' ); |
|
38 | + // check required WP version |
|
39 | + if (! $this->_minimum_wp_version_required()) { |
|
40 | + $this->_request->un_set('activate', true); |
|
41 | + add_action('admin_notices', array($this, 'minimum_wp_version_error'), 1); |
|
42 | + //$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' ); |
|
43 | + $this->_response->terminate_request(); |
|
44 | + $this->_response->deactivate_plugin(); |
|
45 | + } |
|
46 | + // check recommended PHP version |
|
47 | + if (! $this->_minimum_php_version_recommended()) { |
|
48 | + $this->_display_minimum_recommended_php_version_notice(); |
|
49 | + } |
|
50 | + |
|
51 | + //upcoming required version |
|
52 | + if (! $this->upcomingRequiredPhpVersion()) { |
|
53 | + $this->displayUpcomingRequiredVersion(); |
|
54 | + } |
|
55 | + $this->_response = $this->process_request_stack($this->_request, $this->_response); |
|
56 | + //$this->_response->add_output( "\n\t OUT << " . __CLASS__ ); |
|
57 | + return $this->_response; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * Helper method to assess installed wp version against given values. |
|
63 | + * By default this compares the required minimum version of WP for EE against the installed version of WP |
|
64 | + * Note, $wp_version is the first parameter sent into the PHP version_compare function (what is being checked |
|
65 | + * against) so consider that when sending in your values. |
|
66 | + * |
|
67 | + * @param string $version_to_check |
|
68 | + * @param string $operator |
|
69 | + * @return bool |
|
70 | + */ |
|
71 | + public static function check_wp_version($version_to_check = EE_MIN_WP_VER_REQUIRED, $operator = '>=') |
|
72 | + { |
|
73 | + global $wp_version; |
|
74 | + return version_compare( |
|
75 | + // first account for wp_version being pre-release |
|
76 | + // (like RC, beta etc) which are usually in the format like 4.7-RC3-39519 |
|
77 | + strpos($wp_version, '-') > 0 |
|
78 | + ? substr($wp_version, 0, strpos($wp_version, '-')) |
|
79 | + : $wp_version, |
|
80 | + $version_to_check, |
|
81 | + $operator |
|
82 | + ); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * _minimum_wp_version_required |
|
89 | + * |
|
90 | + * @access private |
|
91 | + * @return boolean |
|
92 | + */ |
|
93 | + private function _minimum_wp_version_required() |
|
94 | + { |
|
95 | + return EE_Recommended_Versions::check_wp_version(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * _check_php_version |
|
102 | + * |
|
103 | + * @access private |
|
104 | + * @param string $min_version |
|
105 | + * @return boolean |
|
106 | + */ |
|
107 | + private function _check_php_version($min_version = EE_MIN_PHP_VER_RECOMMENDED) |
|
108 | + { |
|
109 | + return version_compare(PHP_VERSION, $min_version, '>='); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * _minimum_php_version_recommended |
|
116 | + * |
|
117 | + * @access private |
|
118 | + * @return boolean |
|
119 | + */ |
|
120 | + private function _minimum_php_version_recommended() |
|
121 | + { |
|
122 | + return $this->_check_php_version(); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Returns whether the provided php version number is greater than the current version of php installed on the server. |
|
128 | + * @param string $version_required |
|
129 | + * @return bool |
|
130 | + */ |
|
131 | + private function upcomingRequiredPhpVersion($version_required = '5.5') |
|
132 | + { |
|
133 | + return $this->_check_php_version($version_required); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * minimum_wp_version_error |
|
140 | + * |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + public function minimum_wp_version_error() |
|
144 | + { |
|
145 | + global $wp_version; |
|
146 | + ?> |
|
147 | 147 | <div class="error"> |
148 | 148 | <p> |
149 | 149 | <?php |
150 | - printf( |
|
151 | - __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
152 | - 'event_espresso'), |
|
153 | - EE_MIN_WP_VER_REQUIRED, |
|
154 | - $wp_version, |
|
155 | - '<br/>', |
|
156 | - '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
157 | - ); |
|
158 | - ?> |
|
150 | + printf( |
|
151 | + __('We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', |
|
152 | + 'event_espresso'), |
|
153 | + EE_MIN_WP_VER_REQUIRED, |
|
154 | + $wp_version, |
|
155 | + '<br/>', |
|
156 | + '<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>' |
|
157 | + ); |
|
158 | + ?> |
|
159 | 159 | </p> |
160 | 160 | </div> |
161 | 161 | <?php |
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * _display_minimum_recommended_php_version_notice |
|
168 | - * |
|
169 | - * @access private |
|
170 | - * @return void |
|
171 | - * @throws InvalidDataTypeException |
|
172 | - */ |
|
173 | - private function _display_minimum_recommended_php_version_notice() |
|
174 | - { |
|
175 | - if($this->_request->isAdmin()){ |
|
176 | - new PersistentAdminNotice( |
|
177 | - 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
178 | - sprintf( |
|
179 | - __( |
|
180 | - 'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
181 | - 'event_espresso' |
|
182 | - ), |
|
183 | - EE_MIN_PHP_VER_RECOMMENDED, |
|
184 | - PHP_VERSION, |
|
185 | - '<br/>', |
|
186 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
187 | - ) |
|
188 | - ); |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * Sets a notice for an upcoming required version of PHP in the next update of EE core. |
|
195 | - */ |
|
196 | - private function displayUpcomingRequiredVersion() |
|
197 | - { |
|
198 | - if ($this->_request->isAdmin() |
|
199 | - && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->_request) |
|
200 | - && current_user_can('update_plugins') |
|
201 | - ) { |
|
202 | - add_action('admin_notices', function () { |
|
203 | - echo '<div class="notice event-espresso-admin-notice notice-warning"><p>' |
|
204 | - . sprintf( |
|
205 | - esc_html__( |
|
206 | - 'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater. Your web server\'s PHP version is %3$s. You can contact your host and ask them to update your PHP version to at least PHP 5.6. Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s', |
|
207 | - 'event_espresso' |
|
208 | - ), |
|
209 | - '<strong>', |
|
210 | - '</strong>', |
|
211 | - PHP_VERSION, |
|
212 | - '<a href="https://wordpress.org/support/upgrade-php/">', |
|
213 | - '</a>' |
|
214 | - ) |
|
215 | - . '</p></div>'; |
|
216 | - }); |
|
217 | - } |
|
218 | - } |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * _display_minimum_recommended_php_version_notice |
|
168 | + * |
|
169 | + * @access private |
|
170 | + * @return void |
|
171 | + * @throws InvalidDataTypeException |
|
172 | + */ |
|
173 | + private function _display_minimum_recommended_php_version_notice() |
|
174 | + { |
|
175 | + if($this->_request->isAdmin()){ |
|
176 | + new PersistentAdminNotice( |
|
177 | + 'php_version_' . str_replace('.', '-', EE_MIN_PHP_VER_RECOMMENDED) . '_recommended', |
|
178 | + sprintf( |
|
179 | + __( |
|
180 | + 'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
181 | + 'event_espresso' |
|
182 | + ), |
|
183 | + EE_MIN_PHP_VER_RECOMMENDED, |
|
184 | + PHP_VERSION, |
|
185 | + '<br/>', |
|
186 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
187 | + ) |
|
188 | + ); |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * Sets a notice for an upcoming required version of PHP in the next update of EE core. |
|
195 | + */ |
|
196 | + private function displayUpcomingRequiredVersion() |
|
197 | + { |
|
198 | + if ($this->_request->isAdmin() |
|
199 | + && apply_filters('FHEE__EE_Recommended_Versions__displayUpcomingRequiredVersion', true, $this->_request) |
|
200 | + && current_user_can('update_plugins') |
|
201 | + ) { |
|
202 | + add_action('admin_notices', function () { |
|
203 | + echo '<div class="notice event-espresso-admin-notice notice-warning"><p>' |
|
204 | + . sprintf( |
|
205 | + esc_html__( |
|
206 | + 'Please note: The next update of Event Espresso 4 will %1$srequire%2$s PHP 5.4.45 or greater. Your web server\'s PHP version is %3$s. You can contact your host and ask them to update your PHP version to at least PHP 5.6. Please do not update to the new version of Event Espresso 4 until the PHP update is completed. Read about why keeping your server on the latest version of PHP is a good idea %4$shere%5$s', |
|
207 | + 'event_espresso' |
|
208 | + ), |
|
209 | + '<strong>', |
|
210 | + '</strong>', |
|
211 | + PHP_VERSION, |
|
212 | + '<a href="https://wordpress.org/support/upgrade-php/">', |
|
213 | + '</a>' |
|
214 | + ) |
|
215 | + . '</p></div>'; |
|
216 | + }); |
|
217 | + } |
|
218 | + } |
|
219 | 219 | } |
@@ -18,530 +18,530 @@ |
||
18 | 18 | class Events_Admin_List_Table extends EE_Admin_List_Table |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Datetime |
|
23 | - */ |
|
24 | - private $_dtt; |
|
25 | - |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Initial setup of data properties for the list table. |
|
30 | - */ |
|
31 | - protected function _setup_data() |
|
32 | - { |
|
33 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
34 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Set up of additional properties for the list table. |
|
41 | - */ |
|
42 | - protected function _set_properties() |
|
43 | - { |
|
44 | - $this->_wp_list_args = array( |
|
45 | - 'singular' => esc_html__('event', 'event_espresso'), |
|
46 | - 'plural' => esc_html__('events', 'event_espresso'), |
|
47 | - 'ajax' => true, //for now |
|
48 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
49 | - ); |
|
50 | - $this->_columns = array( |
|
51 | - 'cb' => '<input type="checkbox" />', |
|
52 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
53 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
54 | - 'author' => esc_html__('Author', 'event_espresso'), |
|
55 | - 'venue' => esc_html__('Venue', 'event_espresso'), |
|
56 | - 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
57 | - 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
58 | - 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
59 | - . '<span class="screen-reader-text">' |
|
60 | - . esc_html__('Approved Registrations', 'event_espresso') |
|
61 | - . '</span>' |
|
62 | - . '</span>', |
|
63 | - //'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
64 | - 'actions' => esc_html__('Actions', 'event_espresso'), |
|
65 | - ); |
|
66 | - $this->_sortable_columns = array( |
|
67 | - 'id' => array('EVT_ID' => true), |
|
68 | - 'name' => array('EVT_name' => false), |
|
69 | - 'author' => array('EVT_wp_user' => false), |
|
70 | - 'venue' => array('Venue.VNU_name' => false), |
|
71 | - 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
72 | - 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
73 | - ); |
|
74 | - $this->_primary_column = 'id'; |
|
75 | - $this->_hidden_columns = array('author'); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @return array |
|
82 | - */ |
|
83 | - protected function _get_table_filters() |
|
84 | - { |
|
85 | - return array(); //no filters with decaf |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Setup of views properties. |
|
92 | - * |
|
93 | - * @throws InvalidDataTypeException |
|
94 | - * @throws InvalidInterfaceException |
|
95 | - * @throws InvalidArgumentException |
|
96 | - */ |
|
97 | - protected function _add_view_counts() |
|
98 | - { |
|
99 | - $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
100 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
101 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
102 | - 'ee_delete_events', |
|
103 | - 'espresso_events_trash_events' |
|
104 | - )) { |
|
105 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @param EE_Event $item |
|
113 | - * @return string |
|
114 | - * @throws EE_Error |
|
115 | - */ |
|
116 | - protected function _get_row_class($item) |
|
117 | - { |
|
118 | - $class = parent::_get_row_class($item); |
|
119 | - //add status class |
|
120 | - $class .= $item instanceof EE_Event |
|
121 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
122 | - : ''; |
|
123 | - if ($this->_has_checkbox_column) { |
|
124 | - $class .= ' has-checkbox-column'; |
|
125 | - } |
|
126 | - return $class; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @param EE_Event $item |
|
133 | - * @return string |
|
134 | - * @throws EE_Error |
|
135 | - */ |
|
136 | - public function column_status(EE_Event $item) |
|
137 | - { |
|
138 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
139 | - . $item->get_active_status() |
|
140 | - . '"></span>'; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param EE_Event $item |
|
147 | - * @return string |
|
148 | - * @throws EE_Error |
|
149 | - */ |
|
150 | - public function column_cb($item) |
|
151 | - { |
|
152 | - if (! $item instanceof EE_Event) { |
|
153 | - return ''; |
|
154 | - } |
|
155 | - $this->_dtt = $item->primary_datetime(); //set this for use in other columns |
|
156 | - //does event have any attached registrations? |
|
157 | - $regs = $item->count_related('Registration'); |
|
158 | - return $regs > 0 && $this->_view === 'trash' |
|
159 | - ? '<span class="ee-lock-icon"></span>' |
|
160 | - : sprintf( |
|
161 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
162 | - $item->ID() |
|
163 | - ); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @param EE_Event $item |
|
170 | - * @return mixed|string |
|
171 | - * @throws EE_Error |
|
172 | - */ |
|
173 | - public function column_id(EE_Event $item) |
|
174 | - { |
|
175 | - $content = $item->ID(); |
|
176 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
177 | - return $content; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param EE_Event $item |
|
184 | - * @return string |
|
185 | - * @throws EE_Error |
|
186 | - * @throws InvalidArgumentException |
|
187 | - * @throws InvalidDataTypeException |
|
188 | - * @throws InvalidInterfaceException |
|
189 | - */ |
|
190 | - public function column_name(EE_Event $item) |
|
191 | - { |
|
192 | - $edit_query_args = array( |
|
193 | - 'action' => 'edit', |
|
194 | - 'post' => $item->ID(), |
|
195 | - ); |
|
196 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
197 | - $actions = $this->_column_name_action_setup($item); |
|
198 | - $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
199 | - $content = '<strong><a class="row-title" href="' |
|
200 | - . $edit_link . '">' |
|
201 | - . $item->name() |
|
202 | - . '</a></strong>' |
|
203 | - . $status; |
|
204 | - $content .= '<br><span class="ee-status-text-small">' |
|
205 | - . EEH_Template::pretty_status( |
|
206 | - $item->get_active_status(), |
|
207 | - false, |
|
208 | - 'sentence' |
|
209 | - ) |
|
210 | - . '</span>'; |
|
211 | - $content .= $this->row_actions($actions); |
|
212 | - return $content; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Just a method for setting up the actions for the name column |
|
219 | - * |
|
220 | - * @param EE_Event $item |
|
221 | - * @return array array of actions |
|
222 | - * @throws EE_Error |
|
223 | - * @throws InvalidArgumentException |
|
224 | - * @throws InvalidDataTypeException |
|
225 | - * @throws InvalidInterfaceException |
|
226 | - */ |
|
227 | - protected function _column_name_action_setup(EE_Event $item) |
|
228 | - { |
|
229 | - //todo: remove when attendees is active |
|
230 | - if (! defined('REG_ADMIN_URL')) { |
|
231 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
232 | - } |
|
233 | - $actions = array(); |
|
234 | - $restore_event_link = ''; |
|
235 | - $delete_event_link = ''; |
|
236 | - $trash_event_link = ''; |
|
237 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
238 | - 'ee_edit_event', |
|
239 | - 'espresso_events_edit', |
|
240 | - $item->ID() |
|
241 | - )) { |
|
242 | - $edit_query_args = array( |
|
243 | - 'action' => 'edit', |
|
244 | - 'post' => $item->ID(), |
|
245 | - ); |
|
246 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
247 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
248 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
249 | - . esc_html__('Edit', 'event_espresso') |
|
250 | - . '</a>'; |
|
251 | - } |
|
252 | - if ( |
|
253 | - EE_Registry::instance()->CAP->current_user_can( |
|
254 | - 'ee_read_registrations', |
|
255 | - 'espresso_registrations_view_registration' |
|
256 | - ) |
|
257 | - && EE_Registry::instance()->CAP->current_user_can( |
|
258 | - 'ee_read_event', |
|
259 | - 'espresso_registrations_view_registration', |
|
260 | - $item->ID() |
|
261 | - ) |
|
262 | - ) { |
|
263 | - $attendees_query_args = array( |
|
264 | - 'action' => 'default', |
|
265 | - 'event_id' => $item->ID(), |
|
266 | - ); |
|
267 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
268 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
269 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
270 | - . esc_html__('Registrations', 'event_espresso') |
|
271 | - . '</a>'; |
|
272 | - } |
|
273 | - if ( |
|
274 | - EE_Registry::instance()->CAP->current_user_can( |
|
275 | - 'ee_delete_event', |
|
276 | - 'espresso_events_trash_event', |
|
277 | - $item->ID() |
|
278 | - ) |
|
279 | - ) { |
|
280 | - $trash_event_query_args = array( |
|
281 | - 'action' => 'trash_event', |
|
282 | - 'EVT_ID' => $item->ID(), |
|
283 | - ); |
|
284 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
285 | - $trash_event_query_args, |
|
286 | - EVENTS_ADMIN_URL |
|
287 | - ); |
|
288 | - } |
|
289 | - if ( |
|
290 | - EE_Registry::instance()->CAP->current_user_can( |
|
291 | - 'ee_delete_event', |
|
292 | - 'espresso_events_restore_event', |
|
293 | - $item->ID() |
|
294 | - ) |
|
295 | - ) { |
|
296 | - $restore_event_query_args = array( |
|
297 | - 'action' => 'restore_event', |
|
298 | - 'EVT_ID' => $item->ID(), |
|
299 | - ); |
|
300 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
301 | - $restore_event_query_args, |
|
302 | - EVENTS_ADMIN_URL |
|
303 | - ); |
|
304 | - } |
|
305 | - if ( |
|
306 | - EE_Registry::instance()->CAP->current_user_can( |
|
307 | - 'ee_delete_event', |
|
308 | - 'espresso_events_delete_event', |
|
309 | - $item->ID() |
|
310 | - ) |
|
311 | - ) { |
|
312 | - $delete_event_query_args = array( |
|
313 | - 'action' => 'delete_event', |
|
314 | - 'EVT_ID' => $item->ID(), |
|
315 | - ); |
|
316 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
317 | - $delete_event_query_args, |
|
318 | - EVENTS_ADMIN_URL |
|
319 | - ); |
|
320 | - } |
|
321 | - $view_link = get_permalink($item->ID()); |
|
322 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
323 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
324 | - . esc_html__('View', 'event_espresso') |
|
325 | - . '</a>'; |
|
326 | - if ($item->get('status') === 'trash') { |
|
327 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
328 | - 'ee_delete_event', |
|
329 | - 'espresso_events_restore_event', |
|
330 | - $item->ID() |
|
331 | - )) { |
|
332 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
333 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
334 | - . '">' |
|
335 | - . esc_html__('Restore from Trash', 'event_espresso') |
|
336 | - . '</a>'; |
|
337 | - } |
|
338 | - if ( |
|
339 | - $item->count_related('Registration') === 0 |
|
340 | - && EE_Registry::instance()->CAP->current_user_can( |
|
341 | - 'ee_delete_event', |
|
342 | - 'espresso_events_delete_event', |
|
343 | - $item->ID() |
|
344 | - ) |
|
345 | - ) { |
|
346 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
347 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
348 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
349 | - . '</a>'; |
|
350 | - } |
|
351 | - } else { |
|
352 | - if ( |
|
353 | - EE_Registry::instance()->CAP->current_user_can( |
|
354 | - 'ee_delete_event', |
|
355 | - 'espresso_events_trash_event', |
|
356 | - $item->ID() |
|
357 | - ) |
|
358 | - ) { |
|
359 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
360 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
361 | - . esc_html__('Trash', 'event_espresso') |
|
362 | - . '</a>'; |
|
363 | - } |
|
364 | - } |
|
365 | - return $actions; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * @param EE_Event $item |
|
372 | - * @return string |
|
373 | - * @throws EE_Error |
|
374 | - */ |
|
375 | - public function column_author(EE_Event $item) |
|
376 | - { |
|
377 | - //user author info |
|
378 | - $event_author = get_userdata($item->wp_user()); |
|
379 | - $gravatar = get_avatar($item->wp_user(), '15'); |
|
380 | - //filter link |
|
381 | - $query_args = array( |
|
382 | - 'action' => 'default', |
|
383 | - 'EVT_wp_user' => $item->wp_user(), |
|
384 | - ); |
|
385 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
386 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
387 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
388 | - . $event_author->display_name |
|
389 | - . '</a>'; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * @param EE_Event $item |
|
396 | - * @return string |
|
397 | - * @throws EE_Error |
|
398 | - */ |
|
399 | - public function column_venue(EE_Event $item) |
|
400 | - { |
|
401 | - $venue = $item->get_first_related('Venue'); |
|
402 | - return ! empty($venue) |
|
403 | - ? $venue->name() |
|
404 | - : ''; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * @param EE_Event $item |
|
410 | - * @return string |
|
411 | - * @throws EE_Error |
|
412 | - */ |
|
413 | - public function column_start_date_time(EE_Event $item) |
|
414 | - { |
|
415 | - return $this->_dtt instanceof EE_Datetime |
|
416 | - ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
417 | - : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * @param EE_Event $item |
|
423 | - * @return string |
|
424 | - * @throws EE_Error |
|
425 | - */ |
|
426 | - public function column_reg_begins(EE_Event $item) |
|
427 | - { |
|
428 | - $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
429 | - return $reg_start instanceof EE_Ticket |
|
430 | - ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
431 | - : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * @param EE_Event $item |
|
438 | - * @return int|string |
|
439 | - * @throws EE_Error |
|
440 | - * @throws InvalidArgumentException |
|
441 | - * @throws InvalidDataTypeException |
|
442 | - * @throws InvalidInterfaceException |
|
443 | - */ |
|
444 | - public function column_attendees(EE_Event $item) |
|
445 | - { |
|
446 | - $attendees_query_args = array( |
|
447 | - 'action' => 'default', |
|
448 | - 'event_id' => $item->ID(), |
|
449 | - ); |
|
450 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
451 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
452 | - return EE_Registry::instance()->CAP->current_user_can( |
|
453 | - 'ee_read_event', |
|
454 | - 'espresso_registrations_view_registration', |
|
455 | - $item->ID() |
|
456 | - ) |
|
457 | - && EE_Registry::instance()->CAP->current_user_can( |
|
458 | - 'ee_read_registrations', |
|
459 | - 'espresso_registrations_view_registration' |
|
460 | - ) |
|
461 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
462 | - : $registered_attendees; |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * @param EE_Event $item |
|
469 | - * @return float |
|
470 | - * @throws EE_Error |
|
471 | - * @throws InvalidArgumentException |
|
472 | - * @throws InvalidDataTypeException |
|
473 | - * @throws InvalidInterfaceException |
|
474 | - */ |
|
475 | - public function column_tkts_sold(EE_Event $item) |
|
476 | - { |
|
477 | - return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * @param EE_Event $item |
|
484 | - * @return string |
|
485 | - * @throws EE_Error |
|
486 | - * @throws InvalidArgumentException |
|
487 | - * @throws InvalidDataTypeException |
|
488 | - * @throws InvalidInterfaceException |
|
489 | - */ |
|
490 | - public function column_actions(EE_Event $item) |
|
491 | - { |
|
492 | - //todo: remove when attendees is active |
|
493 | - if (! defined('REG_ADMIN_URL')) { |
|
494 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
495 | - } |
|
496 | - $action_links = array(); |
|
497 | - $view_link = get_permalink($item->ID()); |
|
498 | - $action_links[] = '<a href="' . $view_link . '"' |
|
499 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
500 | - $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
501 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
502 | - 'ee_edit_event', |
|
503 | - 'espresso_events_edit', |
|
504 | - $item->ID() |
|
505 | - )) { |
|
506 | - $edit_query_args = array( |
|
507 | - 'action' => 'edit', |
|
508 | - 'post' => $item->ID(), |
|
509 | - ); |
|
510 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
511 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
512 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
513 | - . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
514 | - . '</a>'; |
|
515 | - } |
|
516 | - if ( |
|
517 | - EE_Registry::instance()->CAP->current_user_can( |
|
518 | - 'ee_read_registrations', |
|
519 | - 'espresso_registrations_view_registration' |
|
520 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
521 | - 'ee_read_event', |
|
522 | - 'espresso_registrations_view_registration', |
|
523 | - $item->ID() |
|
524 | - ) |
|
525 | - ) { |
|
526 | - $attendees_query_args = array( |
|
527 | - 'action' => 'default', |
|
528 | - 'event_id' => $item->ID(), |
|
529 | - ); |
|
530 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
531 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
532 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
533 | - . '<div class="dashicons dashicons-groups"></div>' |
|
534 | - . '</a>'; |
|
535 | - } |
|
536 | - $action_links = apply_filters( |
|
537 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
538 | - $action_links, |
|
539 | - $item |
|
540 | - ); |
|
541 | - return $this->_action_string( |
|
542 | - implode("\n\t", $action_links), |
|
543 | - $item, |
|
544 | - 'div' |
|
545 | - ); |
|
546 | - } |
|
21 | + /** |
|
22 | + * @var EE_Datetime |
|
23 | + */ |
|
24 | + private $_dtt; |
|
25 | + |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Initial setup of data properties for the list table. |
|
30 | + */ |
|
31 | + protected function _setup_data() |
|
32 | + { |
|
33 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
34 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Set up of additional properties for the list table. |
|
41 | + */ |
|
42 | + protected function _set_properties() |
|
43 | + { |
|
44 | + $this->_wp_list_args = array( |
|
45 | + 'singular' => esc_html__('event', 'event_espresso'), |
|
46 | + 'plural' => esc_html__('events', 'event_espresso'), |
|
47 | + 'ajax' => true, //for now |
|
48 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
49 | + ); |
|
50 | + $this->_columns = array( |
|
51 | + 'cb' => '<input type="checkbox" />', |
|
52 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
53 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
54 | + 'author' => esc_html__('Author', 'event_espresso'), |
|
55 | + 'venue' => esc_html__('Venue', 'event_espresso'), |
|
56 | + 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
57 | + 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
58 | + 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
59 | + . '<span class="screen-reader-text">' |
|
60 | + . esc_html__('Approved Registrations', 'event_espresso') |
|
61 | + . '</span>' |
|
62 | + . '</span>', |
|
63 | + //'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
64 | + 'actions' => esc_html__('Actions', 'event_espresso'), |
|
65 | + ); |
|
66 | + $this->_sortable_columns = array( |
|
67 | + 'id' => array('EVT_ID' => true), |
|
68 | + 'name' => array('EVT_name' => false), |
|
69 | + 'author' => array('EVT_wp_user' => false), |
|
70 | + 'venue' => array('Venue.VNU_name' => false), |
|
71 | + 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
72 | + 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
73 | + ); |
|
74 | + $this->_primary_column = 'id'; |
|
75 | + $this->_hidden_columns = array('author'); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @return array |
|
82 | + */ |
|
83 | + protected function _get_table_filters() |
|
84 | + { |
|
85 | + return array(); //no filters with decaf |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Setup of views properties. |
|
92 | + * |
|
93 | + * @throws InvalidDataTypeException |
|
94 | + * @throws InvalidInterfaceException |
|
95 | + * @throws InvalidArgumentException |
|
96 | + */ |
|
97 | + protected function _add_view_counts() |
|
98 | + { |
|
99 | + $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
100 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
101 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
102 | + 'ee_delete_events', |
|
103 | + 'espresso_events_trash_events' |
|
104 | + )) { |
|
105 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @param EE_Event $item |
|
113 | + * @return string |
|
114 | + * @throws EE_Error |
|
115 | + */ |
|
116 | + protected function _get_row_class($item) |
|
117 | + { |
|
118 | + $class = parent::_get_row_class($item); |
|
119 | + //add status class |
|
120 | + $class .= $item instanceof EE_Event |
|
121 | + ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
122 | + : ''; |
|
123 | + if ($this->_has_checkbox_column) { |
|
124 | + $class .= ' has-checkbox-column'; |
|
125 | + } |
|
126 | + return $class; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @param EE_Event $item |
|
133 | + * @return string |
|
134 | + * @throws EE_Error |
|
135 | + */ |
|
136 | + public function column_status(EE_Event $item) |
|
137 | + { |
|
138 | + return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
139 | + . $item->get_active_status() |
|
140 | + . '"></span>'; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param EE_Event $item |
|
147 | + * @return string |
|
148 | + * @throws EE_Error |
|
149 | + */ |
|
150 | + public function column_cb($item) |
|
151 | + { |
|
152 | + if (! $item instanceof EE_Event) { |
|
153 | + return ''; |
|
154 | + } |
|
155 | + $this->_dtt = $item->primary_datetime(); //set this for use in other columns |
|
156 | + //does event have any attached registrations? |
|
157 | + $regs = $item->count_related('Registration'); |
|
158 | + return $regs > 0 && $this->_view === 'trash' |
|
159 | + ? '<span class="ee-lock-icon"></span>' |
|
160 | + : sprintf( |
|
161 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
162 | + $item->ID() |
|
163 | + ); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @param EE_Event $item |
|
170 | + * @return mixed|string |
|
171 | + * @throws EE_Error |
|
172 | + */ |
|
173 | + public function column_id(EE_Event $item) |
|
174 | + { |
|
175 | + $content = $item->ID(); |
|
176 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
177 | + return $content; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param EE_Event $item |
|
184 | + * @return string |
|
185 | + * @throws EE_Error |
|
186 | + * @throws InvalidArgumentException |
|
187 | + * @throws InvalidDataTypeException |
|
188 | + * @throws InvalidInterfaceException |
|
189 | + */ |
|
190 | + public function column_name(EE_Event $item) |
|
191 | + { |
|
192 | + $edit_query_args = array( |
|
193 | + 'action' => 'edit', |
|
194 | + 'post' => $item->ID(), |
|
195 | + ); |
|
196 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
197 | + $actions = $this->_column_name_action_setup($item); |
|
198 | + $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
199 | + $content = '<strong><a class="row-title" href="' |
|
200 | + . $edit_link . '">' |
|
201 | + . $item->name() |
|
202 | + . '</a></strong>' |
|
203 | + . $status; |
|
204 | + $content .= '<br><span class="ee-status-text-small">' |
|
205 | + . EEH_Template::pretty_status( |
|
206 | + $item->get_active_status(), |
|
207 | + false, |
|
208 | + 'sentence' |
|
209 | + ) |
|
210 | + . '</span>'; |
|
211 | + $content .= $this->row_actions($actions); |
|
212 | + return $content; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Just a method for setting up the actions for the name column |
|
219 | + * |
|
220 | + * @param EE_Event $item |
|
221 | + * @return array array of actions |
|
222 | + * @throws EE_Error |
|
223 | + * @throws InvalidArgumentException |
|
224 | + * @throws InvalidDataTypeException |
|
225 | + * @throws InvalidInterfaceException |
|
226 | + */ |
|
227 | + protected function _column_name_action_setup(EE_Event $item) |
|
228 | + { |
|
229 | + //todo: remove when attendees is active |
|
230 | + if (! defined('REG_ADMIN_URL')) { |
|
231 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
232 | + } |
|
233 | + $actions = array(); |
|
234 | + $restore_event_link = ''; |
|
235 | + $delete_event_link = ''; |
|
236 | + $trash_event_link = ''; |
|
237 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
238 | + 'ee_edit_event', |
|
239 | + 'espresso_events_edit', |
|
240 | + $item->ID() |
|
241 | + )) { |
|
242 | + $edit_query_args = array( |
|
243 | + 'action' => 'edit', |
|
244 | + 'post' => $item->ID(), |
|
245 | + ); |
|
246 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
247 | + $actions['edit'] = '<a href="' . $edit_link . '"' |
|
248 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
249 | + . esc_html__('Edit', 'event_espresso') |
|
250 | + . '</a>'; |
|
251 | + } |
|
252 | + if ( |
|
253 | + EE_Registry::instance()->CAP->current_user_can( |
|
254 | + 'ee_read_registrations', |
|
255 | + 'espresso_registrations_view_registration' |
|
256 | + ) |
|
257 | + && EE_Registry::instance()->CAP->current_user_can( |
|
258 | + 'ee_read_event', |
|
259 | + 'espresso_registrations_view_registration', |
|
260 | + $item->ID() |
|
261 | + ) |
|
262 | + ) { |
|
263 | + $attendees_query_args = array( |
|
264 | + 'action' => 'default', |
|
265 | + 'event_id' => $item->ID(), |
|
266 | + ); |
|
267 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
268 | + $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
269 | + . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
270 | + . esc_html__('Registrations', 'event_espresso') |
|
271 | + . '</a>'; |
|
272 | + } |
|
273 | + if ( |
|
274 | + EE_Registry::instance()->CAP->current_user_can( |
|
275 | + 'ee_delete_event', |
|
276 | + 'espresso_events_trash_event', |
|
277 | + $item->ID() |
|
278 | + ) |
|
279 | + ) { |
|
280 | + $trash_event_query_args = array( |
|
281 | + 'action' => 'trash_event', |
|
282 | + 'EVT_ID' => $item->ID(), |
|
283 | + ); |
|
284 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
285 | + $trash_event_query_args, |
|
286 | + EVENTS_ADMIN_URL |
|
287 | + ); |
|
288 | + } |
|
289 | + if ( |
|
290 | + EE_Registry::instance()->CAP->current_user_can( |
|
291 | + 'ee_delete_event', |
|
292 | + 'espresso_events_restore_event', |
|
293 | + $item->ID() |
|
294 | + ) |
|
295 | + ) { |
|
296 | + $restore_event_query_args = array( |
|
297 | + 'action' => 'restore_event', |
|
298 | + 'EVT_ID' => $item->ID(), |
|
299 | + ); |
|
300 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
301 | + $restore_event_query_args, |
|
302 | + EVENTS_ADMIN_URL |
|
303 | + ); |
|
304 | + } |
|
305 | + if ( |
|
306 | + EE_Registry::instance()->CAP->current_user_can( |
|
307 | + 'ee_delete_event', |
|
308 | + 'espresso_events_delete_event', |
|
309 | + $item->ID() |
|
310 | + ) |
|
311 | + ) { |
|
312 | + $delete_event_query_args = array( |
|
313 | + 'action' => 'delete_event', |
|
314 | + 'EVT_ID' => $item->ID(), |
|
315 | + ); |
|
316 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
317 | + $delete_event_query_args, |
|
318 | + EVENTS_ADMIN_URL |
|
319 | + ); |
|
320 | + } |
|
321 | + $view_link = get_permalink($item->ID()); |
|
322 | + $actions['view'] = '<a href="' . $view_link . '"' |
|
323 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
324 | + . esc_html__('View', 'event_espresso') |
|
325 | + . '</a>'; |
|
326 | + if ($item->get('status') === 'trash') { |
|
327 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
328 | + 'ee_delete_event', |
|
329 | + 'espresso_events_restore_event', |
|
330 | + $item->ID() |
|
331 | + )) { |
|
332 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
333 | + . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
334 | + . '">' |
|
335 | + . esc_html__('Restore from Trash', 'event_espresso') |
|
336 | + . '</a>'; |
|
337 | + } |
|
338 | + if ( |
|
339 | + $item->count_related('Registration') === 0 |
|
340 | + && EE_Registry::instance()->CAP->current_user_can( |
|
341 | + 'ee_delete_event', |
|
342 | + 'espresso_events_delete_event', |
|
343 | + $item->ID() |
|
344 | + ) |
|
345 | + ) { |
|
346 | + $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
347 | + . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
348 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
349 | + . '</a>'; |
|
350 | + } |
|
351 | + } else { |
|
352 | + if ( |
|
353 | + EE_Registry::instance()->CAP->current_user_can( |
|
354 | + 'ee_delete_event', |
|
355 | + 'espresso_events_trash_event', |
|
356 | + $item->ID() |
|
357 | + ) |
|
358 | + ) { |
|
359 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
360 | + . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
361 | + . esc_html__('Trash', 'event_espresso') |
|
362 | + . '</a>'; |
|
363 | + } |
|
364 | + } |
|
365 | + return $actions; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * @param EE_Event $item |
|
372 | + * @return string |
|
373 | + * @throws EE_Error |
|
374 | + */ |
|
375 | + public function column_author(EE_Event $item) |
|
376 | + { |
|
377 | + //user author info |
|
378 | + $event_author = get_userdata($item->wp_user()); |
|
379 | + $gravatar = get_avatar($item->wp_user(), '15'); |
|
380 | + //filter link |
|
381 | + $query_args = array( |
|
382 | + 'action' => 'default', |
|
383 | + 'EVT_wp_user' => $item->wp_user(), |
|
384 | + ); |
|
385 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
386 | + return $gravatar . ' <a href="' . $filter_url . '"' |
|
387 | + . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
388 | + . $event_author->display_name |
|
389 | + . '</a>'; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * @param EE_Event $item |
|
396 | + * @return string |
|
397 | + * @throws EE_Error |
|
398 | + */ |
|
399 | + public function column_venue(EE_Event $item) |
|
400 | + { |
|
401 | + $venue = $item->get_first_related('Venue'); |
|
402 | + return ! empty($venue) |
|
403 | + ? $venue->name() |
|
404 | + : ''; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * @param EE_Event $item |
|
410 | + * @return string |
|
411 | + * @throws EE_Error |
|
412 | + */ |
|
413 | + public function column_start_date_time(EE_Event $item) |
|
414 | + { |
|
415 | + return $this->_dtt instanceof EE_Datetime |
|
416 | + ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
417 | + : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * @param EE_Event $item |
|
423 | + * @return string |
|
424 | + * @throws EE_Error |
|
425 | + */ |
|
426 | + public function column_reg_begins(EE_Event $item) |
|
427 | + { |
|
428 | + $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
429 | + return $reg_start instanceof EE_Ticket |
|
430 | + ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
431 | + : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * @param EE_Event $item |
|
438 | + * @return int|string |
|
439 | + * @throws EE_Error |
|
440 | + * @throws InvalidArgumentException |
|
441 | + * @throws InvalidDataTypeException |
|
442 | + * @throws InvalidInterfaceException |
|
443 | + */ |
|
444 | + public function column_attendees(EE_Event $item) |
|
445 | + { |
|
446 | + $attendees_query_args = array( |
|
447 | + 'action' => 'default', |
|
448 | + 'event_id' => $item->ID(), |
|
449 | + ); |
|
450 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
451 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
452 | + return EE_Registry::instance()->CAP->current_user_can( |
|
453 | + 'ee_read_event', |
|
454 | + 'espresso_registrations_view_registration', |
|
455 | + $item->ID() |
|
456 | + ) |
|
457 | + && EE_Registry::instance()->CAP->current_user_can( |
|
458 | + 'ee_read_registrations', |
|
459 | + 'espresso_registrations_view_registration' |
|
460 | + ) |
|
461 | + ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
462 | + : $registered_attendees; |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * @param EE_Event $item |
|
469 | + * @return float |
|
470 | + * @throws EE_Error |
|
471 | + * @throws InvalidArgumentException |
|
472 | + * @throws InvalidDataTypeException |
|
473 | + * @throws InvalidInterfaceException |
|
474 | + */ |
|
475 | + public function column_tkts_sold(EE_Event $item) |
|
476 | + { |
|
477 | + return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * @param EE_Event $item |
|
484 | + * @return string |
|
485 | + * @throws EE_Error |
|
486 | + * @throws InvalidArgumentException |
|
487 | + * @throws InvalidDataTypeException |
|
488 | + * @throws InvalidInterfaceException |
|
489 | + */ |
|
490 | + public function column_actions(EE_Event $item) |
|
491 | + { |
|
492 | + //todo: remove when attendees is active |
|
493 | + if (! defined('REG_ADMIN_URL')) { |
|
494 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
495 | + } |
|
496 | + $action_links = array(); |
|
497 | + $view_link = get_permalink($item->ID()); |
|
498 | + $action_links[] = '<a href="' . $view_link . '"' |
|
499 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
500 | + $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
501 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
502 | + 'ee_edit_event', |
|
503 | + 'espresso_events_edit', |
|
504 | + $item->ID() |
|
505 | + )) { |
|
506 | + $edit_query_args = array( |
|
507 | + 'action' => 'edit', |
|
508 | + 'post' => $item->ID(), |
|
509 | + ); |
|
510 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
511 | + $action_links[] = '<a href="' . $edit_link . '"' |
|
512 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
513 | + . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
514 | + . '</a>'; |
|
515 | + } |
|
516 | + if ( |
|
517 | + EE_Registry::instance()->CAP->current_user_can( |
|
518 | + 'ee_read_registrations', |
|
519 | + 'espresso_registrations_view_registration' |
|
520 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
521 | + 'ee_read_event', |
|
522 | + 'espresso_registrations_view_registration', |
|
523 | + $item->ID() |
|
524 | + ) |
|
525 | + ) { |
|
526 | + $attendees_query_args = array( |
|
527 | + 'action' => 'default', |
|
528 | + 'event_id' => $item->ID(), |
|
529 | + ); |
|
530 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
531 | + $action_links[] = '<a href="' . $attendees_link . '"' |
|
532 | + . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
533 | + . '<div class="dashicons dashicons-groups"></div>' |
|
534 | + . '</a>'; |
|
535 | + } |
|
536 | + $action_links = apply_filters( |
|
537 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
538 | + $action_links, |
|
539 | + $item |
|
540 | + ); |
|
541 | + return $this->_action_string( |
|
542 | + implode("\n\t", $action_links), |
|
543 | + $item, |
|
544 | + 'div' |
|
545 | + ); |
|
546 | + } |
|
547 | 547 | } |
@@ -15,115 +15,115 @@ |
||
15 | 15 | class Extend_EE_Registrations_List_Table extends EE_Registrations_List_Table |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param EE_Registration $item |
|
20 | - * @return string |
|
21 | - * @throws EE_Error |
|
22 | - * @throws InvalidArgumentException |
|
23 | - * @throws ReflectionException |
|
24 | - * @throws InvalidDataTypeException |
|
25 | - * @throws InvalidInterfaceException |
|
26 | - */ |
|
27 | - function column__REG_date(EE_Registration $item) |
|
28 | - { |
|
29 | - $date_linked = parent::column__REG_date($item); |
|
30 | - $actions = array(); |
|
31 | - //Build row actions |
|
32 | - $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
33 | - 'action' => 'event_registrations', |
|
34 | - 'event_id' => $item->event_ID(), |
|
35 | - ), REG_ADMIN_URL); |
|
36 | - $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can( |
|
37 | - 'ee_read_registration', |
|
38 | - 'espresso_registrations_registration_checkins', |
|
39 | - $item->ID() |
|
40 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
41 | - 'ee_read_checkins', |
|
42 | - 'espresso_registrations_registration_checkins' |
|
43 | - ) |
|
44 | - ? '<a href="' . $check_in_url . '"' |
|
45 | - . ' title="' . esc_attr__( |
|
46 | - 'The Check-In List allows you to easily toggle check-in status for this event', |
|
47 | - 'event_espresso' |
|
48 | - ) |
|
49 | - . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
50 | - : esc_html__('View Check-ins', 'event_espresso'); |
|
18 | + /** |
|
19 | + * @param EE_Registration $item |
|
20 | + * @return string |
|
21 | + * @throws EE_Error |
|
22 | + * @throws InvalidArgumentException |
|
23 | + * @throws ReflectionException |
|
24 | + * @throws InvalidDataTypeException |
|
25 | + * @throws InvalidInterfaceException |
|
26 | + */ |
|
27 | + function column__REG_date(EE_Registration $item) |
|
28 | + { |
|
29 | + $date_linked = parent::column__REG_date($item); |
|
30 | + $actions = array(); |
|
31 | + //Build row actions |
|
32 | + $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
33 | + 'action' => 'event_registrations', |
|
34 | + 'event_id' => $item->event_ID(), |
|
35 | + ), REG_ADMIN_URL); |
|
36 | + $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can( |
|
37 | + 'ee_read_registration', |
|
38 | + 'espresso_registrations_registration_checkins', |
|
39 | + $item->ID() |
|
40 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
41 | + 'ee_read_checkins', |
|
42 | + 'espresso_registrations_registration_checkins' |
|
43 | + ) |
|
44 | + ? '<a href="' . $check_in_url . '"' |
|
45 | + . ' title="' . esc_attr__( |
|
46 | + 'The Check-In List allows you to easily toggle check-in status for this event', |
|
47 | + 'event_espresso' |
|
48 | + ) |
|
49 | + . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
50 | + : esc_html__('View Check-ins', 'event_espresso'); |
|
51 | 51 | |
52 | - return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
|
53 | - } |
|
52 | + return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * column_default |
|
58 | - * |
|
59 | - * @param \EE_Registration $item |
|
60 | - * @return string |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidArgumentException |
|
63 | - * @throws InvalidDataTypeException |
|
64 | - * @throws InvalidInterfaceException |
|
65 | - * @throws ReflectionException |
|
66 | - */ |
|
67 | - public function column_DTT_EVT_start(EE_Registration $item) |
|
68 | - { |
|
69 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
70 | - $ticket = $item->ticket(); |
|
71 | - $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
72 | - $EVT_ID = $item->event_ID(); |
|
73 | - $datetimes_for_display = array(); |
|
74 | - foreach ($datetimes as $datetime) { |
|
75 | - $datetime_string = ''; |
|
76 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
77 | - 'ee_read_checkin', |
|
78 | - 'espresso_registrations_registration_checkins', |
|
79 | - $item->ID() |
|
80 | - )) { |
|
81 | - // open "a" tag and "href" |
|
82 | - $datetime_string .= '<a href="'; |
|
83 | - // checkin URL |
|
84 | - $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
85 | - array( |
|
86 | - 'action' => 'event_registrations', |
|
87 | - 'event_id' => $EVT_ID, |
|
88 | - 'DTT_ID' => $datetime->ID(), |
|
89 | - ), |
|
90 | - REG_ADMIN_URL |
|
91 | - ); |
|
92 | - // close "href" |
|
93 | - $datetime_string .= '"'; |
|
94 | - // open "title" tag |
|
95 | - $datetime_string .= ' title="'; |
|
96 | - // link title text |
|
97 | - $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
98 | - // close "title" tag and end of "a" tag opening |
|
99 | - $datetime_string .= '">'; |
|
100 | - // link text |
|
101 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
102 | - // close "a" tag |
|
103 | - $datetime_string .= '</a>'; |
|
104 | - } else { |
|
105 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
106 | - } |
|
107 | - // add a "View Registrations" link that filters list by event AND datetime |
|
108 | - $datetime_string .= $this->row_actions( |
|
109 | - array( |
|
110 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
111 | - array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
112 | - REG_ADMIN_URL |
|
113 | - ) |
|
114 | - . '" title="' . sprintf( |
|
115 | - esc_attr__( |
|
116 | - 'Filter this list to only show registrations for this datetime %s', |
|
117 | - 'event_espresso' |
|
118 | - ), |
|
119 | - $datetime->name() |
|
120 | - ) . '">' |
|
121 | - . esc_html__('View Registrations', 'event_espresso') |
|
122 | - . '</a>', |
|
123 | - ) |
|
124 | - ); |
|
125 | - $datetimes_for_display[] = $datetime_string; |
|
126 | - } |
|
127 | - return $this->generateDisplayForDateTimes($datetimes_for_display); |
|
128 | - } |
|
56 | + /** |
|
57 | + * column_default |
|
58 | + * |
|
59 | + * @param \EE_Registration $item |
|
60 | + * @return string |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidArgumentException |
|
63 | + * @throws InvalidDataTypeException |
|
64 | + * @throws InvalidInterfaceException |
|
65 | + * @throws ReflectionException |
|
66 | + */ |
|
67 | + public function column_DTT_EVT_start(EE_Registration $item) |
|
68 | + { |
|
69 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
70 | + $ticket = $item->ticket(); |
|
71 | + $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
72 | + $EVT_ID = $item->event_ID(); |
|
73 | + $datetimes_for_display = array(); |
|
74 | + foreach ($datetimes as $datetime) { |
|
75 | + $datetime_string = ''; |
|
76 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
77 | + 'ee_read_checkin', |
|
78 | + 'espresso_registrations_registration_checkins', |
|
79 | + $item->ID() |
|
80 | + )) { |
|
81 | + // open "a" tag and "href" |
|
82 | + $datetime_string .= '<a href="'; |
|
83 | + // checkin URL |
|
84 | + $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
85 | + array( |
|
86 | + 'action' => 'event_registrations', |
|
87 | + 'event_id' => $EVT_ID, |
|
88 | + 'DTT_ID' => $datetime->ID(), |
|
89 | + ), |
|
90 | + REG_ADMIN_URL |
|
91 | + ); |
|
92 | + // close "href" |
|
93 | + $datetime_string .= '"'; |
|
94 | + // open "title" tag |
|
95 | + $datetime_string .= ' title="'; |
|
96 | + // link title text |
|
97 | + $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
98 | + // close "title" tag and end of "a" tag opening |
|
99 | + $datetime_string .= '">'; |
|
100 | + // link text |
|
101 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
102 | + // close "a" tag |
|
103 | + $datetime_string .= '</a>'; |
|
104 | + } else { |
|
105 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
106 | + } |
|
107 | + // add a "View Registrations" link that filters list by event AND datetime |
|
108 | + $datetime_string .= $this->row_actions( |
|
109 | + array( |
|
110 | + 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
111 | + array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
112 | + REG_ADMIN_URL |
|
113 | + ) |
|
114 | + . '" title="' . sprintf( |
|
115 | + esc_attr__( |
|
116 | + 'Filter this list to only show registrations for this datetime %s', |
|
117 | + 'event_espresso' |
|
118 | + ), |
|
119 | + $datetime->name() |
|
120 | + ) . '">' |
|
121 | + . esc_html__('View Registrations', 'event_espresso') |
|
122 | + . '</a>', |
|
123 | + ) |
|
124 | + ); |
|
125 | + $datetimes_for_display[] = $datetime_string; |
|
126 | + } |
|
127 | + return $this->generateDisplayForDateTimes($datetimes_for_display); |
|
128 | + } |
|
129 | 129 | } |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | 'ee_read_checkins', |
42 | 42 | 'espresso_registrations_registration_checkins' |
43 | 43 | ) |
44 | - ? '<a href="' . $check_in_url . '"' |
|
45 | - . ' title="' . esc_attr__( |
|
44 | + ? '<a href="'.$check_in_url.'"' |
|
45 | + . ' title="'.esc_attr__( |
|
46 | 46 | 'The Check-In List allows you to easily toggle check-in status for this event', |
47 | 47 | 'event_espresso' |
48 | 48 | ) |
49 | - . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
49 | + . '">'.esc_html__('View Check-ins', 'event_espresso').'</a>' |
|
50 | 50 | : esc_html__('View Check-ins', 'event_espresso'); |
51 | 51 | |
52 | 52 | return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
@@ -107,17 +107,17 @@ discard block |
||
107 | 107 | // add a "View Registrations" link that filters list by event AND datetime |
108 | 108 | $datetime_string .= $this->row_actions( |
109 | 109 | array( |
110 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
110 | + 'event_datetime_filter' => '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
111 | 111 | array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
112 | 112 | REG_ADMIN_URL |
113 | 113 | ) |
114 | - . '" title="' . sprintf( |
|
114 | + . '" title="'.sprintf( |
|
115 | 115 | esc_attr__( |
116 | 116 | 'Filter this list to only show registrations for this datetime %s', |
117 | 117 | 'event_espresso' |
118 | 118 | ), |
119 | 119 | $datetime->name() |
120 | - ) . '">' |
|
120 | + ).'">' |
|
121 | 121 | . esc_html__('View Registrations', 'event_espresso') |
122 | 122 | . '</a>', |
123 | 123 | ) |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
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 | |
@@ -28,1006 +28,1006 @@ discard block |
||
28 | 28 | { |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - private $_status; |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + private $_status; |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * An array of transaction details for the related transaction to the registration being processed. |
|
39 | - * This is set via the _set_related_details method. |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $_transaction_details = array(); |
|
37 | + /** |
|
38 | + * An array of transaction details for the related transaction to the registration being processed. |
|
39 | + * This is set via the _set_related_details method. |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $_transaction_details = array(); |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * An array of event details for the related event to the registration being processed. |
|
48 | - * This is set via the _set_related_details method. |
|
49 | - * |
|
50 | - * @var array |
|
51 | - */ |
|
52 | - protected $_event_details = array(); |
|
46 | + /** |
|
47 | + * An array of event details for the related event to the registration being processed. |
|
48 | + * This is set via the _set_related_details method. |
|
49 | + * |
|
50 | + * @var array |
|
51 | + */ |
|
52 | + protected $_event_details = array(); |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @param \Registrations_Admin_Page $admin_page |
|
57 | - */ |
|
58 | - public function __construct(Registrations_Admin_Page $admin_page) |
|
59 | - { |
|
60 | - if (! empty($_GET['event_id'])) { |
|
61 | - $extra_query_args = array(); |
|
62 | - foreach ($admin_page->get_views() as $key => $view_details) { |
|
63 | - $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']); |
|
64 | - } |
|
65 | - $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args); |
|
66 | - } |
|
67 | - parent::__construct($admin_page); |
|
68 | - $this->_status = $this->_admin_page->get_registration_status_array(); |
|
69 | - } |
|
55 | + /** |
|
56 | + * @param \Registrations_Admin_Page $admin_page |
|
57 | + */ |
|
58 | + public function __construct(Registrations_Admin_Page $admin_page) |
|
59 | + { |
|
60 | + if (! empty($_GET['event_id'])) { |
|
61 | + $extra_query_args = array(); |
|
62 | + foreach ($admin_page->get_views() as $key => $view_details) { |
|
63 | + $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']); |
|
64 | + } |
|
65 | + $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args); |
|
66 | + } |
|
67 | + parent::__construct($admin_page); |
|
68 | + $this->_status = $this->_admin_page->get_registration_status_array(); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * _setup_data |
|
74 | - * |
|
75 | - * @access protected |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - protected function _setup_data() |
|
79 | - { |
|
80 | - $this->_data = $this->_admin_page->get_registrations($this->_per_page); |
|
81 | - $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false); |
|
82 | - } |
|
72 | + /** |
|
73 | + * _setup_data |
|
74 | + * |
|
75 | + * @access protected |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + protected function _setup_data() |
|
79 | + { |
|
80 | + $this->_data = $this->_admin_page->get_registrations($this->_per_page); |
|
81 | + $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false); |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * _set_properties |
|
87 | - * |
|
88 | - * @access protected |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - protected function _set_properties() |
|
92 | - { |
|
93 | - $this->_wp_list_args = array( |
|
94 | - 'singular' => __('registration', 'event_espresso'), |
|
95 | - 'plural' => __('registrations', 'event_espresso'), |
|
96 | - 'ajax' => true, |
|
97 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
98 | - ); |
|
99 | - $ID_column_name = __('ID', 'event_espresso'); |
|
100 | - $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
101 | - $ID_column_name .= __('Registrant Name', 'event_espresso'); |
|
102 | - $ID_column_name .= '</span> '; |
|
103 | - if (isset($_GET['event_id'])) { |
|
104 | - $this->_columns = array( |
|
105 | - 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
106 | - '_REG_ID' => $ID_column_name, |
|
107 | - 'ATT_fname' => __('Name', 'event_espresso'), |
|
108 | - 'ATT_email' => __('Email', 'event_espresso'), |
|
109 | - '_REG_date' => __('Reg Date', 'event_espresso'), |
|
110 | - 'PRC_amount' => __('TKT Price', 'event_espresso'), |
|
111 | - '_REG_final_price' => __('Final Price', 'event_espresso'), |
|
112 | - 'TXN_total' => __('Total Txn', 'event_espresso'), |
|
113 | - 'TXN_paid' => __('Paid', 'event_espresso'), |
|
114 | - 'actions' => __('Actions', 'event_espresso'), |
|
115 | - ); |
|
116 | - $this->_bottom_buttons = array( |
|
117 | - 'report' => array( |
|
118 | - 'route' => 'registrations_report', |
|
119 | - 'extra_request' => array( |
|
120 | - 'EVT_ID' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
121 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
122 | - ), |
|
123 | - ), |
|
124 | - ); |
|
125 | - } else { |
|
126 | - $this->_columns = array( |
|
127 | - 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
128 | - '_REG_ID' => $ID_column_name, |
|
129 | - 'ATT_fname' => __('Name', 'event_espresso'), |
|
130 | - '_REG_date' => __('TXN Date', 'event_espresso'), |
|
131 | - 'event_name' => __('Event', 'event_espresso'), |
|
132 | - 'DTT_EVT_start' => __('Event Date', 'event_espresso'), |
|
133 | - '_REG_final_price' => __('Price', 'event_espresso'), |
|
134 | - '_REG_paid' => __('Paid', 'event_espresso'), |
|
135 | - 'actions' => __('Actions', 'event_espresso'), |
|
136 | - ); |
|
137 | - $this->_bottom_buttons = array( |
|
138 | - 'report_all' => array( |
|
139 | - 'route' => 'registrations_report', |
|
140 | - 'extra_request' => array( |
|
141 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
142 | - ), |
|
143 | - ), |
|
144 | - ); |
|
145 | - } |
|
146 | - $this->_bottom_buttons['report_filtered'] = array( |
|
147 | - 'route' => 'registrations_report', |
|
148 | - 'extra_request' => array( |
|
149 | - 'use_filters' => true, |
|
150 | - 'filters' => array_diff_key($this->_req_data, array_flip(array( |
|
151 | - 'page', |
|
152 | - 'action', |
|
153 | - 'default_nonce', |
|
154 | - ))), |
|
155 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
156 | - ), |
|
157 | - ); |
|
158 | - $this->_primary_column = '_REG_ID'; |
|
159 | - $this->_sortable_columns = array( |
|
160 | - '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
161 | - /** |
|
162 | - * Allows users to change the default sort if they wish. |
|
163 | - * Returning a falsey on this filter will result in the default sort to be by firstname rather than last |
|
164 | - * name. |
|
165 | - */ |
|
166 | - 'ATT_fname' => array( |
|
167 | - 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
168 | - true, |
|
169 | - $this, |
|
170 | - ) |
|
171 | - ? array('ATT_lname' => false) |
|
172 | - : array('ATT_fname' => false), |
|
173 | - 'event_name' => array('event_name' => false), |
|
174 | - 'DTT_EVT_start' => array('DTT_EVT_start' => false), |
|
175 | - '_REG_ID' => array('_REG_ID' => false), |
|
176 | - ); |
|
177 | - $this->_hidden_columns = array(); |
|
178 | - } |
|
85 | + /** |
|
86 | + * _set_properties |
|
87 | + * |
|
88 | + * @access protected |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + protected function _set_properties() |
|
92 | + { |
|
93 | + $this->_wp_list_args = array( |
|
94 | + 'singular' => __('registration', 'event_espresso'), |
|
95 | + 'plural' => __('registrations', 'event_espresso'), |
|
96 | + 'ajax' => true, |
|
97 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
98 | + ); |
|
99 | + $ID_column_name = __('ID', 'event_espresso'); |
|
100 | + $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
101 | + $ID_column_name .= __('Registrant Name', 'event_espresso'); |
|
102 | + $ID_column_name .= '</span> '; |
|
103 | + if (isset($_GET['event_id'])) { |
|
104 | + $this->_columns = array( |
|
105 | + 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
106 | + '_REG_ID' => $ID_column_name, |
|
107 | + 'ATT_fname' => __('Name', 'event_espresso'), |
|
108 | + 'ATT_email' => __('Email', 'event_espresso'), |
|
109 | + '_REG_date' => __('Reg Date', 'event_espresso'), |
|
110 | + 'PRC_amount' => __('TKT Price', 'event_espresso'), |
|
111 | + '_REG_final_price' => __('Final Price', 'event_espresso'), |
|
112 | + 'TXN_total' => __('Total Txn', 'event_espresso'), |
|
113 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
114 | + 'actions' => __('Actions', 'event_espresso'), |
|
115 | + ); |
|
116 | + $this->_bottom_buttons = array( |
|
117 | + 'report' => array( |
|
118 | + 'route' => 'registrations_report', |
|
119 | + 'extra_request' => array( |
|
120 | + 'EVT_ID' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
121 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
122 | + ), |
|
123 | + ), |
|
124 | + ); |
|
125 | + } else { |
|
126 | + $this->_columns = array( |
|
127 | + 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
128 | + '_REG_ID' => $ID_column_name, |
|
129 | + 'ATT_fname' => __('Name', 'event_espresso'), |
|
130 | + '_REG_date' => __('TXN Date', 'event_espresso'), |
|
131 | + 'event_name' => __('Event', 'event_espresso'), |
|
132 | + 'DTT_EVT_start' => __('Event Date', 'event_espresso'), |
|
133 | + '_REG_final_price' => __('Price', 'event_espresso'), |
|
134 | + '_REG_paid' => __('Paid', 'event_espresso'), |
|
135 | + 'actions' => __('Actions', 'event_espresso'), |
|
136 | + ); |
|
137 | + $this->_bottom_buttons = array( |
|
138 | + 'report_all' => array( |
|
139 | + 'route' => 'registrations_report', |
|
140 | + 'extra_request' => array( |
|
141 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
142 | + ), |
|
143 | + ), |
|
144 | + ); |
|
145 | + } |
|
146 | + $this->_bottom_buttons['report_filtered'] = array( |
|
147 | + 'route' => 'registrations_report', |
|
148 | + 'extra_request' => array( |
|
149 | + 'use_filters' => true, |
|
150 | + 'filters' => array_diff_key($this->_req_data, array_flip(array( |
|
151 | + 'page', |
|
152 | + 'action', |
|
153 | + 'default_nonce', |
|
154 | + ))), |
|
155 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
156 | + ), |
|
157 | + ); |
|
158 | + $this->_primary_column = '_REG_ID'; |
|
159 | + $this->_sortable_columns = array( |
|
160 | + '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
161 | + /** |
|
162 | + * Allows users to change the default sort if they wish. |
|
163 | + * Returning a falsey on this filter will result in the default sort to be by firstname rather than last |
|
164 | + * name. |
|
165 | + */ |
|
166 | + 'ATT_fname' => array( |
|
167 | + 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
168 | + true, |
|
169 | + $this, |
|
170 | + ) |
|
171 | + ? array('ATT_lname' => false) |
|
172 | + : array('ATT_fname' => false), |
|
173 | + 'event_name' => array('event_name' => false), |
|
174 | + 'DTT_EVT_start' => array('DTT_EVT_start' => false), |
|
175 | + '_REG_ID' => array('_REG_ID' => false), |
|
176 | + ); |
|
177 | + $this->_hidden_columns = array(); |
|
178 | + } |
|
179 | 179 | |
180 | 180 | |
181 | - /** |
|
182 | - * This simply sets up the row class for the table rows. |
|
183 | - * Allows for easier overriding of child methods for setting up sorting. |
|
184 | - * |
|
185 | - * @param EE_Registration $item the current item |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - protected function _get_row_class($item) |
|
189 | - { |
|
190 | - $class = parent::_get_row_class($item); |
|
191 | - //add status class |
|
192 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
193 | - if ($this->_has_checkbox_column) { |
|
194 | - $class .= ' has-checkbox-column'; |
|
195 | - } |
|
196 | - return $class; |
|
197 | - } |
|
181 | + /** |
|
182 | + * This simply sets up the row class for the table rows. |
|
183 | + * Allows for easier overriding of child methods for setting up sorting. |
|
184 | + * |
|
185 | + * @param EE_Registration $item the current item |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + protected function _get_row_class($item) |
|
189 | + { |
|
190 | + $class = parent::_get_row_class($item); |
|
191 | + //add status class |
|
192 | + $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
193 | + if ($this->_has_checkbox_column) { |
|
194 | + $class .= ' has-checkbox-column'; |
|
195 | + } |
|
196 | + return $class; |
|
197 | + } |
|
198 | 198 | |
199 | 199 | |
200 | - /** |
|
201 | - * Set the $_transaction_details property if not set yet. |
|
202 | - * |
|
203 | - * @param EE_Registration $registration |
|
204 | - * @throws EE_Error |
|
205 | - * @throws InvalidArgumentException |
|
206 | - * @throws ReflectionException |
|
207 | - * @throws InvalidDataTypeException |
|
208 | - * @throws InvalidInterfaceException |
|
209 | - */ |
|
210 | - protected function _set_related_details(EE_Registration $registration) |
|
211 | - { |
|
212 | - $transaction = $registration->get_first_related('Transaction'); |
|
213 | - $status = $transaction instanceof EE_Transaction ? $transaction->status_ID() |
|
214 | - : EEM_Transaction::failed_status_code; |
|
215 | - $this->_transaction_details = array( |
|
216 | - 'transaction' => $transaction, |
|
217 | - 'status' => $status, |
|
218 | - 'id' => $transaction instanceof EE_Transaction ? $transaction->ID() : 0, |
|
219 | - 'title_attr' => sprintf( |
|
220 | - __('View Transaction Details (%s)', 'event_espresso'), |
|
221 | - EEH_Template::pretty_status($status, false, 'sentence') |
|
222 | - ), |
|
223 | - ); |
|
224 | - try { |
|
225 | - $event = $registration->event(); |
|
226 | - } catch (EntityNotFoundException $e) { |
|
227 | - $event = null; |
|
228 | - } |
|
229 | - $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive; |
|
230 | - $this->_event_details = array( |
|
231 | - 'event' => $event, |
|
232 | - 'status' => $status, |
|
233 | - 'id' => $event instanceof EE_Event ? $event->ID() : 0, |
|
234 | - 'title_attr' => sprintf( |
|
235 | - __('Edit Event (%s)', 'event_espresso'), |
|
236 | - EEH_Template::pretty_status($status, false, 'sentence') |
|
237 | - ), |
|
238 | - ); |
|
239 | - } |
|
200 | + /** |
|
201 | + * Set the $_transaction_details property if not set yet. |
|
202 | + * |
|
203 | + * @param EE_Registration $registration |
|
204 | + * @throws EE_Error |
|
205 | + * @throws InvalidArgumentException |
|
206 | + * @throws ReflectionException |
|
207 | + * @throws InvalidDataTypeException |
|
208 | + * @throws InvalidInterfaceException |
|
209 | + */ |
|
210 | + protected function _set_related_details(EE_Registration $registration) |
|
211 | + { |
|
212 | + $transaction = $registration->get_first_related('Transaction'); |
|
213 | + $status = $transaction instanceof EE_Transaction ? $transaction->status_ID() |
|
214 | + : EEM_Transaction::failed_status_code; |
|
215 | + $this->_transaction_details = array( |
|
216 | + 'transaction' => $transaction, |
|
217 | + 'status' => $status, |
|
218 | + 'id' => $transaction instanceof EE_Transaction ? $transaction->ID() : 0, |
|
219 | + 'title_attr' => sprintf( |
|
220 | + __('View Transaction Details (%s)', 'event_espresso'), |
|
221 | + EEH_Template::pretty_status($status, false, 'sentence') |
|
222 | + ), |
|
223 | + ); |
|
224 | + try { |
|
225 | + $event = $registration->event(); |
|
226 | + } catch (EntityNotFoundException $e) { |
|
227 | + $event = null; |
|
228 | + } |
|
229 | + $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive; |
|
230 | + $this->_event_details = array( |
|
231 | + 'event' => $event, |
|
232 | + 'status' => $status, |
|
233 | + 'id' => $event instanceof EE_Event ? $event->ID() : 0, |
|
234 | + 'title_attr' => sprintf( |
|
235 | + __('Edit Event (%s)', 'event_espresso'), |
|
236 | + EEH_Template::pretty_status($status, false, 'sentence') |
|
237 | + ), |
|
238 | + ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | |
242 | - /** |
|
243 | - * _get_table_filters |
|
244 | - * |
|
245 | - * @access protected |
|
246 | - * @return array |
|
247 | - */ |
|
248 | - protected function _get_table_filters() |
|
249 | - { |
|
250 | - $filters = array(); |
|
251 | - //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as |
|
252 | - // methods. |
|
253 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
254 | - $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
255 | - $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : ''; |
|
256 | - $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category); |
|
257 | - $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category); |
|
258 | - $status = array(); |
|
259 | - $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso')); |
|
260 | - foreach ($this->_status as $key => $value) { |
|
261 | - $status[] = array('id' => $key, 'text' => $value); |
|
262 | - } |
|
263 | - if ($this->_view !== 'incomplete') { |
|
264 | - $filters[] = EEH_Form_Fields::select_input( |
|
265 | - '_reg_status', |
|
266 | - $status, |
|
267 | - isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status'])) |
|
268 | - : '' |
|
269 | - ); |
|
270 | - } |
|
271 | - if (isset($this->_req_data['event_id'])) { |
|
272 | - $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id'); |
|
273 | - } |
|
274 | - return $filters; |
|
275 | - } |
|
242 | + /** |
|
243 | + * _get_table_filters |
|
244 | + * |
|
245 | + * @access protected |
|
246 | + * @return array |
|
247 | + */ |
|
248 | + protected function _get_table_filters() |
|
249 | + { |
|
250 | + $filters = array(); |
|
251 | + //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as |
|
252 | + // methods. |
|
253 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
254 | + $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
255 | + $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : ''; |
|
256 | + $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category); |
|
257 | + $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category); |
|
258 | + $status = array(); |
|
259 | + $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso')); |
|
260 | + foreach ($this->_status as $key => $value) { |
|
261 | + $status[] = array('id' => $key, 'text' => $value); |
|
262 | + } |
|
263 | + if ($this->_view !== 'incomplete') { |
|
264 | + $filters[] = EEH_Form_Fields::select_input( |
|
265 | + '_reg_status', |
|
266 | + $status, |
|
267 | + isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status'])) |
|
268 | + : '' |
|
269 | + ); |
|
270 | + } |
|
271 | + if (isset($this->_req_data['event_id'])) { |
|
272 | + $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id'); |
|
273 | + } |
|
274 | + return $filters; |
|
275 | + } |
|
276 | 276 | |
277 | 277 | |
278 | - /** |
|
279 | - * _add_view_counts |
|
280 | - * |
|
281 | - * @access protected |
|
282 | - * @return void |
|
283 | - * @throws EE_Error |
|
284 | - * @throws InvalidArgumentException |
|
285 | - * @throws InvalidDataTypeException |
|
286 | - * @throws InvalidInterfaceException |
|
287 | - */ |
|
288 | - protected function _add_view_counts() |
|
289 | - { |
|
290 | - $this->_views['all']['count'] = $this->_total_registrations(); |
|
291 | - $this->_views['month']['count'] = $this->_total_registrations_this_month(); |
|
292 | - $this->_views['today']['count'] = $this->_total_registrations_today(); |
|
293 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
294 | - 'ee_delete_registrations', |
|
295 | - 'espresso_registrations_trash_registrations' |
|
296 | - )) { |
|
297 | - $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete'); |
|
298 | - $this->_views['trash']['count'] = $this->_total_registrations('trash'); |
|
299 | - } |
|
300 | - } |
|
278 | + /** |
|
279 | + * _add_view_counts |
|
280 | + * |
|
281 | + * @access protected |
|
282 | + * @return void |
|
283 | + * @throws EE_Error |
|
284 | + * @throws InvalidArgumentException |
|
285 | + * @throws InvalidDataTypeException |
|
286 | + * @throws InvalidInterfaceException |
|
287 | + */ |
|
288 | + protected function _add_view_counts() |
|
289 | + { |
|
290 | + $this->_views['all']['count'] = $this->_total_registrations(); |
|
291 | + $this->_views['month']['count'] = $this->_total_registrations_this_month(); |
|
292 | + $this->_views['today']['count'] = $this->_total_registrations_today(); |
|
293 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
294 | + 'ee_delete_registrations', |
|
295 | + 'espresso_registrations_trash_registrations' |
|
296 | + )) { |
|
297 | + $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete'); |
|
298 | + $this->_views['trash']['count'] = $this->_total_registrations('trash'); |
|
299 | + } |
|
300 | + } |
|
301 | 301 | |
302 | 302 | |
303 | - /** |
|
304 | - * _total_registrations |
|
305 | - * |
|
306 | - * @access protected |
|
307 | - * @param string $view |
|
308 | - * @return int |
|
309 | - * @throws EE_Error |
|
310 | - * @throws InvalidArgumentException |
|
311 | - * @throws InvalidDataTypeException |
|
312 | - * @throws InvalidInterfaceException |
|
313 | - */ |
|
314 | - protected function _total_registrations($view = '') |
|
315 | - { |
|
316 | - $_where = array(); |
|
317 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
318 | - if ($EVT_ID) { |
|
319 | - $_where['EVT_ID'] = $EVT_ID; |
|
320 | - } |
|
321 | - switch ($view) { |
|
322 | - case 'trash': |
|
323 | - return EEM_Registration::instance()->count_deleted(array($_where)); |
|
324 | - break; |
|
325 | - case 'incomplete': |
|
326 | - $_where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
327 | - break; |
|
328 | - default: |
|
329 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
330 | - } |
|
331 | - return EEM_Registration::instance()->count(array($_where)); |
|
332 | - } |
|
303 | + /** |
|
304 | + * _total_registrations |
|
305 | + * |
|
306 | + * @access protected |
|
307 | + * @param string $view |
|
308 | + * @return int |
|
309 | + * @throws EE_Error |
|
310 | + * @throws InvalidArgumentException |
|
311 | + * @throws InvalidDataTypeException |
|
312 | + * @throws InvalidInterfaceException |
|
313 | + */ |
|
314 | + protected function _total_registrations($view = '') |
|
315 | + { |
|
316 | + $_where = array(); |
|
317 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
318 | + if ($EVT_ID) { |
|
319 | + $_where['EVT_ID'] = $EVT_ID; |
|
320 | + } |
|
321 | + switch ($view) { |
|
322 | + case 'trash': |
|
323 | + return EEM_Registration::instance()->count_deleted(array($_where)); |
|
324 | + break; |
|
325 | + case 'incomplete': |
|
326 | + $_where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
327 | + break; |
|
328 | + default: |
|
329 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
330 | + } |
|
331 | + return EEM_Registration::instance()->count(array($_where)); |
|
332 | + } |
|
333 | 333 | |
334 | 334 | |
335 | - /** |
|
336 | - * _total_registrations_this_month |
|
337 | - * |
|
338 | - * @access protected |
|
339 | - * @return int |
|
340 | - * @throws EE_Error |
|
341 | - * @throws InvalidArgumentException |
|
342 | - * @throws InvalidDataTypeException |
|
343 | - * @throws InvalidInterfaceException |
|
344 | - */ |
|
345 | - protected function _total_registrations_this_month() |
|
346 | - { |
|
347 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
348 | - $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
349 | - $this_year_r = date('Y', current_time('timestamp')); |
|
350 | - $time_start = ' 00:00:00'; |
|
351 | - $time_end = ' 23:59:59'; |
|
352 | - $this_month_r = date('m', current_time('timestamp')); |
|
353 | - $days_this_month = date('t', current_time('timestamp')); |
|
354 | - //setup date query. |
|
355 | - $beginning_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
356 | - 'REG_date', |
|
357 | - $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
358 | - 'Y-m-d H:i:s' |
|
359 | - ); |
|
360 | - $end_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
361 | - 'REG_date', |
|
362 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
363 | - 'Y-m-d H:i:s' |
|
364 | - ); |
|
365 | - $_where['REG_date'] = array( |
|
366 | - 'BETWEEN', |
|
367 | - array( |
|
368 | - $beginning_string, |
|
369 | - $end_string, |
|
370 | - ), |
|
371 | - ); |
|
372 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
373 | - return EEM_Registration::instance()->count(array($_where)); |
|
374 | - } |
|
335 | + /** |
|
336 | + * _total_registrations_this_month |
|
337 | + * |
|
338 | + * @access protected |
|
339 | + * @return int |
|
340 | + * @throws EE_Error |
|
341 | + * @throws InvalidArgumentException |
|
342 | + * @throws InvalidDataTypeException |
|
343 | + * @throws InvalidInterfaceException |
|
344 | + */ |
|
345 | + protected function _total_registrations_this_month() |
|
346 | + { |
|
347 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
348 | + $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
349 | + $this_year_r = date('Y', current_time('timestamp')); |
|
350 | + $time_start = ' 00:00:00'; |
|
351 | + $time_end = ' 23:59:59'; |
|
352 | + $this_month_r = date('m', current_time('timestamp')); |
|
353 | + $days_this_month = date('t', current_time('timestamp')); |
|
354 | + //setup date query. |
|
355 | + $beginning_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
356 | + 'REG_date', |
|
357 | + $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
358 | + 'Y-m-d H:i:s' |
|
359 | + ); |
|
360 | + $end_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
361 | + 'REG_date', |
|
362 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
363 | + 'Y-m-d H:i:s' |
|
364 | + ); |
|
365 | + $_where['REG_date'] = array( |
|
366 | + 'BETWEEN', |
|
367 | + array( |
|
368 | + $beginning_string, |
|
369 | + $end_string, |
|
370 | + ), |
|
371 | + ); |
|
372 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
373 | + return EEM_Registration::instance()->count(array($_where)); |
|
374 | + } |
|
375 | 375 | |
376 | 376 | |
377 | - /** |
|
378 | - * _total_registrations_today |
|
379 | - * |
|
380 | - * @access protected |
|
381 | - * @return int |
|
382 | - * @throws EE_Error |
|
383 | - * @throws InvalidArgumentException |
|
384 | - * @throws InvalidDataTypeException |
|
385 | - * @throws InvalidInterfaceException |
|
386 | - */ |
|
387 | - protected function _total_registrations_today() |
|
388 | - { |
|
389 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
390 | - $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
391 | - $current_date = date('Y-m-d', current_time('timestamp')); |
|
392 | - $time_start = ' 00:00:00'; |
|
393 | - $time_end = ' 23:59:59'; |
|
394 | - $_where['REG_date'] = array( |
|
395 | - 'BETWEEN', |
|
396 | - array( |
|
397 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
398 | - 'REG_date', |
|
399 | - $current_date . $time_start, |
|
400 | - 'Y-m-d H:i:s' |
|
401 | - ), |
|
402 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
403 | - 'REG_date', |
|
404 | - $current_date . $time_end, |
|
405 | - 'Y-m-d H:i:s' |
|
406 | - ), |
|
407 | - ), |
|
408 | - ); |
|
409 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
410 | - return EEM_Registration::instance()->count(array($_where)); |
|
411 | - } |
|
377 | + /** |
|
378 | + * _total_registrations_today |
|
379 | + * |
|
380 | + * @access protected |
|
381 | + * @return int |
|
382 | + * @throws EE_Error |
|
383 | + * @throws InvalidArgumentException |
|
384 | + * @throws InvalidDataTypeException |
|
385 | + * @throws InvalidInterfaceException |
|
386 | + */ |
|
387 | + protected function _total_registrations_today() |
|
388 | + { |
|
389 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
390 | + $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
391 | + $current_date = date('Y-m-d', current_time('timestamp')); |
|
392 | + $time_start = ' 00:00:00'; |
|
393 | + $time_end = ' 23:59:59'; |
|
394 | + $_where['REG_date'] = array( |
|
395 | + 'BETWEEN', |
|
396 | + array( |
|
397 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
398 | + 'REG_date', |
|
399 | + $current_date . $time_start, |
|
400 | + 'Y-m-d H:i:s' |
|
401 | + ), |
|
402 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
403 | + 'REG_date', |
|
404 | + $current_date . $time_end, |
|
405 | + 'Y-m-d H:i:s' |
|
406 | + ), |
|
407 | + ), |
|
408 | + ); |
|
409 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
410 | + return EEM_Registration::instance()->count(array($_where)); |
|
411 | + } |
|
412 | 412 | |
413 | 413 | |
414 | - /** |
|
415 | - * column_cb |
|
416 | - * |
|
417 | - * @access public |
|
418 | - * @param \EE_Registration $item |
|
419 | - * @return string |
|
420 | - * @throws EE_Error |
|
421 | - * @throws InvalidArgumentException |
|
422 | - * @throws InvalidDataTypeException |
|
423 | - * @throws InvalidInterfaceException |
|
424 | - * @throws ReflectionException |
|
425 | - */ |
|
426 | - public function column_cb($item) |
|
427 | - { |
|
428 | - /** checkbox/lock **/ |
|
429 | - $transaction = $item->get_first_related('Transaction'); |
|
430 | - $payment_count = $transaction instanceof EE_Transaction |
|
431 | - ? $transaction->count_related('Payment') |
|
432 | - : 0; |
|
433 | - return $payment_count > 0 |
|
434 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
435 | - 'ee_edit_registration', |
|
436 | - 'registration_list_table_checkbox_input', |
|
437 | - $item->ID() |
|
438 | - ) |
|
439 | - ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()) |
|
440 | - . '<span class="ee-lock-icon"></span>' |
|
441 | - : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()); |
|
442 | - } |
|
414 | + /** |
|
415 | + * column_cb |
|
416 | + * |
|
417 | + * @access public |
|
418 | + * @param \EE_Registration $item |
|
419 | + * @return string |
|
420 | + * @throws EE_Error |
|
421 | + * @throws InvalidArgumentException |
|
422 | + * @throws InvalidDataTypeException |
|
423 | + * @throws InvalidInterfaceException |
|
424 | + * @throws ReflectionException |
|
425 | + */ |
|
426 | + public function column_cb($item) |
|
427 | + { |
|
428 | + /** checkbox/lock **/ |
|
429 | + $transaction = $item->get_first_related('Transaction'); |
|
430 | + $payment_count = $transaction instanceof EE_Transaction |
|
431 | + ? $transaction->count_related('Payment') |
|
432 | + : 0; |
|
433 | + return $payment_count > 0 |
|
434 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
435 | + 'ee_edit_registration', |
|
436 | + 'registration_list_table_checkbox_input', |
|
437 | + $item->ID() |
|
438 | + ) |
|
439 | + ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()) |
|
440 | + . '<span class="ee-lock-icon"></span>' |
|
441 | + : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()); |
|
442 | + } |
|
443 | 443 | |
444 | 444 | |
445 | - /** |
|
446 | - * column__REG_ID |
|
447 | - * |
|
448 | - * @access public |
|
449 | - * @param \EE_Registration $item |
|
450 | - * @return string |
|
451 | - * @throws EE_Error |
|
452 | - * @throws InvalidArgumentException |
|
453 | - * @throws InvalidDataTypeException |
|
454 | - * @throws InvalidInterfaceException |
|
455 | - * @throws ReflectionException |
|
456 | - */ |
|
457 | - public function column__REG_ID(EE_Registration $item) |
|
458 | - { |
|
459 | - $attendee = $item->attendee(); |
|
460 | - $content = $item->ID(); |
|
461 | - $content .= '<div class="show-on-mobile-view-only">'; |
|
462 | - $content .= '<br>'; |
|
463 | - $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
464 | - $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
465 | - $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
466 | - $content .= '</div>'; |
|
467 | - return $content; |
|
468 | - } |
|
445 | + /** |
|
446 | + * column__REG_ID |
|
447 | + * |
|
448 | + * @access public |
|
449 | + * @param \EE_Registration $item |
|
450 | + * @return string |
|
451 | + * @throws EE_Error |
|
452 | + * @throws InvalidArgumentException |
|
453 | + * @throws InvalidDataTypeException |
|
454 | + * @throws InvalidInterfaceException |
|
455 | + * @throws ReflectionException |
|
456 | + */ |
|
457 | + public function column__REG_ID(EE_Registration $item) |
|
458 | + { |
|
459 | + $attendee = $item->attendee(); |
|
460 | + $content = $item->ID(); |
|
461 | + $content .= '<div class="show-on-mobile-view-only">'; |
|
462 | + $content .= '<br>'; |
|
463 | + $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
464 | + $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
465 | + $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
466 | + $content .= '</div>'; |
|
467 | + return $content; |
|
468 | + } |
|
469 | 469 | |
470 | 470 | |
471 | - /** |
|
472 | - * column__REG_date |
|
473 | - * |
|
474 | - * @access public |
|
475 | - * @param \EE_Registration $item |
|
476 | - * @return string |
|
477 | - * @throws EE_Error |
|
478 | - * @throws InvalidArgumentException |
|
479 | - * @throws InvalidDataTypeException |
|
480 | - * @throws InvalidInterfaceException |
|
481 | - * @throws ReflectionException |
|
482 | - */ |
|
483 | - public function column__REG_date(EE_Registration $item) |
|
484 | - { |
|
485 | - $this->_set_related_details($item); |
|
486 | - //Build row actions |
|
487 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
488 | - 'action' => 'view_transaction', |
|
489 | - 'TXN_ID' => $this->_transaction_details['id'], |
|
490 | - ), TXN_ADMIN_URL); |
|
491 | - $view_link = EE_Registry::instance()->CAP->current_user_can( |
|
492 | - 'ee_read_transaction', |
|
493 | - 'espresso_transactions_view_transaction' |
|
494 | - ) |
|
495 | - ? '<a class="ee-status-color-' |
|
496 | - . $this->_transaction_details['status'] |
|
497 | - . '" href="' |
|
498 | - . $view_lnk_url |
|
499 | - . '" title="' |
|
500 | - . esc_attr($this->_transaction_details['title_attr']) |
|
501 | - . '">' |
|
502 | - . $item->get_i18n_datetime('REG_date') |
|
503 | - . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
504 | - $view_link .= '<br><span class="ee-status-text-small">' |
|
505 | - . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence') |
|
506 | - . '</span>'; |
|
507 | - return $view_link; |
|
508 | - } |
|
471 | + /** |
|
472 | + * column__REG_date |
|
473 | + * |
|
474 | + * @access public |
|
475 | + * @param \EE_Registration $item |
|
476 | + * @return string |
|
477 | + * @throws EE_Error |
|
478 | + * @throws InvalidArgumentException |
|
479 | + * @throws InvalidDataTypeException |
|
480 | + * @throws InvalidInterfaceException |
|
481 | + * @throws ReflectionException |
|
482 | + */ |
|
483 | + public function column__REG_date(EE_Registration $item) |
|
484 | + { |
|
485 | + $this->_set_related_details($item); |
|
486 | + //Build row actions |
|
487 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
488 | + 'action' => 'view_transaction', |
|
489 | + 'TXN_ID' => $this->_transaction_details['id'], |
|
490 | + ), TXN_ADMIN_URL); |
|
491 | + $view_link = EE_Registry::instance()->CAP->current_user_can( |
|
492 | + 'ee_read_transaction', |
|
493 | + 'espresso_transactions_view_transaction' |
|
494 | + ) |
|
495 | + ? '<a class="ee-status-color-' |
|
496 | + . $this->_transaction_details['status'] |
|
497 | + . '" href="' |
|
498 | + . $view_lnk_url |
|
499 | + . '" title="' |
|
500 | + . esc_attr($this->_transaction_details['title_attr']) |
|
501 | + . '">' |
|
502 | + . $item->get_i18n_datetime('REG_date') |
|
503 | + . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
504 | + $view_link .= '<br><span class="ee-status-text-small">' |
|
505 | + . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence') |
|
506 | + . '</span>'; |
|
507 | + return $view_link; |
|
508 | + } |
|
509 | 509 | |
510 | 510 | |
511 | - /** |
|
512 | - * column_event_name |
|
513 | - * |
|
514 | - * @access public |
|
515 | - * @param \EE_Registration $item |
|
516 | - * @return string |
|
517 | - * @throws EE_Error |
|
518 | - * @throws InvalidArgumentException |
|
519 | - * @throws InvalidDataTypeException |
|
520 | - * @throws InvalidInterfaceException |
|
521 | - * @throws ReflectionException |
|
522 | - */ |
|
523 | - public function column_event_name(EE_Registration $item) |
|
524 | - { |
|
525 | - $this->_set_related_details($item); |
|
526 | - // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62 |
|
527 | - $EVT_ID = $item->event_ID(); |
|
528 | - $event_name = $item->event_name(); |
|
529 | - $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso'); |
|
530 | - $event_name = wp_trim_words($event_name, 30, '...'); |
|
531 | - if ($EVT_ID) { |
|
532 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
533 | - array('action' => 'edit', 'post' => $EVT_ID), |
|
534 | - EVENTS_ADMIN_URL |
|
535 | - ); |
|
536 | - $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID) |
|
537 | - ? '<a class="ee-status-color-' |
|
538 | - . $this->_event_details['status'] |
|
539 | - . '" href="' |
|
540 | - . $edit_event_url |
|
541 | - . '" title="' |
|
542 | - . esc_attr($this->_event_details['title_attr']) |
|
543 | - . '">' |
|
544 | - . $event_name |
|
545 | - . '</a>' : $event_name; |
|
546 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
|
547 | - $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
548 | - $actions['event_filter'] .= sprintf( |
|
549 | - esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'), |
|
550 | - $event_name |
|
551 | - ); |
|
552 | - $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
553 | - } else { |
|
554 | - $edit_event = $event_name; |
|
555 | - $actions['event_filter'] = ''; |
|
556 | - } |
|
557 | - return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions)); |
|
558 | - } |
|
511 | + /** |
|
512 | + * column_event_name |
|
513 | + * |
|
514 | + * @access public |
|
515 | + * @param \EE_Registration $item |
|
516 | + * @return string |
|
517 | + * @throws EE_Error |
|
518 | + * @throws InvalidArgumentException |
|
519 | + * @throws InvalidDataTypeException |
|
520 | + * @throws InvalidInterfaceException |
|
521 | + * @throws ReflectionException |
|
522 | + */ |
|
523 | + public function column_event_name(EE_Registration $item) |
|
524 | + { |
|
525 | + $this->_set_related_details($item); |
|
526 | + // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62 |
|
527 | + $EVT_ID = $item->event_ID(); |
|
528 | + $event_name = $item->event_name(); |
|
529 | + $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso'); |
|
530 | + $event_name = wp_trim_words($event_name, 30, '...'); |
|
531 | + if ($EVT_ID) { |
|
532 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
533 | + array('action' => 'edit', 'post' => $EVT_ID), |
|
534 | + EVENTS_ADMIN_URL |
|
535 | + ); |
|
536 | + $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID) |
|
537 | + ? '<a class="ee-status-color-' |
|
538 | + . $this->_event_details['status'] |
|
539 | + . '" href="' |
|
540 | + . $edit_event_url |
|
541 | + . '" title="' |
|
542 | + . esc_attr($this->_event_details['title_attr']) |
|
543 | + . '">' |
|
544 | + . $event_name |
|
545 | + . '</a>' : $event_name; |
|
546 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
|
547 | + $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
548 | + $actions['event_filter'] .= sprintf( |
|
549 | + esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'), |
|
550 | + $event_name |
|
551 | + ); |
|
552 | + $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
553 | + } else { |
|
554 | + $edit_event = $event_name; |
|
555 | + $actions['event_filter'] = ''; |
|
556 | + } |
|
557 | + return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions)); |
|
558 | + } |
|
559 | 559 | |
560 | 560 | |
561 | - /** |
|
562 | - * column_DTT_EVT_start |
|
563 | - * |
|
564 | - * @access public |
|
565 | - * @param \EE_Registration $item |
|
566 | - * @return string |
|
567 | - * @throws EE_Error |
|
568 | - * @throws InvalidArgumentException |
|
569 | - * @throws InvalidDataTypeException |
|
570 | - * @throws InvalidInterfaceException |
|
571 | - * @throws ReflectionException |
|
572 | - */ |
|
573 | - public function column_DTT_EVT_start(EE_Registration $item) |
|
574 | - { |
|
575 | - $datetime_strings = array(); |
|
576 | - $ticket = $item->ticket(true); |
|
577 | - if ($ticket instanceof EE_Ticket) { |
|
578 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
579 | - $datetimes = $ticket->datetimes($remove_defaults); |
|
580 | - foreach ($datetimes as $datetime) { |
|
581 | - $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
582 | - } |
|
583 | - return $this->generateDisplayForDatetimes($datetime_strings); |
|
584 | - } |
|
585 | - return __('There is no ticket on this registration', 'event_espresso'); |
|
586 | - } |
|
561 | + /** |
|
562 | + * column_DTT_EVT_start |
|
563 | + * |
|
564 | + * @access public |
|
565 | + * @param \EE_Registration $item |
|
566 | + * @return string |
|
567 | + * @throws EE_Error |
|
568 | + * @throws InvalidArgumentException |
|
569 | + * @throws InvalidDataTypeException |
|
570 | + * @throws InvalidInterfaceException |
|
571 | + * @throws ReflectionException |
|
572 | + */ |
|
573 | + public function column_DTT_EVT_start(EE_Registration $item) |
|
574 | + { |
|
575 | + $datetime_strings = array(); |
|
576 | + $ticket = $item->ticket(true); |
|
577 | + if ($ticket instanceof EE_Ticket) { |
|
578 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
579 | + $datetimes = $ticket->datetimes($remove_defaults); |
|
580 | + foreach ($datetimes as $datetime) { |
|
581 | + $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
582 | + } |
|
583 | + return $this->generateDisplayForDatetimes($datetime_strings); |
|
584 | + } |
|
585 | + return __('There is no ticket on this registration', 'event_espresso'); |
|
586 | + } |
|
587 | 587 | |
588 | 588 | |
589 | - /** |
|
590 | - * Receives an array of datetime strings to display and converts them to the html container for the column. |
|
591 | - * |
|
592 | - * @param array $datetime_strings |
|
593 | - * @return string |
|
594 | - */ |
|
595 | - public function generateDisplayForDateTimes(array $datetime_strings) |
|
596 | - { |
|
597 | - $content = '<div class="ee-registration-event-datetimes-container">'; |
|
598 | - $expand_toggle = count($datetime_strings) > 1 |
|
599 | - ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso') |
|
600 | - . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>' |
|
601 | - : ''; |
|
602 | - //get first item for initial visibility |
|
603 | - $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>'; |
|
604 | - $content .= $expand_toggle; |
|
605 | - if ($datetime_strings) { |
|
606 | - $content .= '<div style="clear:both"></div>'; |
|
607 | - $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">'; |
|
608 | - $content .= implode("<br />", $datetime_strings); |
|
609 | - $content .= '</div>'; |
|
610 | - } |
|
611 | - $content .= '</div>'; |
|
612 | - return $content; |
|
613 | - } |
|
589 | + /** |
|
590 | + * Receives an array of datetime strings to display and converts them to the html container for the column. |
|
591 | + * |
|
592 | + * @param array $datetime_strings |
|
593 | + * @return string |
|
594 | + */ |
|
595 | + public function generateDisplayForDateTimes(array $datetime_strings) |
|
596 | + { |
|
597 | + $content = '<div class="ee-registration-event-datetimes-container">'; |
|
598 | + $expand_toggle = count($datetime_strings) > 1 |
|
599 | + ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso') |
|
600 | + . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>' |
|
601 | + : ''; |
|
602 | + //get first item for initial visibility |
|
603 | + $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>'; |
|
604 | + $content .= $expand_toggle; |
|
605 | + if ($datetime_strings) { |
|
606 | + $content .= '<div style="clear:both"></div>'; |
|
607 | + $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">'; |
|
608 | + $content .= implode("<br />", $datetime_strings); |
|
609 | + $content .= '</div>'; |
|
610 | + } |
|
611 | + $content .= '</div>'; |
|
612 | + return $content; |
|
613 | + } |
|
614 | 614 | |
615 | 615 | |
616 | - /** |
|
617 | - * column_ATT_fname |
|
618 | - * |
|
619 | - * @access public |
|
620 | - * @param \EE_Registration $item |
|
621 | - * @return string |
|
622 | - * @throws EE_Error |
|
623 | - * @throws InvalidArgumentException |
|
624 | - * @throws InvalidDataTypeException |
|
625 | - * @throws InvalidInterfaceException |
|
626 | - * @throws ReflectionException |
|
627 | - */ |
|
628 | - public function column_ATT_fname(EE_Registration $item) |
|
629 | - { |
|
630 | - $attendee = $item->attendee(); |
|
631 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
632 | - 'action' => 'view_registration', |
|
633 | - '_REG_ID' => $item->ID(), |
|
634 | - ), REG_ADMIN_URL); |
|
635 | - $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
636 | - $link = EE_Registry::instance()->CAP->current_user_can( |
|
637 | - 'ee_read_registration', |
|
638 | - 'espresso_registrations_view_registration', |
|
639 | - $item->ID() |
|
640 | - ) |
|
641 | - ? '<a href="' |
|
642 | - . $edit_lnk_url |
|
643 | - . '" title="' |
|
644 | - . esc_attr__('View Registration Details', 'event_espresso') |
|
645 | - . '">' |
|
646 | - . $attendee_name |
|
647 | - . '</a>' : $attendee_name; |
|
648 | - $link .= $item->count() === 1 |
|
649 | - ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : ''; |
|
650 | - $t = $item->get_first_related('Transaction'); |
|
651 | - $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
|
652 | - //append group count to name |
|
653 | - $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
654 | - //append reg_code |
|
655 | - $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
656 | - //reg status text for accessibility |
|
657 | - $link .= '<br><span class="ee-status-text-small">' |
|
658 | - . EEH_Template::pretty_status($item->status_ID(), false, 'sentence') |
|
659 | - . '</span>'; |
|
660 | - //trash/restore/delete actions |
|
661 | - $actions = array(); |
|
662 | - if ($this->_view !== 'trash' |
|
663 | - && $payment_count === 0 |
|
664 | - && EE_Registry::instance()->CAP->current_user_can( |
|
665 | - 'ee_delete_registration', |
|
666 | - 'espresso_registrations_trash_registrations', |
|
667 | - $item->ID() |
|
668 | - )) { |
|
669 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
670 | - 'action' => 'trash_registrations', |
|
671 | - '_REG_ID' => $item->ID(), |
|
672 | - ), REG_ADMIN_URL); |
|
673 | - $actions['trash'] = '<a href="' |
|
674 | - . $trash_lnk_url |
|
675 | - . '" title="' |
|
676 | - . esc_attr__('Trash Registration', 'event_espresso') |
|
677 | - . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
678 | - } elseif ($this->_view === 'trash') { |
|
679 | - // restore registration link |
|
680 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
681 | - 'ee_delete_registration', |
|
682 | - 'espresso_registrations_restore_registrations', |
|
683 | - $item->ID() |
|
684 | - )) { |
|
685 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
686 | - 'action' => 'restore_registrations', |
|
687 | - '_REG_ID' => $item->ID(), |
|
688 | - ), REG_ADMIN_URL); |
|
689 | - $actions['restore'] = '<a href="' |
|
690 | - . $restore_lnk_url |
|
691 | - . '" title="' |
|
692 | - . esc_attr__('Restore Registration', 'event_espresso') . '">' |
|
693 | - . __('Restore', 'event_espresso') . '</a>'; |
|
694 | - } |
|
695 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
696 | - 'ee_delete_registration', |
|
697 | - 'espresso_registrations_ee_delete_registrations', |
|
698 | - $item->ID() |
|
699 | - )) { |
|
700 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
701 | - 'action' => 'delete_registrations', |
|
702 | - '_REG_ID' => $item->ID(), |
|
703 | - ), REG_ADMIN_URL); |
|
704 | - $actions['delete'] = '<a href="' |
|
705 | - . $delete_lnk_url |
|
706 | - . '" title="' |
|
707 | - . esc_attr__('Delete Registration Permanently', 'event_espresso') |
|
708 | - . '">' |
|
709 | - . __('Delete', 'event_espresso') |
|
710 | - . '</a>'; |
|
711 | - } |
|
712 | - } |
|
713 | - return sprintf('%1$s %2$s', $link, $this->row_actions($actions)); |
|
714 | - } |
|
616 | + /** |
|
617 | + * column_ATT_fname |
|
618 | + * |
|
619 | + * @access public |
|
620 | + * @param \EE_Registration $item |
|
621 | + * @return string |
|
622 | + * @throws EE_Error |
|
623 | + * @throws InvalidArgumentException |
|
624 | + * @throws InvalidDataTypeException |
|
625 | + * @throws InvalidInterfaceException |
|
626 | + * @throws ReflectionException |
|
627 | + */ |
|
628 | + public function column_ATT_fname(EE_Registration $item) |
|
629 | + { |
|
630 | + $attendee = $item->attendee(); |
|
631 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
632 | + 'action' => 'view_registration', |
|
633 | + '_REG_ID' => $item->ID(), |
|
634 | + ), REG_ADMIN_URL); |
|
635 | + $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
636 | + $link = EE_Registry::instance()->CAP->current_user_can( |
|
637 | + 'ee_read_registration', |
|
638 | + 'espresso_registrations_view_registration', |
|
639 | + $item->ID() |
|
640 | + ) |
|
641 | + ? '<a href="' |
|
642 | + . $edit_lnk_url |
|
643 | + . '" title="' |
|
644 | + . esc_attr__('View Registration Details', 'event_espresso') |
|
645 | + . '">' |
|
646 | + . $attendee_name |
|
647 | + . '</a>' : $attendee_name; |
|
648 | + $link .= $item->count() === 1 |
|
649 | + ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : ''; |
|
650 | + $t = $item->get_first_related('Transaction'); |
|
651 | + $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
|
652 | + //append group count to name |
|
653 | + $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
654 | + //append reg_code |
|
655 | + $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
656 | + //reg status text for accessibility |
|
657 | + $link .= '<br><span class="ee-status-text-small">' |
|
658 | + . EEH_Template::pretty_status($item->status_ID(), false, 'sentence') |
|
659 | + . '</span>'; |
|
660 | + //trash/restore/delete actions |
|
661 | + $actions = array(); |
|
662 | + if ($this->_view !== 'trash' |
|
663 | + && $payment_count === 0 |
|
664 | + && EE_Registry::instance()->CAP->current_user_can( |
|
665 | + 'ee_delete_registration', |
|
666 | + 'espresso_registrations_trash_registrations', |
|
667 | + $item->ID() |
|
668 | + )) { |
|
669 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
670 | + 'action' => 'trash_registrations', |
|
671 | + '_REG_ID' => $item->ID(), |
|
672 | + ), REG_ADMIN_URL); |
|
673 | + $actions['trash'] = '<a href="' |
|
674 | + . $trash_lnk_url |
|
675 | + . '" title="' |
|
676 | + . esc_attr__('Trash Registration', 'event_espresso') |
|
677 | + . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
678 | + } elseif ($this->_view === 'trash') { |
|
679 | + // restore registration link |
|
680 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
681 | + 'ee_delete_registration', |
|
682 | + 'espresso_registrations_restore_registrations', |
|
683 | + $item->ID() |
|
684 | + )) { |
|
685 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
686 | + 'action' => 'restore_registrations', |
|
687 | + '_REG_ID' => $item->ID(), |
|
688 | + ), REG_ADMIN_URL); |
|
689 | + $actions['restore'] = '<a href="' |
|
690 | + . $restore_lnk_url |
|
691 | + . '" title="' |
|
692 | + . esc_attr__('Restore Registration', 'event_espresso') . '">' |
|
693 | + . __('Restore', 'event_espresso') . '</a>'; |
|
694 | + } |
|
695 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
696 | + 'ee_delete_registration', |
|
697 | + 'espresso_registrations_ee_delete_registrations', |
|
698 | + $item->ID() |
|
699 | + )) { |
|
700 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
701 | + 'action' => 'delete_registrations', |
|
702 | + '_REG_ID' => $item->ID(), |
|
703 | + ), REG_ADMIN_URL); |
|
704 | + $actions['delete'] = '<a href="' |
|
705 | + . $delete_lnk_url |
|
706 | + . '" title="' |
|
707 | + . esc_attr__('Delete Registration Permanently', 'event_espresso') |
|
708 | + . '">' |
|
709 | + . __('Delete', 'event_espresso') |
|
710 | + . '</a>'; |
|
711 | + } |
|
712 | + } |
|
713 | + return sprintf('%1$s %2$s', $link, $this->row_actions($actions)); |
|
714 | + } |
|
715 | 715 | |
716 | 716 | |
717 | - /** |
|
718 | - * column_ATT_email |
|
719 | - * |
|
720 | - * @access public |
|
721 | - * @param \EE_Registration $item |
|
722 | - * @return string |
|
723 | - * @throws EE_Error |
|
724 | - * @throws InvalidArgumentException |
|
725 | - * @throws InvalidDataTypeException |
|
726 | - * @throws InvalidInterfaceException |
|
727 | - * @throws ReflectionException |
|
728 | - */ |
|
729 | - public function column_ATT_email(EE_Registration $item) |
|
730 | - { |
|
731 | - $attendee = $item->get_first_related('Attendee'); |
|
732 | - return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso') |
|
733 | - : $attendee->email(); |
|
734 | - } |
|
717 | + /** |
|
718 | + * column_ATT_email |
|
719 | + * |
|
720 | + * @access public |
|
721 | + * @param \EE_Registration $item |
|
722 | + * @return string |
|
723 | + * @throws EE_Error |
|
724 | + * @throws InvalidArgumentException |
|
725 | + * @throws InvalidDataTypeException |
|
726 | + * @throws InvalidInterfaceException |
|
727 | + * @throws ReflectionException |
|
728 | + */ |
|
729 | + public function column_ATT_email(EE_Registration $item) |
|
730 | + { |
|
731 | + $attendee = $item->get_first_related('Attendee'); |
|
732 | + return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso') |
|
733 | + : $attendee->email(); |
|
734 | + } |
|
735 | 735 | |
736 | 736 | |
737 | - /** |
|
738 | - * column__REG_count |
|
739 | - * |
|
740 | - * @access public |
|
741 | - * @param \EE_Registration $item |
|
742 | - * @return string |
|
743 | - */ |
|
744 | - public function column__REG_count(EE_Registration $item) |
|
745 | - { |
|
746 | - return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size()); |
|
747 | - } |
|
737 | + /** |
|
738 | + * column__REG_count |
|
739 | + * |
|
740 | + * @access public |
|
741 | + * @param \EE_Registration $item |
|
742 | + * @return string |
|
743 | + */ |
|
744 | + public function column__REG_count(EE_Registration $item) |
|
745 | + { |
|
746 | + return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size()); |
|
747 | + } |
|
748 | 748 | |
749 | 749 | |
750 | - /** |
|
751 | - * column_PRC_amount |
|
752 | - * |
|
753 | - * @access public |
|
754 | - * @param \EE_Registration $item |
|
755 | - * @return string |
|
756 | - * @throws EE_Error |
|
757 | - */ |
|
758 | - public function column_PRC_amount(EE_Registration $item) |
|
759 | - { |
|
760 | - $ticket = $item->ticket(); |
|
761 | - $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">' |
|
762 | - . $ticket->name() |
|
763 | - . '</span><br />' : ''; |
|
764 | - if ($item->final_price() > 0) { |
|
765 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
766 | - } else { |
|
767 | - // free event |
|
768 | - $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
|
769 | - . __('free', 'event_espresso') |
|
770 | - . '</span>'; |
|
771 | - } |
|
772 | - return $content; |
|
773 | - } |
|
750 | + /** |
|
751 | + * column_PRC_amount |
|
752 | + * |
|
753 | + * @access public |
|
754 | + * @param \EE_Registration $item |
|
755 | + * @return string |
|
756 | + * @throws EE_Error |
|
757 | + */ |
|
758 | + public function column_PRC_amount(EE_Registration $item) |
|
759 | + { |
|
760 | + $ticket = $item->ticket(); |
|
761 | + $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">' |
|
762 | + . $ticket->name() |
|
763 | + . '</span><br />' : ''; |
|
764 | + if ($item->final_price() > 0) { |
|
765 | + $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
766 | + } else { |
|
767 | + // free event |
|
768 | + $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
|
769 | + . __('free', 'event_espresso') |
|
770 | + . '</span>'; |
|
771 | + } |
|
772 | + return $content; |
|
773 | + } |
|
774 | 774 | |
775 | 775 | |
776 | - /** |
|
777 | - * column__REG_final_price |
|
778 | - * |
|
779 | - * @access public |
|
780 | - * @param \EE_Registration $item |
|
781 | - * @return string |
|
782 | - * @throws EE_Error |
|
783 | - */ |
|
784 | - public function column__REG_final_price(EE_Registration $item) |
|
785 | - { |
|
786 | - $ticket = $item->ticket(); |
|
787 | - $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket |
|
788 | - ? '' |
|
789 | - : '<span class="TKT_name">' |
|
790 | - . $ticket->name() |
|
791 | - . '</span><br />'; |
|
792 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
793 | - return $content; |
|
794 | - } |
|
776 | + /** |
|
777 | + * column__REG_final_price |
|
778 | + * |
|
779 | + * @access public |
|
780 | + * @param \EE_Registration $item |
|
781 | + * @return string |
|
782 | + * @throws EE_Error |
|
783 | + */ |
|
784 | + public function column__REG_final_price(EE_Registration $item) |
|
785 | + { |
|
786 | + $ticket = $item->ticket(); |
|
787 | + $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket |
|
788 | + ? '' |
|
789 | + : '<span class="TKT_name">' |
|
790 | + . $ticket->name() |
|
791 | + . '</span><br />'; |
|
792 | + $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
793 | + return $content; |
|
794 | + } |
|
795 | 795 | |
796 | 796 | |
797 | - /** |
|
798 | - * column__REG_paid |
|
799 | - * |
|
800 | - * @access public |
|
801 | - * @param \EE_Registration $item |
|
802 | - * @return string |
|
803 | - * @throws EE_Error |
|
804 | - */ |
|
805 | - public function column__REG_paid(EE_Registration $item) |
|
806 | - { |
|
807 | - $payment_method = $item->payment_method(); |
|
808 | - $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
|
809 | - : __('Unknown', 'event_espresso'); |
|
810 | - $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
811 | - if ($item->paid() > 0) { |
|
812 | - $content .= '<br><span class="ee-status-text-small">' |
|
813 | - . sprintf( |
|
814 | - __('...via %s', 'event_espresso'), |
|
815 | - $payment_method_name |
|
816 | - ) |
|
817 | - . '</span>'; |
|
818 | - } |
|
819 | - return $content; |
|
820 | - } |
|
797 | + /** |
|
798 | + * column__REG_paid |
|
799 | + * |
|
800 | + * @access public |
|
801 | + * @param \EE_Registration $item |
|
802 | + * @return string |
|
803 | + * @throws EE_Error |
|
804 | + */ |
|
805 | + public function column__REG_paid(EE_Registration $item) |
|
806 | + { |
|
807 | + $payment_method = $item->payment_method(); |
|
808 | + $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
|
809 | + : __('Unknown', 'event_espresso'); |
|
810 | + $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
811 | + if ($item->paid() > 0) { |
|
812 | + $content .= '<br><span class="ee-status-text-small">' |
|
813 | + . sprintf( |
|
814 | + __('...via %s', 'event_espresso'), |
|
815 | + $payment_method_name |
|
816 | + ) |
|
817 | + . '</span>'; |
|
818 | + } |
|
819 | + return $content; |
|
820 | + } |
|
821 | 821 | |
822 | 822 | |
823 | - /** |
|
824 | - * column_TXN_total |
|
825 | - * |
|
826 | - * @access public |
|
827 | - * @param \EE_Registration $item |
|
828 | - * @return string |
|
829 | - * @throws EE_Error |
|
830 | - * @throws EntityNotFoundException |
|
831 | - * @throws InvalidArgumentException |
|
832 | - * @throws InvalidDataTypeException |
|
833 | - * @throws InvalidInterfaceException |
|
834 | - */ |
|
835 | - public function column_TXN_total(EE_Registration $item) |
|
836 | - { |
|
837 | - if ($item->transaction()) { |
|
838 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
839 | - 'action' => 'view_transaction', |
|
840 | - 'TXN_ID' => $item->transaction_ID(), |
|
841 | - ), TXN_ADMIN_URL); |
|
842 | - return EE_Registry::instance()->CAP->current_user_can( |
|
843 | - 'ee_read_transaction', |
|
844 | - 'espresso_transactions_view_transaction', |
|
845 | - $item->transaction_ID() |
|
846 | - ) |
|
847 | - ? '<span class="reg-pad-rght"><a class="status-' |
|
848 | - . $item->transaction()->status_ID() |
|
849 | - . '" href="' |
|
850 | - . $view_txn_lnk_url |
|
851 | - . '" title="' |
|
852 | - . esc_attr__('View Transaction', 'event_espresso') |
|
853 | - . '">' |
|
854 | - . $item->transaction()->pretty_total() |
|
855 | - . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
856 | - } else { |
|
857 | - return __("None", "event_espresso"); |
|
858 | - } |
|
859 | - } |
|
823 | + /** |
|
824 | + * column_TXN_total |
|
825 | + * |
|
826 | + * @access public |
|
827 | + * @param \EE_Registration $item |
|
828 | + * @return string |
|
829 | + * @throws EE_Error |
|
830 | + * @throws EntityNotFoundException |
|
831 | + * @throws InvalidArgumentException |
|
832 | + * @throws InvalidDataTypeException |
|
833 | + * @throws InvalidInterfaceException |
|
834 | + */ |
|
835 | + public function column_TXN_total(EE_Registration $item) |
|
836 | + { |
|
837 | + if ($item->transaction()) { |
|
838 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
839 | + 'action' => 'view_transaction', |
|
840 | + 'TXN_ID' => $item->transaction_ID(), |
|
841 | + ), TXN_ADMIN_URL); |
|
842 | + return EE_Registry::instance()->CAP->current_user_can( |
|
843 | + 'ee_read_transaction', |
|
844 | + 'espresso_transactions_view_transaction', |
|
845 | + $item->transaction_ID() |
|
846 | + ) |
|
847 | + ? '<span class="reg-pad-rght"><a class="status-' |
|
848 | + . $item->transaction()->status_ID() |
|
849 | + . '" href="' |
|
850 | + . $view_txn_lnk_url |
|
851 | + . '" title="' |
|
852 | + . esc_attr__('View Transaction', 'event_espresso') |
|
853 | + . '">' |
|
854 | + . $item->transaction()->pretty_total() |
|
855 | + . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
856 | + } else { |
|
857 | + return __("None", "event_espresso"); |
|
858 | + } |
|
859 | + } |
|
860 | 860 | |
861 | 861 | |
862 | - /** |
|
863 | - * column_TXN_paid |
|
864 | - * |
|
865 | - * @access public |
|
866 | - * @param \EE_Registration $item |
|
867 | - * @return string |
|
868 | - * @throws EE_Error |
|
869 | - * @throws EntityNotFoundException |
|
870 | - * @throws InvalidArgumentException |
|
871 | - * @throws InvalidDataTypeException |
|
872 | - * @throws InvalidInterfaceException |
|
873 | - */ |
|
874 | - public function column_TXN_paid(EE_Registration $item) |
|
875 | - { |
|
876 | - if ($item->count() === 1) { |
|
877 | - $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance(); |
|
878 | - if ($transaction->paid() >= $transaction->total()) { |
|
879 | - return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
880 | - } else { |
|
881 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
882 | - 'action' => 'view_transaction', |
|
883 | - 'TXN_ID' => $item->transaction_ID(), |
|
884 | - ), TXN_ADMIN_URL); |
|
885 | - return EE_Registry::instance()->CAP->current_user_can( |
|
886 | - 'ee_read_transaction', |
|
887 | - 'espresso_transactions_view_transaction', |
|
888 | - $item->transaction_ID() |
|
889 | - ) |
|
890 | - ? '<span class="reg-pad-rght"><a class="status-' |
|
891 | - . $transaction->status_ID() |
|
892 | - . '" href="' |
|
893 | - . $view_txn_lnk_url |
|
894 | - . '" title="' |
|
895 | - . esc_attr__('View Transaction', 'event_espresso') |
|
896 | - . '">' |
|
897 | - . $item->transaction()->pretty_paid() |
|
898 | - . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
899 | - } |
|
900 | - } |
|
901 | - return ' '; |
|
902 | - } |
|
862 | + /** |
|
863 | + * column_TXN_paid |
|
864 | + * |
|
865 | + * @access public |
|
866 | + * @param \EE_Registration $item |
|
867 | + * @return string |
|
868 | + * @throws EE_Error |
|
869 | + * @throws EntityNotFoundException |
|
870 | + * @throws InvalidArgumentException |
|
871 | + * @throws InvalidDataTypeException |
|
872 | + * @throws InvalidInterfaceException |
|
873 | + */ |
|
874 | + public function column_TXN_paid(EE_Registration $item) |
|
875 | + { |
|
876 | + if ($item->count() === 1) { |
|
877 | + $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance(); |
|
878 | + if ($transaction->paid() >= $transaction->total()) { |
|
879 | + return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
880 | + } else { |
|
881 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
882 | + 'action' => 'view_transaction', |
|
883 | + 'TXN_ID' => $item->transaction_ID(), |
|
884 | + ), TXN_ADMIN_URL); |
|
885 | + return EE_Registry::instance()->CAP->current_user_can( |
|
886 | + 'ee_read_transaction', |
|
887 | + 'espresso_transactions_view_transaction', |
|
888 | + $item->transaction_ID() |
|
889 | + ) |
|
890 | + ? '<span class="reg-pad-rght"><a class="status-' |
|
891 | + . $transaction->status_ID() |
|
892 | + . '" href="' |
|
893 | + . $view_txn_lnk_url |
|
894 | + . '" title="' |
|
895 | + . esc_attr__('View Transaction', 'event_espresso') |
|
896 | + . '">' |
|
897 | + . $item->transaction()->pretty_paid() |
|
898 | + . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
899 | + } |
|
900 | + } |
|
901 | + return ' '; |
|
902 | + } |
|
903 | 903 | |
904 | 904 | |
905 | - /** |
|
906 | - * column_actions |
|
907 | - * |
|
908 | - * @access public |
|
909 | - * @param \EE_Registration $item |
|
910 | - * @return string |
|
911 | - * @throws EE_Error |
|
912 | - * @throws InvalidArgumentException |
|
913 | - * @throws InvalidDataTypeException |
|
914 | - * @throws InvalidInterfaceException |
|
915 | - * @throws ReflectionException |
|
916 | - */ |
|
917 | - public function column_actions(EE_Registration $item) |
|
918 | - { |
|
919 | - $actions = array(); |
|
920 | - $attendee = $item->attendee(); |
|
921 | - $this->_set_related_details($item); |
|
922 | - //Build row actions |
|
923 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
924 | - 'action' => 'view_registration', |
|
925 | - '_REG_ID' => $item->ID(), |
|
926 | - ), REG_ADMIN_URL); |
|
927 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
928 | - 'action' => 'edit_attendee', |
|
929 | - 'post' => $item->attendee_ID(), |
|
930 | - ), REG_ADMIN_URL); |
|
931 | - // page=attendees&event_admin_reports=resend_email®istration_id=43653465634&event_id=2&form_action=resend_email |
|
932 | - //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID ); |
|
933 | - $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
934 | - 'action' => 'resend_registration', |
|
935 | - '_REG_ID' => $item->ID(), |
|
936 | - ), REG_ADMIN_URL, true); |
|
937 | - //Build row actions |
|
938 | - $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
939 | - 'ee_read_registration', |
|
940 | - 'espresso_registrations_view_registration', |
|
941 | - $item->ID() |
|
942 | - ) ? '<li><a href="' |
|
943 | - . $view_lnk_url |
|
944 | - . '" title="' |
|
945 | - . esc_attr__('View Registration Details', 'event_espresso') |
|
946 | - . '" class="tiny-text"> |
|
905 | + /** |
|
906 | + * column_actions |
|
907 | + * |
|
908 | + * @access public |
|
909 | + * @param \EE_Registration $item |
|
910 | + * @return string |
|
911 | + * @throws EE_Error |
|
912 | + * @throws InvalidArgumentException |
|
913 | + * @throws InvalidDataTypeException |
|
914 | + * @throws InvalidInterfaceException |
|
915 | + * @throws ReflectionException |
|
916 | + */ |
|
917 | + public function column_actions(EE_Registration $item) |
|
918 | + { |
|
919 | + $actions = array(); |
|
920 | + $attendee = $item->attendee(); |
|
921 | + $this->_set_related_details($item); |
|
922 | + //Build row actions |
|
923 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
924 | + 'action' => 'view_registration', |
|
925 | + '_REG_ID' => $item->ID(), |
|
926 | + ), REG_ADMIN_URL); |
|
927 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
928 | + 'action' => 'edit_attendee', |
|
929 | + 'post' => $item->attendee_ID(), |
|
930 | + ), REG_ADMIN_URL); |
|
931 | + // page=attendees&event_admin_reports=resend_email®istration_id=43653465634&event_id=2&form_action=resend_email |
|
932 | + //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID ); |
|
933 | + $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
934 | + 'action' => 'resend_registration', |
|
935 | + '_REG_ID' => $item->ID(), |
|
936 | + ), REG_ADMIN_URL, true); |
|
937 | + //Build row actions |
|
938 | + $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
939 | + 'ee_read_registration', |
|
940 | + 'espresso_registrations_view_registration', |
|
941 | + $item->ID() |
|
942 | + ) ? '<li><a href="' |
|
943 | + . $view_lnk_url |
|
944 | + . '" title="' |
|
945 | + . esc_attr__('View Registration Details', 'event_espresso') |
|
946 | + . '" class="tiny-text"> |
|
947 | 947 | <div class="dashicons dashicons-clipboard"></div> |
948 | 948 | </a> |
949 | 949 | </li>' |
950 | - : ''; |
|
951 | - $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
952 | - 'ee_edit_contacts', |
|
953 | - 'espresso_registrations_edit_attendee' |
|
954 | - ) |
|
955 | - && $attendee instanceof EE_Attendee |
|
956 | - ? ' |
|
950 | + : ''; |
|
951 | + $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
952 | + 'ee_edit_contacts', |
|
953 | + 'espresso_registrations_edit_attendee' |
|
954 | + ) |
|
955 | + && $attendee instanceof EE_Attendee |
|
956 | + ? ' |
|
957 | 957 | <li> |
958 | 958 | <a href="' . $edit_lnk_url . '" title="' |
959 | - . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
|
959 | + . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
|
960 | 960 | <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div> |
961 | 961 | </a> |
962 | 962 | </li>' : ''; |
963 | - $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee |
|
964 | - && EE_Registry::instance()->CAP->current_user_can( |
|
965 | - 'ee_send_message', |
|
966 | - 'espresso_registrations_resend_registration', |
|
967 | - $item->ID() |
|
968 | - ) |
|
969 | - ? ' |
|
963 | + $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee |
|
964 | + && EE_Registry::instance()->CAP->current_user_can( |
|
965 | + 'ee_send_message', |
|
966 | + 'espresso_registrations_resend_registration', |
|
967 | + $item->ID() |
|
968 | + ) |
|
969 | + ? ' |
|
970 | 970 | <li> |
971 | 971 | <a href="' |
972 | - . $resend_reg_lnk_url |
|
973 | - . '" title="' |
|
974 | - . esc_attr__('Resend Registration Details', 'event_espresso') |
|
975 | - . '" class="tiny-text"> |
|
972 | + . $resend_reg_lnk_url |
|
973 | + . '" title="' |
|
974 | + . esc_attr__('Resend Registration Details', 'event_espresso') |
|
975 | + . '" class="tiny-text"> |
|
976 | 976 | <div class="dashicons dashicons-email-alt"></div> |
977 | 977 | </a> |
978 | 978 | </li>' : ''; |
979 | - // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb |
|
980 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
981 | - 'action' => 'view_transaction', |
|
982 | - 'TXN_ID' => $this->_transaction_details['id'], |
|
983 | - ), TXN_ADMIN_URL); |
|
984 | - $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
985 | - 'ee_read_transaction', |
|
986 | - 'espresso_transactions_view_transaction', |
|
987 | - $this->_transaction_details['id'] |
|
988 | - ) |
|
989 | - ? ' |
|
979 | + // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb |
|
980 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
981 | + 'action' => 'view_transaction', |
|
982 | + 'TXN_ID' => $this->_transaction_details['id'], |
|
983 | + ), TXN_ADMIN_URL); |
|
984 | + $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
985 | + 'ee_read_transaction', |
|
986 | + 'espresso_transactions_view_transaction', |
|
987 | + $this->_transaction_details['id'] |
|
988 | + ) |
|
989 | + ? ' |
|
990 | 990 | <li> |
991 | 991 | <a class="ee-status-color-' |
992 | - . $this->_transaction_details['status'] |
|
993 | - . ' tiny-text" href="' |
|
994 | - . $view_txn_lnk_url |
|
995 | - . '" title="' |
|
996 | - . $this->_transaction_details['title_attr'] |
|
997 | - . '"> |
|
992 | + . $this->_transaction_details['status'] |
|
993 | + . ' tiny-text" href="' |
|
994 | + . $view_txn_lnk_url |
|
995 | + . '" title="' |
|
996 | + . $this->_transaction_details['title_attr'] |
|
997 | + . '"> |
|
998 | 998 | <div class="dashicons dashicons-cart"></div> |
999 | 999 | </a> |
1000 | 1000 | </li>' : ''; |
1001 | - //invoice link |
|
1002 | - $actions['dl_invoice_lnk'] = ''; |
|
1003 | - $dl_invoice_lnk_url = $item->invoice_url(); |
|
1004 | - //only show invoice link if message type is active. |
|
1005 | - if ($attendee instanceof EE_Attendee |
|
1006 | - && $item->is_primary_registrant() |
|
1007 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
1008 | - ) { |
|
1009 | - $actions['dl_invoice_lnk'] = ' |
|
1001 | + //invoice link |
|
1002 | + $actions['dl_invoice_lnk'] = ''; |
|
1003 | + $dl_invoice_lnk_url = $item->invoice_url(); |
|
1004 | + //only show invoice link if message type is active. |
|
1005 | + if ($attendee instanceof EE_Attendee |
|
1006 | + && $item->is_primary_registrant() |
|
1007 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
1008 | + ) { |
|
1009 | + $actions['dl_invoice_lnk'] = ' |
|
1010 | 1010 | <li> |
1011 | 1011 | <a title="' |
1012 | - . esc_attr__('View Transaction Invoice', 'event_espresso') |
|
1013 | - . '" target="_blank" href="' |
|
1014 | - . $dl_invoice_lnk_url |
|
1015 | - . '" class="tiny-text"> |
|
1012 | + . esc_attr__('View Transaction Invoice', 'event_espresso') |
|
1013 | + . '" target="_blank" href="' |
|
1014 | + . $dl_invoice_lnk_url |
|
1015 | + . '" class="tiny-text"> |
|
1016 | 1016 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
1017 | 1017 | </a> |
1018 | 1018 | </li>'; |
1019 | - } |
|
1020 | - $actions['filtered_messages_link'] = ''; |
|
1021 | - //message list table link (filtered by REG_ID |
|
1022 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
1023 | - $actions['filtered_messages_link'] = '<li>' |
|
1024 | - . EEH_MSG_Template::get_message_action_link( |
|
1025 | - 'see_notifications_for', |
|
1026 | - null, |
|
1027 | - array('_REG_ID' => $item->ID()) |
|
1028 | - ) . '</li>'; |
|
1029 | - } |
|
1030 | - $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
|
1031 | - return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
|
1032 | - } |
|
1019 | + } |
|
1020 | + $actions['filtered_messages_link'] = ''; |
|
1021 | + //message list table link (filtered by REG_ID |
|
1022 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
1023 | + $actions['filtered_messages_link'] = '<li>' |
|
1024 | + . EEH_MSG_Template::get_message_action_link( |
|
1025 | + 'see_notifications_for', |
|
1026 | + null, |
|
1027 | + array('_REG_ID' => $item->ID()) |
|
1028 | + ) . '</li>'; |
|
1029 | + } |
|
1030 | + $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
|
1031 | + return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
|
1032 | + } |
|
1033 | 1033 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
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 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct(Registrations_Admin_Page $admin_page) |
59 | 59 | { |
60 | - if (! empty($_GET['event_id'])) { |
|
60 | + if ( ! empty($_GET['event_id'])) { |
|
61 | 61 | $extra_query_args = array(); |
62 | 62 | foreach ($admin_page->get_views() as $key => $view_details) { |
63 | 63 | $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | ); |
158 | 158 | $this->_primary_column = '_REG_ID'; |
159 | 159 | $this->_sortable_columns = array( |
160 | - '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
160 | + '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
161 | 161 | /** |
162 | 162 | * Allows users to change the default sort if they wish. |
163 | 163 | * Returning a falsey on this filter will result in the default sort to be by firstname rather than last |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | { |
190 | 190 | $class = parent::_get_row_class($item); |
191 | 191 | //add status class |
192 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
192 | + $class .= ' ee-status-strip reg-status-'.$item->status_ID(); |
|
193 | 193 | if ($this->_has_checkbox_column) { |
194 | 194 | $class .= ' has-checkbox-column'; |
195 | 195 | } |
@@ -354,12 +354,12 @@ discard block |
||
354 | 354 | //setup date query. |
355 | 355 | $beginning_string = EEM_Registration::instance()->convert_datetime_for_query( |
356 | 356 | 'REG_date', |
357 | - $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
357 | + $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start, |
|
358 | 358 | 'Y-m-d H:i:s' |
359 | 359 | ); |
360 | 360 | $end_string = EEM_Registration::instance()->convert_datetime_for_query( |
361 | 361 | 'REG_date', |
362 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
362 | + $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end, |
|
363 | 363 | 'Y-m-d H:i:s' |
364 | 364 | ); |
365 | 365 | $_where['REG_date'] = array( |
@@ -396,12 +396,12 @@ discard block |
||
396 | 396 | array( |
397 | 397 | EEM_Registration::instance()->convert_datetime_for_query( |
398 | 398 | 'REG_date', |
399 | - $current_date . $time_start, |
|
399 | + $current_date.$time_start, |
|
400 | 400 | 'Y-m-d H:i:s' |
401 | 401 | ), |
402 | 402 | EEM_Registration::instance()->convert_datetime_for_query( |
403 | 403 | 'REG_date', |
404 | - $current_date . $time_end, |
|
404 | + $current_date.$time_end, |
|
405 | 405 | 'Y-m-d H:i:s' |
406 | 406 | ), |
407 | 407 | ), |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | $content .= '<div class="show-on-mobile-view-only">'; |
462 | 462 | $content .= '<br>'; |
463 | 463 | $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
464 | - $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
465 | - $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
464 | + $content .= ' '.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
465 | + $content .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
466 | 466 | $content .= '</div>'; |
467 | 467 | return $content; |
468 | 468 | } |
@@ -544,12 +544,12 @@ discard block |
||
544 | 544 | . $event_name |
545 | 545 | . '</a>' : $event_name; |
546 | 546 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
547 | - $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
547 | + $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="'; |
|
548 | 548 | $actions['event_filter'] .= sprintf( |
549 | 549 | esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'), |
550 | 550 | $event_name |
551 | 551 | ); |
552 | - $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
552 | + $actions['event_filter'] .= '">'.__('View Registrations', 'event_espresso').'</a>'; |
|
553 | 553 | } else { |
554 | 554 | $edit_event = $event_name; |
555 | 555 | $actions['event_filter'] = ''; |
@@ -596,11 +596,11 @@ discard block |
||
596 | 596 | { |
597 | 597 | $content = '<div class="ee-registration-event-datetimes-container">'; |
598 | 598 | $expand_toggle = count($datetime_strings) > 1 |
599 | - ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso') |
|
599 | + ? ' <span title="'.esc_attr__('Click to view all dates', 'event_espresso') |
|
600 | 600 | . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>' |
601 | 601 | : ''; |
602 | 602 | //get first item for initial visibility |
603 | - $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>'; |
|
603 | + $content .= '<div class="left">'.array_shift($datetime_strings).'</div>'; |
|
604 | 604 | $content .= $expand_toggle; |
605 | 605 | if ($datetime_strings) { |
606 | 606 | $content .= '<div style="clear:both"></div>'; |
@@ -650,9 +650,9 @@ discard block |
||
650 | 650 | $t = $item->get_first_related('Transaction'); |
651 | 651 | $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
652 | 652 | //append group count to name |
653 | - $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
653 | + $link .= ' '.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
654 | 654 | //append reg_code |
655 | - $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
655 | + $link .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
656 | 656 | //reg status text for accessibility |
657 | 657 | $link .= '<br><span class="ee-status-text-small">' |
658 | 658 | . EEH_Template::pretty_status($item->status_ID(), false, 'sentence') |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | . $trash_lnk_url |
675 | 675 | . '" title="' |
676 | 676 | . esc_attr__('Trash Registration', 'event_espresso') |
677 | - . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
677 | + . '">'.__('Trash', 'event_espresso').'</a>'; |
|
678 | 678 | } elseif ($this->_view === 'trash') { |
679 | 679 | // restore registration link |
680 | 680 | if (EE_Registry::instance()->CAP->current_user_can( |
@@ -689,8 +689,8 @@ discard block |
||
689 | 689 | $actions['restore'] = '<a href="' |
690 | 690 | . $restore_lnk_url |
691 | 691 | . '" title="' |
692 | - . esc_attr__('Restore Registration', 'event_espresso') . '">' |
|
693 | - . __('Restore', 'event_espresso') . '</a>'; |
|
692 | + . esc_attr__('Restore Registration', 'event_espresso').'">' |
|
693 | + . __('Restore', 'event_espresso').'</a>'; |
|
694 | 694 | } |
695 | 695 | if (EE_Registry::instance()->CAP->current_user_can( |
696 | 696 | 'ee_delete_registration', |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | . $ticket->name() |
763 | 763 | . '</span><br />' : ''; |
764 | 764 | if ($item->final_price() > 0) { |
765 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
765 | + $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>'; |
|
766 | 766 | } else { |
767 | 767 | // free event |
768 | 768 | $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
@@ -789,7 +789,7 @@ discard block |
||
789 | 789 | : '<span class="TKT_name">' |
790 | 790 | . $ticket->name() |
791 | 791 | . '</span><br />'; |
792 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
792 | + $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>'; |
|
793 | 793 | return $content; |
794 | 794 | } |
795 | 795 | |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | $payment_method = $item->payment_method(); |
808 | 808 | $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
809 | 809 | : __('Unknown', 'event_espresso'); |
810 | - $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
810 | + $content = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>'; |
|
811 | 811 | if ($item->paid() > 0) { |
812 | 812 | $content .= '<br><span class="ee-status-text-small">' |
813 | 813 | . sprintf( |
@@ -852,7 +852,7 @@ discard block |
||
852 | 852 | . esc_attr__('View Transaction', 'event_espresso') |
853 | 853 | . '">' |
854 | 854 | . $item->transaction()->pretty_total() |
855 | - . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
855 | + . '</a></span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>'; |
|
856 | 856 | } else { |
857 | 857 | return __("None", "event_espresso"); |
858 | 858 | } |
@@ -895,7 +895,7 @@ discard block |
||
895 | 895 | . esc_attr__('View Transaction', 'event_espresso') |
896 | 896 | . '">' |
897 | 897 | . $item->transaction()->pretty_paid() |
898 | - . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
898 | + . '</a><span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>'; |
|
899 | 899 | } |
900 | 900 | } |
901 | 901 | return ' '; |
@@ -955,8 +955,8 @@ discard block |
||
955 | 955 | && $attendee instanceof EE_Attendee |
956 | 956 | ? ' |
957 | 957 | <li> |
958 | - <a href="' . $edit_lnk_url . '" title="' |
|
959 | - . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
|
958 | + <a href="' . $edit_lnk_url.'" title="' |
|
959 | + . esc_attr__('Edit Contact Details', 'event_espresso').'" class="tiny-text"> |
|
960 | 960 | <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div> |
961 | 961 | </a> |
962 | 962 | </li>' : ''; |
@@ -1025,7 +1025,7 @@ discard block |
||
1025 | 1025 | 'see_notifications_for', |
1026 | 1026 | null, |
1027 | 1027 | array('_REG_ID' => $item->ID()) |
1028 | - ) . '</li>'; |
|
1028 | + ).'</li>'; |
|
1029 | 1029 | } |
1030 | 1030 | $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
1031 | 1031 | return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
@@ -8,644 +8,644 @@ |
||
8 | 8 | class EE_Email_messenger extends EE_messenger |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * To field for email |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $_to = ''; |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - * CC field for email. |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $_cc = ''; |
|
23 | - |
|
24 | - /** |
|
25 | - * From field for email |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $_from = ''; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * Subject field for email |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $_subject = ''; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Content field for email |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $_content = ''; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * constructor |
|
47 | - * |
|
48 | - * @access public |
|
49 | - */ |
|
50 | - public function __construct() |
|
51 | - { |
|
52 | - //set name and description properties |
|
53 | - $this->name = 'email'; |
|
54 | - $this->description = sprintf( |
|
55 | - esc_html__( |
|
56 | - 'This messenger delivers messages via email using the built-in %s function included with WordPress', |
|
57 | - 'event_espresso' |
|
58 | - ), |
|
59 | - '<code>wp_mail</code>' |
|
60 | - ); |
|
61 | - $this->label = array( |
|
62 | - 'singular' => esc_html__('email', 'event_espresso'), |
|
63 | - 'plural' => esc_html__('emails', 'event_espresso'), |
|
64 | - ); |
|
65 | - $this->activate_on_install = true; |
|
66 | - |
|
67 | - //we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
68 | - // properties |
|
69 | - parent::__construct(); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * see abstract declaration in parent class for details. |
|
75 | - */ |
|
76 | - protected function _set_admin_pages() |
|
77 | - { |
|
78 | - $this->admin_registered_pages = array( |
|
79 | - 'events_edit' => true, |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * see abstract declaration in parent class for details |
|
86 | - */ |
|
87 | - protected function _set_valid_shortcodes() |
|
88 | - { |
|
89 | - //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
90 | - // message type. |
|
91 | - $this->_valid_shortcodes = array( |
|
92 | - 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
93 | - 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
94 | - 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * see abstract declaration in parent class for details |
|
101 | - * |
|
102 | - * @access protected |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - protected function _set_validator_config() |
|
106 | - { |
|
107 | - $valid_shortcodes = $this->get_valid_shortcodes(); |
|
108 | - |
|
109 | - $this->_validator_config = array( |
|
110 | - 'to' => array( |
|
111 | - 'shortcodes' => $valid_shortcodes['to'], |
|
112 | - 'type' => 'email', |
|
113 | - ), |
|
114 | - 'cc' => array( |
|
115 | - 'shortcodes' => $valid_shortcodes['to'], |
|
116 | - 'type' => 'email', |
|
117 | - ), |
|
118 | - 'from' => array( |
|
119 | - 'shortcodes' => $valid_shortcodes['from'], |
|
120 | - 'type' => 'email', |
|
121 | - ), |
|
122 | - 'subject' => array( |
|
123 | - 'shortcodes' => array( |
|
124 | - 'organization', |
|
125 | - 'primary_registration_details', |
|
126 | - 'event_author', |
|
127 | - 'primary_registration_details', |
|
128 | - 'recipient_details', |
|
129 | - ), |
|
130 | - ), |
|
131 | - 'content' => array( |
|
132 | - 'shortcodes' => array( |
|
133 | - 'event_list', |
|
134 | - 'attendee_list', |
|
135 | - 'ticket_list', |
|
136 | - 'organization', |
|
137 | - 'primary_registration_details', |
|
138 | - 'primary_registration_list', |
|
139 | - 'event_author', |
|
140 | - 'recipient_details', |
|
141 | - 'recipient_list', |
|
142 | - 'transaction', |
|
143 | - 'messenger', |
|
144 | - ), |
|
145 | - ), |
|
146 | - 'attendee_list' => array( |
|
147 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
148 | - 'required' => array('[ATTENDEE_LIST]'), |
|
149 | - ), |
|
150 | - 'event_list' => array( |
|
151 | - 'shortcodes' => array( |
|
152 | - 'event', |
|
153 | - 'attendee_list', |
|
154 | - 'ticket_list', |
|
155 | - 'venue', |
|
156 | - 'datetime_list', |
|
157 | - 'attendee', |
|
158 | - 'primary_registration_details', |
|
159 | - 'primary_registration_list', |
|
160 | - 'event_author', |
|
161 | - 'recipient_details', |
|
162 | - 'recipient_list', |
|
163 | - ), |
|
164 | - 'required' => array('[EVENT_LIST]'), |
|
165 | - ), |
|
166 | - 'ticket_list' => array( |
|
167 | - 'shortcodes' => array( |
|
168 | - 'event_list', |
|
169 | - 'attendee_list', |
|
170 | - 'ticket', |
|
171 | - 'datetime_list', |
|
172 | - 'primary_registration_details', |
|
173 | - 'recipient_details', |
|
174 | - ), |
|
175 | - 'required' => array('[TICKET_LIST]'), |
|
176 | - ), |
|
177 | - 'datetime_list' => array( |
|
178 | - 'shortcodes' => array('datetime'), |
|
179 | - 'required' => array('[DATETIME_LIST]'), |
|
180 | - ), |
|
181 | - ); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @see parent EE_messenger class for docs |
|
187 | - * @since 4.5.0 |
|
188 | - */ |
|
189 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
190 | - { |
|
191 | - if ($sending_messenger_name = 'html') { |
|
192 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - public function add_email_css( |
|
198 | - $variation_path, |
|
199 | - $messenger, |
|
200 | - $message_type, |
|
201 | - $type, |
|
202 | - $variation, |
|
203 | - $file_extension, |
|
204 | - $url, |
|
205 | - EE_Messages_Template_Pack $template_pack |
|
206 | - ) { |
|
207 | - //prevent recursion on this callback. |
|
208 | - remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
209 | - $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
210 | - |
|
211 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
212 | - return $variation; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * See parent for details |
|
218 | - * |
|
219 | - * @access protected |
|
220 | - * @return void |
|
221 | - */ |
|
222 | - protected function _set_test_settings_fields() |
|
223 | - { |
|
224 | - $this->_test_settings_fields = array( |
|
225 | - 'to' => array( |
|
226 | - 'input' => 'text', |
|
227 | - 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
228 | - 'type' => 'email', |
|
229 | - 'required' => true, |
|
230 | - 'validation' => true, |
|
231 | - 'css_class' => 'large-text', |
|
232 | - 'format' => '%s', |
|
233 | - 'default' => get_bloginfo('admin_email'), |
|
234 | - ), |
|
235 | - 'subject' => array( |
|
236 | - 'input' => 'hidden', |
|
237 | - 'label' => '', |
|
238 | - 'type' => 'string', |
|
239 | - 'required' => false, |
|
240 | - 'validation' => false, |
|
241 | - 'format' => '%s', |
|
242 | - 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
243 | - 'default' => '', |
|
244 | - 'css_class' => '', |
|
245 | - ), |
|
246 | - ); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * _set_template_fields |
|
252 | - * This sets up the fields that a messenger requires for the message to go out. |
|
253 | - * |
|
254 | - * @access protected |
|
255 | - * @return void |
|
256 | - */ |
|
257 | - protected function _set_template_fields() |
|
258 | - { |
|
259 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
260 | - // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
261 | - // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
262 | - // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
263 | - // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
264 | - // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
265 | - // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
266 | - // will not be displayed/parsed. |
|
267 | - $this->_template_fields = array( |
|
268 | - 'to' => array( |
|
269 | - 'input' => 'text', |
|
270 | - 'label' => esc_html_x( |
|
271 | - 'To', |
|
272 | - 'Label for the "To" field for email addresses', |
|
273 | - 'event_espresso' |
|
274 | - ), |
|
275 | - 'type' => 'string', |
|
276 | - 'required' => true, |
|
277 | - 'validation' => true, |
|
278 | - 'css_class' => 'large-text', |
|
279 | - 'format' => '%s', |
|
280 | - ), |
|
281 | - 'cc' => array( |
|
282 | - 'input' => 'text', |
|
283 | - 'label' => esc_html_x( |
|
284 | - 'CC', |
|
285 | - 'Label for the "Carbon Copy" field used for additional email addresses', |
|
286 | - 'event_espresso' |
|
287 | - ), |
|
288 | - 'type' => 'string', |
|
289 | - 'required' => false, |
|
290 | - 'validation' => true, |
|
291 | - 'css_class' => 'large-text', |
|
292 | - 'format' => '%s', |
|
293 | - ), |
|
294 | - 'from' => array( |
|
295 | - 'input' => 'text', |
|
296 | - 'label' => esc_html_x( |
|
297 | - 'From', |
|
298 | - 'Label for the "From" field for email addresses.', |
|
299 | - 'event_espresso' |
|
300 | - ), |
|
301 | - 'type' => 'string', |
|
302 | - 'required' => true, |
|
303 | - 'validation' => true, |
|
304 | - 'css_class' => 'large-text', |
|
305 | - 'format' => '%s', |
|
306 | - ), |
|
307 | - 'subject' => array( |
|
308 | - 'input' => 'text', |
|
309 | - 'label' => esc_html_x( |
|
310 | - 'Subject', |
|
311 | - 'Label for the "Subject" field (short description of contents) for emails.', |
|
312 | - 'event_espresso' |
|
313 | - ), |
|
314 | - 'type' => 'string', |
|
315 | - 'required' => true, |
|
316 | - 'validation' => true, |
|
317 | - 'css_class' => 'large-text', |
|
318 | - 'format' => '%s', |
|
319 | - ), |
|
320 | - 'content' => '', |
|
321 | - //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
322 | - 'extra' => array( |
|
323 | - 'content' => array( |
|
324 | - 'main' => array( |
|
325 | - 'input' => 'wp_editor', |
|
326 | - 'label' => esc_html__('Main Content', 'event_espresso'), |
|
327 | - 'type' => 'string', |
|
328 | - 'required' => true, |
|
329 | - 'validation' => true, |
|
330 | - 'format' => '%s', |
|
331 | - 'rows' => '15', |
|
332 | - ), |
|
333 | - 'event_list' => array( |
|
334 | - 'input' => 'wp_editor', |
|
335 | - 'label' => '[EVENT_LIST]', |
|
336 | - 'type' => 'string', |
|
337 | - 'required' => true, |
|
338 | - 'validation' => true, |
|
339 | - 'format' => '%s', |
|
340 | - 'rows' => '15', |
|
341 | - 'shortcodes_required' => array('[EVENT_LIST]'), |
|
342 | - ), |
|
343 | - 'attendee_list' => array( |
|
344 | - 'input' => 'textarea', |
|
345 | - 'label' => '[ATTENDEE_LIST]', |
|
346 | - 'type' => 'string', |
|
347 | - 'required' => true, |
|
348 | - 'validation' => true, |
|
349 | - 'format' => '%s', |
|
350 | - 'css_class' => 'large-text', |
|
351 | - 'rows' => '5', |
|
352 | - 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
353 | - ), |
|
354 | - 'ticket_list' => array( |
|
355 | - 'input' => 'textarea', |
|
356 | - 'label' => '[TICKET_LIST]', |
|
357 | - 'type' => 'string', |
|
358 | - 'required' => true, |
|
359 | - 'validation' => true, |
|
360 | - 'format' => '%s', |
|
361 | - 'css_class' => 'large-text', |
|
362 | - 'rows' => '10', |
|
363 | - 'shortcodes_required' => array('[TICKET_LIST]'), |
|
364 | - ), |
|
365 | - 'datetime_list' => array( |
|
366 | - 'input' => 'textarea', |
|
367 | - 'label' => '[DATETIME_LIST]', |
|
368 | - 'type' => 'string', |
|
369 | - 'required' => true, |
|
370 | - 'validation' => true, |
|
371 | - 'format' => '%s', |
|
372 | - 'css_class' => 'large-text', |
|
373 | - 'rows' => '10', |
|
374 | - 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
375 | - ), |
|
376 | - ), |
|
377 | - ), |
|
378 | - ); |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * See definition of this class in parent |
|
384 | - */ |
|
385 | - protected function _set_default_message_types() |
|
386 | - { |
|
387 | - $this->_default_message_types = array( |
|
388 | - 'payment', |
|
389 | - 'payment_refund', |
|
390 | - 'registration', |
|
391 | - 'not_approved_registration', |
|
392 | - 'pending_approval', |
|
393 | - ); |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * @see definition of this class in parent |
|
399 | - * @since 4.5.0 |
|
400 | - */ |
|
401 | - protected function _set_valid_message_types() |
|
402 | - { |
|
403 | - $this->_valid_message_types = array( |
|
404 | - 'payment', |
|
405 | - 'registration', |
|
406 | - 'not_approved_registration', |
|
407 | - 'declined_registration', |
|
408 | - 'cancelled_registration', |
|
409 | - 'pending_approval', |
|
410 | - 'registration_summary', |
|
411 | - 'payment_reminder', |
|
412 | - 'payment_declined', |
|
413 | - 'payment_refund', |
|
414 | - ); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * setting up admin_settings_fields for messenger. |
|
420 | - */ |
|
421 | - protected function _set_admin_settings_fields() |
|
422 | - { |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * We just deliver the messages don't kill us!! |
|
427 | - * |
|
428 | - * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
429 | - * present. |
|
430 | - * @throws EE_Error |
|
431 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
432 | - */ |
|
433 | - protected function _send_message() |
|
434 | - { |
|
435 | - $success = wp_mail( |
|
436 | - $this->_to, |
|
437 | - //some old values for subject may be expecting HTML entities to be decoded in the subject |
|
438 | - //and subjects aren't interpreted as HTML, so there should be no HTML in them |
|
439 | - wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)), |
|
440 | - $this->_body(), |
|
441 | - $this->_headers() |
|
442 | - ); |
|
443 | - if (! $success) { |
|
444 | - EE_Error::add_error( |
|
445 | - sprintf( |
|
446 | - esc_html__( |
|
447 | - 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
448 | - 'event_espresso' |
|
449 | - ), |
|
450 | - $this->_to, |
|
451 | - $this->_from, |
|
452 | - '<br />' |
|
453 | - ), |
|
454 | - __FILE__, |
|
455 | - __FUNCTION__, |
|
456 | - __LINE__ |
|
457 | - ); |
|
458 | - } |
|
459 | - return $success; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * see parent for definition |
|
465 | - * |
|
466 | - * @return string html body of the message content and the related css. |
|
467 | - * @throws EE_Error |
|
468 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
469 | - */ |
|
470 | - protected function _preview() |
|
471 | - { |
|
472 | - return $this->_body(true); |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * Setup headers for email |
|
478 | - * |
|
479 | - * @access protected |
|
480 | - * @return string formatted header for email |
|
481 | - */ |
|
482 | - protected function _headers() |
|
483 | - { |
|
484 | - $this->_ensure_has_from_email_address(); |
|
485 | - $from = $this->_from; |
|
486 | - $headers = array( |
|
487 | - 'From:' . $from, |
|
488 | - 'Reply-To:' . $from, |
|
489 | - 'Content-Type:text/html; charset=utf-8', |
|
490 | - ); |
|
491 | - |
|
492 | - if (! empty($this->_cc)) { |
|
493 | - $headers[] = 'cc: ' . $this->_cc; |
|
494 | - } |
|
495 | - |
|
496 | - //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
497 | - // header. |
|
498 | - add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
499 | - add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
500 | - return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
506 | - * address for the from address to avoid problems with sending emails. |
|
507 | - */ |
|
508 | - protected function _ensure_has_from_email_address() |
|
509 | - { |
|
510 | - if (empty($this->_from)) { |
|
511 | - $this->_from = get_bloginfo('admin_email'); |
|
512 | - } |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
518 | - * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
519 | - * be empty |
|
520 | - * |
|
521 | - * @since 4.3.1 |
|
522 | - * @return array |
|
523 | - */ |
|
524 | - private function _parse_from() |
|
525 | - { |
|
526 | - if (strpos($this->_from, '<') !== false) { |
|
527 | - $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
528 | - $from_name = str_replace('"', '', $from_name); |
|
529 | - $from_name = trim($from_name); |
|
530 | - |
|
531 | - $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
532 | - $from_email = str_replace('>', '', $from_email); |
|
533 | - $from_email = trim($from_email); |
|
534 | - } elseif (trim($this->_from) !== '') { |
|
535 | - $from_name = ''; |
|
536 | - $from_email = trim($this->_from); |
|
537 | - } else { |
|
538 | - $from_name = $from_email = ''; |
|
539 | - } |
|
540 | - return array($from_name, $from_email); |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * Callback for the wp_mail_from filter. |
|
546 | - * |
|
547 | - * @since 4.3.1 |
|
548 | - * @param string $from_email What the original from_email is. |
|
549 | - * @return string |
|
550 | - */ |
|
551 | - public function set_from_address($from_email) |
|
552 | - { |
|
553 | - $parsed_from = $this->_parse_from(); |
|
554 | - //includes fallback if the parsing failed. |
|
555 | - $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
556 | - ? $parsed_from[1] |
|
557 | - : get_bloginfo('admin_email'); |
|
558 | - return $from_email; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * Callback fro the wp_mail_from_name filter. |
|
564 | - * |
|
565 | - * @since 4.3.1 |
|
566 | - * @param string $from_name The original from_name. |
|
567 | - * @return string |
|
568 | - */ |
|
569 | - public function set_from_name($from_name) |
|
570 | - { |
|
571 | - $parsed_from = $this->_parse_from(); |
|
572 | - if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
573 | - $from_name = $parsed_from[0]; |
|
574 | - } |
|
575 | - |
|
576 | - //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
577 | - //but realize the default name is HTML entity-encoded |
|
578 | - $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name; |
|
579 | - |
|
580 | - return $from_name; |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * setup body for email |
|
586 | - * |
|
587 | - * @param bool $preview will determine whether this is preview template or not. |
|
588 | - * @return string formatted body for email. |
|
589 | - * @throws EE_Error |
|
590 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
591 | - */ |
|
592 | - protected function _body($preview = false) |
|
593 | - { |
|
594 | - //setup template args! |
|
595 | - $this->_template_args = array( |
|
596 | - 'subject' => $this->_subject, |
|
597 | - 'from' => $this->_from, |
|
598 | - 'main_body' => wpautop($this->_content), |
|
599 | - ); |
|
600 | - $body = $this->_get_main_template($preview); |
|
601 | - |
|
602 | - /** |
|
603 | - * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
604 | - * |
|
605 | - * @type bool $preview Indicates whether a preview is being generated or not. |
|
606 | - * @return bool true indicates to use the inliner, false bypasses it. |
|
607 | - */ |
|
608 | - if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
609 | - //require CssToInlineStyles library and its dependencies via composer autoloader |
|
610 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
611 | - |
|
612 | - //now if this isn't a preview, let's setup the body so it has inline styles |
|
613 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
614 | - $style = file_get_contents( |
|
615 | - $this->get_variation( |
|
616 | - $this->_tmp_pack, |
|
617 | - $this->_incoming_message_type->name, |
|
618 | - false, |
|
619 | - 'main', |
|
620 | - $this->_variation |
|
621 | - ), |
|
622 | - true |
|
623 | - ); |
|
624 | - $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
625 | - //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
626 | - $body = ltrim($CSS->convert(true), ">\n"); |
|
627 | - //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
628 | - $body = ltrim($body, "<?"); |
|
629 | - } |
|
630 | - |
|
631 | - } |
|
632 | - return $body; |
|
633 | - } |
|
634 | - |
|
635 | - |
|
636 | - /** |
|
637 | - * This just returns any existing test settings that might be saved in the database |
|
638 | - * |
|
639 | - * @access public |
|
640 | - * @return array |
|
641 | - */ |
|
642 | - public function get_existing_test_settings() |
|
643 | - { |
|
644 | - $settings = parent::get_existing_test_settings(); |
|
645 | - //override subject if present because we always want it to be fresh. |
|
646 | - if (is_array($settings) && ! empty($settings['subject'])) { |
|
647 | - $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
648 | - } |
|
649 | - return $settings; |
|
650 | - } |
|
11 | + /** |
|
12 | + * To field for email |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $_to = ''; |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + * CC field for email. |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $_cc = ''; |
|
23 | + |
|
24 | + /** |
|
25 | + * From field for email |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $_from = ''; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * Subject field for email |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $_subject = ''; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Content field for email |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $_content = ''; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * constructor |
|
47 | + * |
|
48 | + * @access public |
|
49 | + */ |
|
50 | + public function __construct() |
|
51 | + { |
|
52 | + //set name and description properties |
|
53 | + $this->name = 'email'; |
|
54 | + $this->description = sprintf( |
|
55 | + esc_html__( |
|
56 | + 'This messenger delivers messages via email using the built-in %s function included with WordPress', |
|
57 | + 'event_espresso' |
|
58 | + ), |
|
59 | + '<code>wp_mail</code>' |
|
60 | + ); |
|
61 | + $this->label = array( |
|
62 | + 'singular' => esc_html__('email', 'event_espresso'), |
|
63 | + 'plural' => esc_html__('emails', 'event_espresso'), |
|
64 | + ); |
|
65 | + $this->activate_on_install = true; |
|
66 | + |
|
67 | + //we're using defaults so let's call parent constructor that will take care of setting up all the other |
|
68 | + // properties |
|
69 | + parent::__construct(); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * see abstract declaration in parent class for details. |
|
75 | + */ |
|
76 | + protected function _set_admin_pages() |
|
77 | + { |
|
78 | + $this->admin_registered_pages = array( |
|
79 | + 'events_edit' => true, |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * see abstract declaration in parent class for details |
|
86 | + */ |
|
87 | + protected function _set_valid_shortcodes() |
|
88 | + { |
|
89 | + //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the |
|
90 | + // message type. |
|
91 | + $this->_valid_shortcodes = array( |
|
92 | + 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
93 | + 'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
94 | + 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * see abstract declaration in parent class for details |
|
101 | + * |
|
102 | + * @access protected |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + protected function _set_validator_config() |
|
106 | + { |
|
107 | + $valid_shortcodes = $this->get_valid_shortcodes(); |
|
108 | + |
|
109 | + $this->_validator_config = array( |
|
110 | + 'to' => array( |
|
111 | + 'shortcodes' => $valid_shortcodes['to'], |
|
112 | + 'type' => 'email', |
|
113 | + ), |
|
114 | + 'cc' => array( |
|
115 | + 'shortcodes' => $valid_shortcodes['to'], |
|
116 | + 'type' => 'email', |
|
117 | + ), |
|
118 | + 'from' => array( |
|
119 | + 'shortcodes' => $valid_shortcodes['from'], |
|
120 | + 'type' => 'email', |
|
121 | + ), |
|
122 | + 'subject' => array( |
|
123 | + 'shortcodes' => array( |
|
124 | + 'organization', |
|
125 | + 'primary_registration_details', |
|
126 | + 'event_author', |
|
127 | + 'primary_registration_details', |
|
128 | + 'recipient_details', |
|
129 | + ), |
|
130 | + ), |
|
131 | + 'content' => array( |
|
132 | + 'shortcodes' => array( |
|
133 | + 'event_list', |
|
134 | + 'attendee_list', |
|
135 | + 'ticket_list', |
|
136 | + 'organization', |
|
137 | + 'primary_registration_details', |
|
138 | + 'primary_registration_list', |
|
139 | + 'event_author', |
|
140 | + 'recipient_details', |
|
141 | + 'recipient_list', |
|
142 | + 'transaction', |
|
143 | + 'messenger', |
|
144 | + ), |
|
145 | + ), |
|
146 | + 'attendee_list' => array( |
|
147 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
148 | + 'required' => array('[ATTENDEE_LIST]'), |
|
149 | + ), |
|
150 | + 'event_list' => array( |
|
151 | + 'shortcodes' => array( |
|
152 | + 'event', |
|
153 | + 'attendee_list', |
|
154 | + 'ticket_list', |
|
155 | + 'venue', |
|
156 | + 'datetime_list', |
|
157 | + 'attendee', |
|
158 | + 'primary_registration_details', |
|
159 | + 'primary_registration_list', |
|
160 | + 'event_author', |
|
161 | + 'recipient_details', |
|
162 | + 'recipient_list', |
|
163 | + ), |
|
164 | + 'required' => array('[EVENT_LIST]'), |
|
165 | + ), |
|
166 | + 'ticket_list' => array( |
|
167 | + 'shortcodes' => array( |
|
168 | + 'event_list', |
|
169 | + 'attendee_list', |
|
170 | + 'ticket', |
|
171 | + 'datetime_list', |
|
172 | + 'primary_registration_details', |
|
173 | + 'recipient_details', |
|
174 | + ), |
|
175 | + 'required' => array('[TICKET_LIST]'), |
|
176 | + ), |
|
177 | + 'datetime_list' => array( |
|
178 | + 'shortcodes' => array('datetime'), |
|
179 | + 'required' => array('[DATETIME_LIST]'), |
|
180 | + ), |
|
181 | + ); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @see parent EE_messenger class for docs |
|
187 | + * @since 4.5.0 |
|
188 | + */ |
|
189 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
190 | + { |
|
191 | + if ($sending_messenger_name = 'html') { |
|
192 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + public function add_email_css( |
|
198 | + $variation_path, |
|
199 | + $messenger, |
|
200 | + $message_type, |
|
201 | + $type, |
|
202 | + $variation, |
|
203 | + $file_extension, |
|
204 | + $url, |
|
205 | + EE_Messages_Template_Pack $template_pack |
|
206 | + ) { |
|
207 | + //prevent recursion on this callback. |
|
208 | + remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
209 | + $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
210 | + |
|
211 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
212 | + return $variation; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * See parent for details |
|
218 | + * |
|
219 | + * @access protected |
|
220 | + * @return void |
|
221 | + */ |
|
222 | + protected function _set_test_settings_fields() |
|
223 | + { |
|
224 | + $this->_test_settings_fields = array( |
|
225 | + 'to' => array( |
|
226 | + 'input' => 'text', |
|
227 | + 'label' => esc_html__('Send a test email to', 'event_espresso'), |
|
228 | + 'type' => 'email', |
|
229 | + 'required' => true, |
|
230 | + 'validation' => true, |
|
231 | + 'css_class' => 'large-text', |
|
232 | + 'format' => '%s', |
|
233 | + 'default' => get_bloginfo('admin_email'), |
|
234 | + ), |
|
235 | + 'subject' => array( |
|
236 | + 'input' => 'hidden', |
|
237 | + 'label' => '', |
|
238 | + 'type' => 'string', |
|
239 | + 'required' => false, |
|
240 | + 'validation' => false, |
|
241 | + 'format' => '%s', |
|
242 | + 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
243 | + 'default' => '', |
|
244 | + 'css_class' => '', |
|
245 | + ), |
|
246 | + ); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * _set_template_fields |
|
252 | + * This sets up the fields that a messenger requires for the message to go out. |
|
253 | + * |
|
254 | + * @access protected |
|
255 | + * @return void |
|
256 | + */ |
|
257 | + protected function _set_template_fields() |
|
258 | + { |
|
259 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for |
|
260 | + // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field |
|
261 | + // they relate to. This is important for the Messages_admin to know what fields to display to the user. |
|
262 | + // Also, notice that the "values" are equal to the field type that messages admin will use to know what |
|
263 | + // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array |
|
264 | + // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be |
|
265 | + // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and |
|
266 | + // will not be displayed/parsed. |
|
267 | + $this->_template_fields = array( |
|
268 | + 'to' => array( |
|
269 | + 'input' => 'text', |
|
270 | + 'label' => esc_html_x( |
|
271 | + 'To', |
|
272 | + 'Label for the "To" field for email addresses', |
|
273 | + 'event_espresso' |
|
274 | + ), |
|
275 | + 'type' => 'string', |
|
276 | + 'required' => true, |
|
277 | + 'validation' => true, |
|
278 | + 'css_class' => 'large-text', |
|
279 | + 'format' => '%s', |
|
280 | + ), |
|
281 | + 'cc' => array( |
|
282 | + 'input' => 'text', |
|
283 | + 'label' => esc_html_x( |
|
284 | + 'CC', |
|
285 | + 'Label for the "Carbon Copy" field used for additional email addresses', |
|
286 | + 'event_espresso' |
|
287 | + ), |
|
288 | + 'type' => 'string', |
|
289 | + 'required' => false, |
|
290 | + 'validation' => true, |
|
291 | + 'css_class' => 'large-text', |
|
292 | + 'format' => '%s', |
|
293 | + ), |
|
294 | + 'from' => array( |
|
295 | + 'input' => 'text', |
|
296 | + 'label' => esc_html_x( |
|
297 | + 'From', |
|
298 | + 'Label for the "From" field for email addresses.', |
|
299 | + 'event_espresso' |
|
300 | + ), |
|
301 | + 'type' => 'string', |
|
302 | + 'required' => true, |
|
303 | + 'validation' => true, |
|
304 | + 'css_class' => 'large-text', |
|
305 | + 'format' => '%s', |
|
306 | + ), |
|
307 | + 'subject' => array( |
|
308 | + 'input' => 'text', |
|
309 | + 'label' => esc_html_x( |
|
310 | + 'Subject', |
|
311 | + 'Label for the "Subject" field (short description of contents) for emails.', |
|
312 | + 'event_espresso' |
|
313 | + ), |
|
314 | + 'type' => 'string', |
|
315 | + 'required' => true, |
|
316 | + 'validation' => true, |
|
317 | + 'css_class' => 'large-text', |
|
318 | + 'format' => '%s', |
|
319 | + ), |
|
320 | + 'content' => '', |
|
321 | + //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
322 | + 'extra' => array( |
|
323 | + 'content' => array( |
|
324 | + 'main' => array( |
|
325 | + 'input' => 'wp_editor', |
|
326 | + 'label' => esc_html__('Main Content', 'event_espresso'), |
|
327 | + 'type' => 'string', |
|
328 | + 'required' => true, |
|
329 | + 'validation' => true, |
|
330 | + 'format' => '%s', |
|
331 | + 'rows' => '15', |
|
332 | + ), |
|
333 | + 'event_list' => array( |
|
334 | + 'input' => 'wp_editor', |
|
335 | + 'label' => '[EVENT_LIST]', |
|
336 | + 'type' => 'string', |
|
337 | + 'required' => true, |
|
338 | + 'validation' => true, |
|
339 | + 'format' => '%s', |
|
340 | + 'rows' => '15', |
|
341 | + 'shortcodes_required' => array('[EVENT_LIST]'), |
|
342 | + ), |
|
343 | + 'attendee_list' => array( |
|
344 | + 'input' => 'textarea', |
|
345 | + 'label' => '[ATTENDEE_LIST]', |
|
346 | + 'type' => 'string', |
|
347 | + 'required' => true, |
|
348 | + 'validation' => true, |
|
349 | + 'format' => '%s', |
|
350 | + 'css_class' => 'large-text', |
|
351 | + 'rows' => '5', |
|
352 | + 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
353 | + ), |
|
354 | + 'ticket_list' => array( |
|
355 | + 'input' => 'textarea', |
|
356 | + 'label' => '[TICKET_LIST]', |
|
357 | + 'type' => 'string', |
|
358 | + 'required' => true, |
|
359 | + 'validation' => true, |
|
360 | + 'format' => '%s', |
|
361 | + 'css_class' => 'large-text', |
|
362 | + 'rows' => '10', |
|
363 | + 'shortcodes_required' => array('[TICKET_LIST]'), |
|
364 | + ), |
|
365 | + 'datetime_list' => array( |
|
366 | + 'input' => 'textarea', |
|
367 | + 'label' => '[DATETIME_LIST]', |
|
368 | + 'type' => 'string', |
|
369 | + 'required' => true, |
|
370 | + 'validation' => true, |
|
371 | + 'format' => '%s', |
|
372 | + 'css_class' => 'large-text', |
|
373 | + 'rows' => '10', |
|
374 | + 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
375 | + ), |
|
376 | + ), |
|
377 | + ), |
|
378 | + ); |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * See definition of this class in parent |
|
384 | + */ |
|
385 | + protected function _set_default_message_types() |
|
386 | + { |
|
387 | + $this->_default_message_types = array( |
|
388 | + 'payment', |
|
389 | + 'payment_refund', |
|
390 | + 'registration', |
|
391 | + 'not_approved_registration', |
|
392 | + 'pending_approval', |
|
393 | + ); |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * @see definition of this class in parent |
|
399 | + * @since 4.5.0 |
|
400 | + */ |
|
401 | + protected function _set_valid_message_types() |
|
402 | + { |
|
403 | + $this->_valid_message_types = array( |
|
404 | + 'payment', |
|
405 | + 'registration', |
|
406 | + 'not_approved_registration', |
|
407 | + 'declined_registration', |
|
408 | + 'cancelled_registration', |
|
409 | + 'pending_approval', |
|
410 | + 'registration_summary', |
|
411 | + 'payment_reminder', |
|
412 | + 'payment_declined', |
|
413 | + 'payment_refund', |
|
414 | + ); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * setting up admin_settings_fields for messenger. |
|
420 | + */ |
|
421 | + protected function _set_admin_settings_fields() |
|
422 | + { |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * We just deliver the messages don't kill us!! |
|
427 | + * |
|
428 | + * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
429 | + * present. |
|
430 | + * @throws EE_Error |
|
431 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
432 | + */ |
|
433 | + protected function _send_message() |
|
434 | + { |
|
435 | + $success = wp_mail( |
|
436 | + $this->_to, |
|
437 | + //some old values for subject may be expecting HTML entities to be decoded in the subject |
|
438 | + //and subjects aren't interpreted as HTML, so there should be no HTML in them |
|
439 | + wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)), |
|
440 | + $this->_body(), |
|
441 | + $this->_headers() |
|
442 | + ); |
|
443 | + if (! $success) { |
|
444 | + EE_Error::add_error( |
|
445 | + sprintf( |
|
446 | + esc_html__( |
|
447 | + 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
448 | + 'event_espresso' |
|
449 | + ), |
|
450 | + $this->_to, |
|
451 | + $this->_from, |
|
452 | + '<br />' |
|
453 | + ), |
|
454 | + __FILE__, |
|
455 | + __FUNCTION__, |
|
456 | + __LINE__ |
|
457 | + ); |
|
458 | + } |
|
459 | + return $success; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * see parent for definition |
|
465 | + * |
|
466 | + * @return string html body of the message content and the related css. |
|
467 | + * @throws EE_Error |
|
468 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
469 | + */ |
|
470 | + protected function _preview() |
|
471 | + { |
|
472 | + return $this->_body(true); |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * Setup headers for email |
|
478 | + * |
|
479 | + * @access protected |
|
480 | + * @return string formatted header for email |
|
481 | + */ |
|
482 | + protected function _headers() |
|
483 | + { |
|
484 | + $this->_ensure_has_from_email_address(); |
|
485 | + $from = $this->_from; |
|
486 | + $headers = array( |
|
487 | + 'From:' . $from, |
|
488 | + 'Reply-To:' . $from, |
|
489 | + 'Content-Type:text/html; charset=utf-8', |
|
490 | + ); |
|
491 | + |
|
492 | + if (! empty($this->_cc)) { |
|
493 | + $headers[] = 'cc: ' . $this->_cc; |
|
494 | + } |
|
495 | + |
|
496 | + //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the |
|
497 | + // header. |
|
498 | + add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
499 | + add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
500 | + return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
506 | + * address for the from address to avoid problems with sending emails. |
|
507 | + */ |
|
508 | + protected function _ensure_has_from_email_address() |
|
509 | + { |
|
510 | + if (empty($this->_from)) { |
|
511 | + $this->_from = get_bloginfo('admin_email'); |
|
512 | + } |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
518 | + * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
519 | + * be empty |
|
520 | + * |
|
521 | + * @since 4.3.1 |
|
522 | + * @return array |
|
523 | + */ |
|
524 | + private function _parse_from() |
|
525 | + { |
|
526 | + if (strpos($this->_from, '<') !== false) { |
|
527 | + $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
528 | + $from_name = str_replace('"', '', $from_name); |
|
529 | + $from_name = trim($from_name); |
|
530 | + |
|
531 | + $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
532 | + $from_email = str_replace('>', '', $from_email); |
|
533 | + $from_email = trim($from_email); |
|
534 | + } elseif (trim($this->_from) !== '') { |
|
535 | + $from_name = ''; |
|
536 | + $from_email = trim($this->_from); |
|
537 | + } else { |
|
538 | + $from_name = $from_email = ''; |
|
539 | + } |
|
540 | + return array($from_name, $from_email); |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * Callback for the wp_mail_from filter. |
|
546 | + * |
|
547 | + * @since 4.3.1 |
|
548 | + * @param string $from_email What the original from_email is. |
|
549 | + * @return string |
|
550 | + */ |
|
551 | + public function set_from_address($from_email) |
|
552 | + { |
|
553 | + $parsed_from = $this->_parse_from(); |
|
554 | + //includes fallback if the parsing failed. |
|
555 | + $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) |
|
556 | + ? $parsed_from[1] |
|
557 | + : get_bloginfo('admin_email'); |
|
558 | + return $from_email; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * Callback fro the wp_mail_from_name filter. |
|
564 | + * |
|
565 | + * @since 4.3.1 |
|
566 | + * @param string $from_name The original from_name. |
|
567 | + * @return string |
|
568 | + */ |
|
569 | + public function set_from_name($from_name) |
|
570 | + { |
|
571 | + $parsed_from = $this->_parse_from(); |
|
572 | + if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
573 | + $from_name = $parsed_from[0]; |
|
574 | + } |
|
575 | + |
|
576 | + //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
577 | + //but realize the default name is HTML entity-encoded |
|
578 | + $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name; |
|
579 | + |
|
580 | + return $from_name; |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * setup body for email |
|
586 | + * |
|
587 | + * @param bool $preview will determine whether this is preview template or not. |
|
588 | + * @return string formatted body for email. |
|
589 | + * @throws EE_Error |
|
590 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception |
|
591 | + */ |
|
592 | + protected function _body($preview = false) |
|
593 | + { |
|
594 | + //setup template args! |
|
595 | + $this->_template_args = array( |
|
596 | + 'subject' => $this->_subject, |
|
597 | + 'from' => $this->_from, |
|
598 | + 'main_body' => wpautop($this->_content), |
|
599 | + ); |
|
600 | + $body = $this->_get_main_template($preview); |
|
601 | + |
|
602 | + /** |
|
603 | + * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
604 | + * |
|
605 | + * @type bool $preview Indicates whether a preview is being generated or not. |
|
606 | + * @return bool true indicates to use the inliner, false bypasses it. |
|
607 | + */ |
|
608 | + if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
609 | + //require CssToInlineStyles library and its dependencies via composer autoloader |
|
610 | + require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
611 | + |
|
612 | + //now if this isn't a preview, let's setup the body so it has inline styles |
|
613 | + if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
614 | + $style = file_get_contents( |
|
615 | + $this->get_variation( |
|
616 | + $this->_tmp_pack, |
|
617 | + $this->_incoming_message_type->name, |
|
618 | + false, |
|
619 | + 'main', |
|
620 | + $this->_variation |
|
621 | + ), |
|
622 | + true |
|
623 | + ); |
|
624 | + $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
625 | + //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
626 | + $body = ltrim($CSS->convert(true), ">\n"); |
|
627 | + //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
628 | + $body = ltrim($body, "<?"); |
|
629 | + } |
|
630 | + |
|
631 | + } |
|
632 | + return $body; |
|
633 | + } |
|
634 | + |
|
635 | + |
|
636 | + /** |
|
637 | + * This just returns any existing test settings that might be saved in the database |
|
638 | + * |
|
639 | + * @access public |
|
640 | + * @return array |
|
641 | + */ |
|
642 | + public function get_existing_test_settings() |
|
643 | + { |
|
644 | + $settings = parent::get_existing_test_settings(); |
|
645 | + //override subject if present because we always want it to be fresh. |
|
646 | + if (is_array($settings) && ! empty($settings['subject'])) { |
|
647 | + $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
648 | + } |
|
649 | + return $settings; |
|
650 | + } |
|
651 | 651 | } |
@@ -107,71 +107,71 @@ discard block |
||
107 | 107 | public function __toString() { |
108 | 108 | $JSON_response = array(); |
109 | 109 | // grab notices |
110 | - $notices = EE_Error::get_notices( FALSE ); |
|
111 | - $this->set_attention( isset( $notices['attention'] ) ? $notices['attention'] : '' ); |
|
112 | - $this->set_errors( isset( $notices['errors'] ) ? $notices['errors'] : '' ); |
|
113 | - $this->set_success( isset( $notices['success'] ) ? $notices['success'] : '' ); |
|
110 | + $notices = EE_Error::get_notices(FALSE); |
|
111 | + $this->set_attention(isset($notices['attention']) ? $notices['attention'] : ''); |
|
112 | + $this->set_errors(isset($notices['errors']) ? $notices['errors'] : ''); |
|
113 | + $this->set_success(isset($notices['success']) ? $notices['success'] : ''); |
|
114 | 114 | // add notices to JSON response, but only if they exist |
115 | - if ( $this->attention() ) { |
|
115 | + if ($this->attention()) { |
|
116 | 116 | $JSON_response['attention'] = $this->attention(); |
117 | 117 | } |
118 | - if ( $this->errors() ) { |
|
118 | + if ($this->errors()) { |
|
119 | 119 | $JSON_response['errors'] = $this->errors(); |
120 | 120 | } |
121 | - if ( $this->unexpected_errors() ) { |
|
121 | + if ($this->unexpected_errors()) { |
|
122 | 122 | $JSON_response['unexpected_errors'] = $this->unexpected_errors(); |
123 | 123 | } |
124 | - if ( $this->success() ) { |
|
124 | + if ($this->success()) { |
|
125 | 125 | $JSON_response['success'] = $this->success(); |
126 | 126 | } |
127 | 127 | // but if NO notices are set... at least set the "success" as a key so that the JS knows everything worked |
128 | - if ( ! isset( $JSON_response[ 'attention' ] ) && ! isset( $JSON_response[ 'errors' ] ) && ! isset( $JSON_response[ 'success' ] ) ) { |
|
128 | + if ( ! isset($JSON_response['attention']) && ! isset($JSON_response['errors']) && ! isset($JSON_response['success'])) { |
|
129 | 129 | $JSON_response['success'] = null; |
130 | 130 | } |
131 | 131 | // set redirect_url, IF it exists |
132 | - if ( $this->redirect_url() ) { |
|
132 | + if ($this->redirect_url()) { |
|
133 | 133 | $JSON_response['redirect_url'] = $this->redirect_url(); |
134 | 134 | } |
135 | 135 | // set registration_time_limit, IF it exists |
136 | - if ( $this->registration_time_limit() ) { |
|
136 | + if ($this->registration_time_limit()) { |
|
137 | 137 | $JSON_response['registration_time_limit'] = $this->registration_time_limit(); |
138 | 138 | } |
139 | 139 | // set payment_amount, IF it exists |
140 | - if ( $this->payment_amount() !== null ) { |
|
141 | - $JSON_response[ 'payment_amount' ] = $this->payment_amount(); |
|
140 | + if ($this->payment_amount() !== null) { |
|
141 | + $JSON_response['payment_amount'] = $this->payment_amount(); |
|
142 | 142 | } |
143 | 143 | // grab generic return data |
144 | 144 | $return_data = $this->return_data(); |
145 | 145 | // add billing form validation rules |
146 | - if ( $this->validation_rules() ) { |
|
146 | + if ($this->validation_rules()) { |
|
147 | 147 | $return_data['validation_rules'] = $this->validation_rules(); |
148 | 148 | } |
149 | 149 | // set reg_step_html, IF it exists |
150 | - if ( $this->reg_step_html() ) { |
|
150 | + if ($this->reg_step_html()) { |
|
151 | 151 | $return_data['reg_step_html'] = $this->reg_step_html(); |
152 | 152 | } |
153 | 153 | // set method of payment, IF it exists |
154 | - if ( $this->method_of_payment() ) { |
|
154 | + if ($this->method_of_payment()) { |
|
155 | 155 | $return_data['method_of_payment'] = $this->method_of_payment(); |
156 | 156 | } |
157 | 157 | // set "plz_select_method_of_payment" message, IF it exists |
158 | - if ( $this->plz_select_method_of_payment() ) { |
|
158 | + if ($this->plz_select_method_of_payment()) { |
|
159 | 159 | $return_data['plz_select_method_of_payment'] = $this->plz_select_method_of_payment(); |
160 | 160 | } |
161 | 161 | // set redirect_form, IF it exists |
162 | - if ( $this->redirect_form() ) { |
|
162 | + if ($this->redirect_form()) { |
|
163 | 163 | $return_data['redirect_form'] = $this->redirect_form(); |
164 | 164 | } |
165 | 165 | // and finally, add return_data array to main JSON response array, IF it contains anything |
166 | 166 | // why did we add some of the above properties to the return data array? |
167 | 167 | // because it is easier and cleaner in the Javascript to deal with this way |
168 | - if ( ! empty( $return_data )) { |
|
168 | + if ( ! empty($return_data)) { |
|
169 | 169 | $JSON_response['return_data'] = $return_data; |
170 | 170 | } |
171 | 171 | // filter final array |
172 | - $JSON_response = apply_filters( 'FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response ); |
|
172 | + $JSON_response = apply_filters('FHEE__EE_SPCO_JSON_Response___toString__JSON_response', $JSON_response); |
|
173 | 173 | // return encoded array |
174 | - return wp_json_encode( $JSON_response ); |
|
174 | + return wp_json_encode($JSON_response); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | /** |
180 | 180 | * @param string $attention |
181 | 181 | */ |
182 | - public function set_attention( $attention ) { |
|
182 | + public function set_attention($attention) { |
|
183 | 183 | $this->_attention = $attention; |
184 | 184 | } |
185 | 185 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | /** |
198 | 198 | * @param string $errors |
199 | 199 | */ |
200 | - public function set_errors( $errors ) { |
|
200 | + public function set_errors($errors) { |
|
201 | 201 | $this->_errors = $errors; |
202 | 202 | } |
203 | 203 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | /** |
225 | 225 | * @param string $unexpected_errors |
226 | 226 | */ |
227 | - public function set_unexpected_errors( $unexpected_errors ) { |
|
227 | + public function set_unexpected_errors($unexpected_errors) { |
|
228 | 228 | $this->_unexpected_errors = $unexpected_errors; |
229 | 229 | } |
230 | 230 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | /** |
234 | 234 | * @param string $success |
235 | 235 | */ |
236 | - public function set_success( $success ) { |
|
236 | + public function set_success($success) { |
|
237 | 237 | $this->_success = $success; |
238 | 238 | } |
239 | 239 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | /** |
252 | 252 | * @param string $method_of_payment |
253 | 253 | */ |
254 | - public function set_method_of_payment( $method_of_payment ) { |
|
254 | + public function set_method_of_payment($method_of_payment) { |
|
255 | 255 | $this->_method_of_payment = $method_of_payment; |
256 | 256 | } |
257 | 257 | |
@@ -278,8 +278,8 @@ discard block |
||
278 | 278 | /** |
279 | 279 | * @param float $payment_amount |
280 | 280 | */ |
281 | - public function set_payment_amount( $payment_amount ) { |
|
282 | - $this->_payment_amount = (float)$payment_amount; |
|
281 | + public function set_payment_amount($payment_amount) { |
|
282 | + $this->_payment_amount = (float) $payment_amount; |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | /** |
288 | 288 | * @param string $next_step_html |
289 | 289 | */ |
290 | - public function set_reg_step_html( $next_step_html ) { |
|
290 | + public function set_reg_step_html($next_step_html) { |
|
291 | 291 | $this->_reg_step_html = $next_step_html; |
292 | 292 | } |
293 | 293 | |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | /** |
306 | 306 | * @param string $redirect_form |
307 | 307 | */ |
308 | - public function set_redirect_form( $redirect_form ) { |
|
308 | + public function set_redirect_form($redirect_form) { |
|
309 | 309 | $this->_redirect_form = $redirect_form; |
310 | 310 | } |
311 | 311 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @return string |
316 | 316 | */ |
317 | 317 | public function redirect_form() { |
318 | - return ! empty( $this->_redirect_form ) ? $this->_redirect_form : FALSE; |
|
318 | + return ! empty($this->_redirect_form) ? $this->_redirect_form : FALSE; |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | /** |
324 | 324 | * @param string $plz_select_method_of_payment |
325 | 325 | */ |
326 | - public function set_plz_select_method_of_payment( $plz_select_method_of_payment ) { |
|
326 | + public function set_plz_select_method_of_payment($plz_select_method_of_payment) { |
|
327 | 327 | $this->_plz_select_method_of_payment = $plz_select_method_of_payment; |
328 | 328 | } |
329 | 329 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | /** |
342 | 342 | * @param string $redirect_url |
343 | 343 | */ |
344 | - public function set_redirect_url( $redirect_url ) { |
|
344 | + public function set_redirect_url($redirect_url) { |
|
345 | 345 | $this->_redirect_url = $redirect_url; |
346 | 346 | } |
347 | 347 | |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | /** |
369 | 369 | * @param string $registration_time_limit |
370 | 370 | */ |
371 | - public function set_registration_time_limit( $registration_time_limit ) { |
|
371 | + public function set_registration_time_limit($registration_time_limit) { |
|
372 | 372 | $this->_registration_time_limit = $registration_time_limit; |
373 | 373 | } |
374 | 374 | |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | /** |
378 | 378 | * @param array $return_data |
379 | 379 | */ |
380 | - public function set_return_data( $return_data ) { |
|
381 | - $this->_return_data = array_merge( $this->_return_data, $return_data ); |
|
380 | + public function set_return_data($return_data) { |
|
381 | + $this->_return_data = array_merge($this->_return_data, $return_data); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | |
@@ -395,9 +395,9 @@ discard block |
||
395 | 395 | /** |
396 | 396 | * @param array $validation_rules |
397 | 397 | */ |
398 | - public function add_validation_rules( $validation_rules = array() ) { |
|
399 | - if ( is_array( $validation_rules ) && ! empty( $validation_rules )) { |
|
400 | - $this->_validation_rules = array_merge( $this->_validation_rules, $validation_rules ); |
|
398 | + public function add_validation_rules($validation_rules = array()) { |
|
399 | + if (is_array($validation_rules) && ! empty($validation_rules)) { |
|
400 | + $this->_validation_rules = array_merge($this->_validation_rules, $validation_rules); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 | |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | * @return array | bool |
408 | 408 | */ |
409 | 409 | public function validation_rules() { |
410 | - return ! empty( $this->_validation_rules ) ? $this->_validation_rules : FALSE; |
|
410 | + return ! empty($this->_validation_rules) ? $this->_validation_rules : FALSE; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 |
@@ -38,216 +38,216 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.002'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.002'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | - /** |
|
119 | - * espresso_load_error_handling |
|
120 | - * this function loads EE's class for handling exceptions and errors |
|
121 | - */ |
|
122 | - function espresso_load_error_handling() |
|
123 | - { |
|
124 | - static $error_handling_loaded = false; |
|
125 | - if ($error_handling_loaded) { |
|
126 | - return; |
|
127 | - } |
|
128 | - // load debugging tools |
|
129 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
130 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
131 | - \EEH_Debug_Tools::instance(); |
|
132 | - } |
|
133 | - // load error handling |
|
134 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
135 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
136 | - } else { |
|
137 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
138 | - } |
|
139 | - $error_handling_loaded = true; |
|
140 | - } |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | + /** |
|
119 | + * espresso_load_error_handling |
|
120 | + * this function loads EE's class for handling exceptions and errors |
|
121 | + */ |
|
122 | + function espresso_load_error_handling() |
|
123 | + { |
|
124 | + static $error_handling_loaded = false; |
|
125 | + if ($error_handling_loaded) { |
|
126 | + return; |
|
127 | + } |
|
128 | + // load debugging tools |
|
129 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
130 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
131 | + \EEH_Debug_Tools::instance(); |
|
132 | + } |
|
133 | + // load error handling |
|
134 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
135 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
136 | + } else { |
|
137 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
138 | + } |
|
139 | + $error_handling_loaded = true; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * espresso_load_required |
|
144 | - * given a class name and path, this function will load that file or throw an exception |
|
145 | - * |
|
146 | - * @param string $classname |
|
147 | - * @param string $full_path_to_file |
|
148 | - * @throws EE_Error |
|
149 | - */ |
|
150 | - function espresso_load_required($classname, $full_path_to_file) |
|
151 | - { |
|
152 | - if (is_readable($full_path_to_file)) { |
|
153 | - require_once $full_path_to_file; |
|
154 | - } else { |
|
155 | - throw new \EE_Error ( |
|
156 | - sprintf( |
|
157 | - esc_html__( |
|
158 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
159 | - 'event_espresso' |
|
160 | - ), |
|
161 | - $classname |
|
162 | - ) |
|
163 | - ); |
|
164 | - } |
|
165 | - } |
|
142 | + /** |
|
143 | + * espresso_load_required |
|
144 | + * given a class name and path, this function will load that file or throw an exception |
|
145 | + * |
|
146 | + * @param string $classname |
|
147 | + * @param string $full_path_to_file |
|
148 | + * @throws EE_Error |
|
149 | + */ |
|
150 | + function espresso_load_required($classname, $full_path_to_file) |
|
151 | + { |
|
152 | + if (is_readable($full_path_to_file)) { |
|
153 | + require_once $full_path_to_file; |
|
154 | + } else { |
|
155 | + throw new \EE_Error ( |
|
156 | + sprintf( |
|
157 | + esc_html__( |
|
158 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
159 | + 'event_espresso' |
|
160 | + ), |
|
161 | + $classname |
|
162 | + ) |
|
163 | + ); |
|
164 | + } |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @since 4.9.27 |
|
169 | - * @throws \EE_Error |
|
170 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
171 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
172 | - * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
173 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
174 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
175 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
176 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
177 | - * @throws \OutOfBoundsException |
|
178 | - */ |
|
179 | - function bootstrap_espresso() |
|
180 | - { |
|
181 | - require_once __DIR__ . '/core/espresso_definitions.php'; |
|
182 | - try { |
|
183 | - espresso_load_error_handling(); |
|
184 | - espresso_load_required( |
|
185 | - 'EEH_Base', |
|
186 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
187 | - ); |
|
188 | - espresso_load_required( |
|
189 | - 'EEH_File', |
|
190 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
191 | - ); |
|
192 | - espresso_load_required( |
|
193 | - 'EEH_File', |
|
194 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
195 | - ); |
|
196 | - espresso_load_required( |
|
197 | - 'EEH_Array', |
|
198 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
199 | - ); |
|
200 | - // instantiate and configure PSR4 autoloader |
|
201 | - espresso_load_required( |
|
202 | - 'Psr4Autoloader', |
|
203 | - EE_CORE . 'Psr4Autoloader.php' |
|
204 | - ); |
|
205 | - espresso_load_required( |
|
206 | - 'EE_Psr4AutoloaderInit', |
|
207 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
208 | - ); |
|
209 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
210 | - $AutoloaderInit->initializeAutoloader(); |
|
211 | - espresso_load_required( |
|
212 | - 'EE_Request', |
|
213 | - EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
214 | - ); |
|
215 | - espresso_load_required( |
|
216 | - 'EE_Response', |
|
217 | - EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
218 | - ); |
|
219 | - espresso_load_required( |
|
220 | - 'EE_Bootstrap', |
|
221 | - EE_CORE . 'EE_Bootstrap.core.php' |
|
222 | - ); |
|
223 | - // bootstrap EE and the request stack |
|
224 | - new EE_Bootstrap( |
|
225 | - new EE_Request($_GET, $_POST, $_COOKIE), |
|
226 | - new EE_Response() |
|
227 | - ); |
|
228 | - } catch (Exception $e) { |
|
229 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
230 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
231 | - } |
|
232 | - } |
|
233 | - bootstrap_espresso(); |
|
234 | - } |
|
167 | + /** |
|
168 | + * @since 4.9.27 |
|
169 | + * @throws \EE_Error |
|
170 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
171 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
172 | + * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
173 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
174 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
175 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
176 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
177 | + * @throws \OutOfBoundsException |
|
178 | + */ |
|
179 | + function bootstrap_espresso() |
|
180 | + { |
|
181 | + require_once __DIR__ . '/core/espresso_definitions.php'; |
|
182 | + try { |
|
183 | + espresso_load_error_handling(); |
|
184 | + espresso_load_required( |
|
185 | + 'EEH_Base', |
|
186 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
187 | + ); |
|
188 | + espresso_load_required( |
|
189 | + 'EEH_File', |
|
190 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
191 | + ); |
|
192 | + espresso_load_required( |
|
193 | + 'EEH_File', |
|
194 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
195 | + ); |
|
196 | + espresso_load_required( |
|
197 | + 'EEH_Array', |
|
198 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
199 | + ); |
|
200 | + // instantiate and configure PSR4 autoloader |
|
201 | + espresso_load_required( |
|
202 | + 'Psr4Autoloader', |
|
203 | + EE_CORE . 'Psr4Autoloader.php' |
|
204 | + ); |
|
205 | + espresso_load_required( |
|
206 | + 'EE_Psr4AutoloaderInit', |
|
207 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
208 | + ); |
|
209 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
210 | + $AutoloaderInit->initializeAutoloader(); |
|
211 | + espresso_load_required( |
|
212 | + 'EE_Request', |
|
213 | + EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
214 | + ); |
|
215 | + espresso_load_required( |
|
216 | + 'EE_Response', |
|
217 | + EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
218 | + ); |
|
219 | + espresso_load_required( |
|
220 | + 'EE_Bootstrap', |
|
221 | + EE_CORE . 'EE_Bootstrap.core.php' |
|
222 | + ); |
|
223 | + // bootstrap EE and the request stack |
|
224 | + new EE_Bootstrap( |
|
225 | + new EE_Request($_GET, $_POST, $_COOKIE), |
|
226 | + new EE_Response() |
|
227 | + ); |
|
228 | + } catch (Exception $e) { |
|
229 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
230 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
231 | + } |
|
232 | + } |
|
233 | + bootstrap_espresso(); |
|
234 | + } |
|
235 | 235 | } |
236 | 236 | if (! function_exists('espresso_deactivate_plugin')) { |
237 | - /** |
|
238 | - * deactivate_plugin |
|
239 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
240 | - * |
|
241 | - * @access public |
|
242 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
243 | - * @return void |
|
244 | - */ |
|
245 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
246 | - { |
|
247 | - if (! function_exists('deactivate_plugins')) { |
|
248 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
249 | - } |
|
250 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
251 | - deactivate_plugins($plugin_basename); |
|
252 | - } |
|
237 | + /** |
|
238 | + * deactivate_plugin |
|
239 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
240 | + * |
|
241 | + * @access public |
|
242 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
243 | + * @return void |
|
244 | + */ |
|
245 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
246 | + { |
|
247 | + if (! function_exists('deactivate_plugins')) { |
|
248 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
249 | + } |
|
250 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
251 | + deactivate_plugins($plugin_basename); |
|
252 | + } |
|
253 | 253 | } |
@@ -14,1422 +14,1422 @@ |
||
14 | 14 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
15 | 15 | { |
16 | 16 | |
17 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
18 | - |
|
19 | - /** |
|
20 | - * Subsections |
|
21 | - * |
|
22 | - * @var EE_Form_Section_Validatable[] |
|
23 | - */ |
|
24 | - protected $_subsections = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * Strategy for laying out the form |
|
28 | - * |
|
29 | - * @var EE_Form_Section_Layout_Base |
|
30 | - */ |
|
31 | - protected $_layout_strategy; |
|
32 | - |
|
33 | - /** |
|
34 | - * Whether or not this form has received and validated a form submission yet |
|
35 | - * |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - protected $_received_submission = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * message displayed to users upon successful form submission |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - protected $_form_submission_success_message = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * message displayed to users upon unsuccessful form submission |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_form_submission_error_message = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * Stores all the data that will localized for form validation |
|
56 | - * |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - static protected $_js_localization = array(); |
|
60 | - |
|
61 | - /** |
|
62 | - * whether or not the form's localized validation JS vars have been set |
|
63 | - * |
|
64 | - * @type boolean |
|
65 | - */ |
|
66 | - static protected $_scripts_localized = false; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * when constructing a proper form section, calls _construct_finalize on children |
|
71 | - * so that they know who their parent is, and what name they've been given. |
|
72 | - * |
|
73 | - * @param array[] $options_array { |
|
74 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
75 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
76 | - * and in that order. This is handy if you want |
|
77 | - * the subsections to be ordered differently than the default, and if you override |
|
78 | - * which fields are shown |
|
79 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
80 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
81 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
82 | - * items from that list of inclusions) |
|
83 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
84 | - * } @see EE_Form_Section_Validatable::__construct() |
|
85 | - * @throws EE_Error |
|
86 | - */ |
|
87 | - public function __construct($options_array = array()) |
|
88 | - { |
|
89 | - $options_array = (array) apply_filters( |
|
90 | - 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
91 | - $options_array, |
|
92 | - $this |
|
93 | - ); |
|
94 | - //call parent first, as it may be setting the name |
|
95 | - parent::__construct($options_array); |
|
96 | - //if they've included subsections in the constructor, add them now |
|
97 | - if (isset($options_array['include'])) { |
|
98 | - //we are going to make sure we ONLY have those subsections to include |
|
99 | - //AND we are going to make sure they're in that specified order |
|
100 | - $reordered_subsections = array(); |
|
101 | - foreach ($options_array['include'] as $input_name) { |
|
102 | - if (isset($this->_subsections[ $input_name ])) { |
|
103 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
104 | - } |
|
105 | - } |
|
106 | - $this->_subsections = $reordered_subsections; |
|
107 | - } |
|
108 | - if (isset($options_array['exclude'])) { |
|
109 | - $exclude = $options_array['exclude']; |
|
110 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
111 | - } |
|
112 | - if (isset($options_array['layout_strategy'])) { |
|
113 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
114 | - } |
|
115 | - if (! $this->_layout_strategy) { |
|
116 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
117 | - } |
|
118 | - $this->_layout_strategy->_construct_finalize($this); |
|
119 | - //ok so we are definitely going to want the forms JS, |
|
120 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
121 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
122 | - //ok so they've constructed this object after when they should have. |
|
123 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
124 | - EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
125 | - } else { |
|
126 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
127 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
128 | - } |
|
129 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
130 | - /** |
|
131 | - * Gives other plugins a chance to hook in before construct finalize is called. |
|
132 | - * The form probably doesn't yet have a parent form section. |
|
133 | - * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
134 | - * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
135 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
136 | - * |
|
137 | - * @since 4.9.32 |
|
138 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
139 | - * except maybe calling _construct_finalize has been done |
|
140 | - * @param array $options_array options passed into the constructor |
|
141 | - */ |
|
142 | - do_action( |
|
143 | - 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
144 | - $this, |
|
145 | - $options_array |
|
146 | - ); |
|
147 | - if (isset($options_array['name'])) { |
|
148 | - $this->_construct_finalize(null, $options_array['name']); |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * Finishes construction given the parent form section and this form section's name |
|
155 | - * |
|
156 | - * @param EE_Form_Section_Proper $parent_form_section |
|
157 | - * @param string $name |
|
158 | - * @throws EE_Error |
|
159 | - */ |
|
160 | - public function _construct_finalize($parent_form_section, $name) |
|
161 | - { |
|
162 | - parent::_construct_finalize($parent_form_section, $name); |
|
163 | - $this->_set_default_name_if_empty(); |
|
164 | - $this->_set_default_html_id_if_empty(); |
|
165 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
166 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
167 | - $subsection->_construct_finalize($this, $subsection_name); |
|
168 | - } else { |
|
169 | - throw new EE_Error( |
|
170 | - sprintf( |
|
171 | - esc_html__( |
|
172 | - 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
173 | - 'event_espresso' |
|
174 | - ), |
|
175 | - $subsection_name, |
|
176 | - get_class($this), |
|
177 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
178 | - ) |
|
179 | - ); |
|
180 | - } |
|
181 | - } |
|
182 | - /** |
|
183 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
184 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
185 | - * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
186 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
187 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
188 | - * ensured it has a name, HTML IDs, etc |
|
189 | - * |
|
190 | - * @param EE_Form_Section_Proper $this |
|
191 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
192 | - * @param string $name |
|
193 | - */ |
|
194 | - do_action( |
|
195 | - 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
196 | - $this, |
|
197 | - $parent_form_section, |
|
198 | - $name |
|
199 | - ); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Gets the layout strategy for this form section |
|
205 | - * |
|
206 | - * @return EE_Form_Section_Layout_Base |
|
207 | - */ |
|
208 | - public function get_layout_strategy() |
|
209 | - { |
|
210 | - return $this->_layout_strategy; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Gets the HTML for a single input for this form section according |
|
216 | - * to the layout strategy |
|
217 | - * |
|
218 | - * @param EE_Form_Input_Base $input |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - public function get_html_for_input($input) |
|
222 | - { |
|
223 | - return $this->_layout_strategy->layout_input($input); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * was_submitted - checks if form inputs are present in request data |
|
229 | - * Basically an alias for form_data_present_in() (which is used by both |
|
230 | - * proper form sections and form inputs) |
|
231 | - * |
|
232 | - * @param null $form_data |
|
233 | - * @return boolean |
|
234 | - * @throws EE_Error |
|
235 | - */ |
|
236 | - public function was_submitted($form_data = null) |
|
237 | - { |
|
238 | - return $this->form_data_present_in($form_data); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
244 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
245 | - * |
|
246 | - * @param array|null $req_data should usually be $_POST (the default). |
|
247 | - * However, you CAN supply a different array. |
|
248 | - * Consider using set_defaults() instead however. |
|
249 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
250 | - * the inputs will have the correct name in the request data for this function |
|
251 | - * to find them and populate the form with them. |
|
252 | - * If you have a flat form (with only input subsections), |
|
253 | - * you can supply a flat array where keys |
|
254 | - * are the form input names and values are their values) |
|
255 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
256 | - * of course, to validate that data, and set errors on the invalid values. |
|
257 | - * But if the data has already been validated |
|
258 | - * (eg you validated the data then stored it in the DB) |
|
259 | - * you may want to skip this step. |
|
260 | - * @throws InvalidArgumentException |
|
261 | - * @throws InvalidInterfaceException |
|
262 | - * @throws InvalidDataTypeException |
|
263 | - * @throws EE_Error |
|
264 | - */ |
|
265 | - public function receive_form_submission($req_data = null, $validate = true) |
|
266 | - { |
|
267 | - $req_data = apply_filters( |
|
268 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
269 | - $req_data, |
|
270 | - $this, |
|
271 | - $validate |
|
272 | - ); |
|
273 | - if ($req_data === null) { |
|
274 | - $req_data = array_merge($_GET, $_POST); |
|
275 | - } |
|
276 | - $req_data = apply_filters( |
|
277 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
278 | - $req_data, |
|
279 | - $this |
|
280 | - ); |
|
281 | - $this->_normalize($req_data); |
|
282 | - if ($validate) { |
|
283 | - $this->_validate(); |
|
284 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
285 | - if (! $this->is_valid()) { |
|
286 | - $this->store_submitted_form_data_in_session(); |
|
287 | - } |
|
288 | - } |
|
289 | - do_action( |
|
290 | - 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
291 | - $req_data, |
|
292 | - $this, |
|
293 | - $validate |
|
294 | - ); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * caches the originally submitted input values in the session |
|
300 | - * so that they can be used to repopulate the form if it failed validation |
|
301 | - * |
|
302 | - * @return boolean whether or not the data was successfully stored in the session |
|
303 | - * @throws InvalidArgumentException |
|
304 | - * @throws InvalidInterfaceException |
|
305 | - * @throws InvalidDataTypeException |
|
306 | - * @throws EE_Error |
|
307 | - */ |
|
308 | - protected function store_submitted_form_data_in_session() |
|
309 | - { |
|
310 | - return EE_Registry::instance()->SSN->set_session_data( |
|
311 | - array( |
|
312 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
313 | - ) |
|
314 | - ); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * retrieves the originally submitted input values in the session |
|
320 | - * so that they can be used to repopulate the form if it failed validation |
|
321 | - * |
|
322 | - * @return array |
|
323 | - * @throws InvalidArgumentException |
|
324 | - * @throws InvalidInterfaceException |
|
325 | - * @throws InvalidDataTypeException |
|
326 | - */ |
|
327 | - protected function get_submitted_form_data_from_session() |
|
328 | - { |
|
329 | - $session = EE_Registry::instance()->SSN; |
|
330 | - if ($session instanceof EE_Session) { |
|
331 | - return $session->get_session_data( |
|
332 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
333 | - ); |
|
334 | - } |
|
335 | - return array(); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * flushed the originally submitted input values from the session |
|
341 | - * |
|
342 | - * @return boolean whether or not the data was successfully removed from the session |
|
343 | - * @throws InvalidArgumentException |
|
344 | - * @throws InvalidInterfaceException |
|
345 | - * @throws InvalidDataTypeException |
|
346 | - */ |
|
347 | - protected function flush_submitted_form_data_from_session() |
|
348 | - { |
|
349 | - return EE_Registry::instance()->SSN->reset_data( |
|
350 | - array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
351 | - ); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Populates this form and its subsections with data from the session. |
|
357 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
358 | - * validation errors when displaying too) |
|
359 | - * Returns true if the form was populated from the session, false otherwise |
|
360 | - * |
|
361 | - * @return boolean |
|
362 | - * @throws InvalidArgumentException |
|
363 | - * @throws InvalidInterfaceException |
|
364 | - * @throws InvalidDataTypeException |
|
365 | - * @throws EE_Error |
|
366 | - */ |
|
367 | - public function populate_from_session() |
|
368 | - { |
|
369 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
370 | - if (empty($form_data_in_session)) { |
|
371 | - return false; |
|
372 | - } |
|
373 | - $this->receive_form_submission($form_data_in_session); |
|
374 | - $this->flush_submitted_form_data_from_session(); |
|
375 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
376 | - return true; |
|
377 | - } |
|
378 | - return false; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * Populates the default data for the form, given an array where keys are |
|
384 | - * the input names, and values are their values (preferably normalized to be their |
|
385 | - * proper PHP types, not all strings... although that should be ok too). |
|
386 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
387 | - * the value being an array formatted in teh same way |
|
388 | - * |
|
389 | - * @param array $default_data |
|
390 | - * @throws EE_Error |
|
391 | - */ |
|
392 | - public function populate_defaults($default_data) |
|
393 | - { |
|
394 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
395 | - if (isset($default_data[ $subsection_name ])) { |
|
396 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
397 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
398 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
399 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
400 | - } |
|
401 | - } |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * returns true if subsection exists |
|
408 | - * |
|
409 | - * @param string $name |
|
410 | - * @return boolean |
|
411 | - */ |
|
412 | - public function subsection_exists($name) |
|
413 | - { |
|
414 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * Gets the subsection specified by its name |
|
420 | - * |
|
421 | - * @param string $name |
|
422 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
423 | - * so that the inputs will be properly configured. |
|
424 | - * However, some client code may be ok |
|
425 | - * with construction finalize being called later |
|
426 | - * (realizing that the subsections' html names |
|
427 | - * might not be set yet, etc.) |
|
428 | - * @return EE_Form_Section_Base |
|
429 | - * @throws EE_Error |
|
430 | - */ |
|
431 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
432 | - { |
|
433 | - if ($require_construction_to_be_finalized) { |
|
434 | - $this->ensure_construct_finalized_called(); |
|
435 | - } |
|
436 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * Gets all the validatable subsections of this form section |
|
442 | - * |
|
443 | - * @return EE_Form_Section_Validatable[] |
|
444 | - * @throws EE_Error |
|
445 | - */ |
|
446 | - public function get_validatable_subsections() |
|
447 | - { |
|
448 | - $validatable_subsections = array(); |
|
449 | - foreach ($this->subsections() as $name => $obj) { |
|
450 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
451 | - $validatable_subsections[ $name ] = $obj; |
|
452 | - } |
|
453 | - } |
|
454 | - return $validatable_subsections; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
460 | - * throw an EE_Error. |
|
461 | - * |
|
462 | - * @param string $name |
|
463 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
464 | - * leave this as TRUE so that the inputs will be properly |
|
465 | - * configured. However, some client code may be ok with |
|
466 | - * construction finalize being called later |
|
467 | - * (realizing that the subsections' html names might not be |
|
468 | - * set yet, etc.) |
|
469 | - * @return EE_Form_Input_Base |
|
470 | - * @throws EE_Error |
|
471 | - */ |
|
472 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
473 | - { |
|
474 | - $subsection = $this->get_subsection( |
|
475 | - $name, |
|
476 | - $require_construction_to_be_finalized |
|
477 | - ); |
|
478 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
479 | - throw new EE_Error( |
|
480 | - sprintf( |
|
481 | - esc_html__( |
|
482 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
483 | - 'event_espresso' |
|
484 | - ), |
|
485 | - $name, |
|
486 | - get_class($this), |
|
487 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
488 | - ) |
|
489 | - ); |
|
490 | - } |
|
491 | - return $subsection; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
497 | - * otherwise throws an EE_Error |
|
498 | - * |
|
499 | - * @param string $name |
|
500 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
501 | - * leave this as TRUE so that the inputs will be properly |
|
502 | - * configured. However, some client code may be ok with |
|
503 | - * construction finalize being called later |
|
504 | - * (realizing that the subsections' html names might not be |
|
505 | - * set yet, etc.) |
|
506 | - * @return EE_Form_Section_Proper |
|
507 | - * @throws EE_Error |
|
508 | - */ |
|
509 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
510 | - { |
|
511 | - $subsection = $this->get_subsection( |
|
512 | - $name, |
|
513 | - $require_construction_to_be_finalized |
|
514 | - ); |
|
515 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
516 | - throw new EE_Error( |
|
517 | - sprintf( |
|
518 | - esc_html__( |
|
519 | - "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
520 | - 'event_espresso' |
|
521 | - ), |
|
522 | - $name, |
|
523 | - get_class($this) |
|
524 | - ) |
|
525 | - ); |
|
526 | - } |
|
527 | - return $subsection; |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - /** |
|
532 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
533 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
534 | - * |
|
535 | - * @param string $name |
|
536 | - * @return mixed depending on the input's type and its normalization strategy |
|
537 | - * @throws EE_Error |
|
538 | - */ |
|
539 | - public function get_input_value($name) |
|
540 | - { |
|
541 | - $input = $this->get_input($name); |
|
542 | - return $input->normalized_value(); |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * Checks if this form section itself is valid, and then checks its subsections |
|
548 | - * |
|
549 | - * @throws EE_Error |
|
550 | - * @return boolean |
|
551 | - */ |
|
552 | - public function is_valid() |
|
553 | - { |
|
554 | - if (! $this->has_received_submission()) { |
|
555 | - throw new EE_Error( |
|
556 | - sprintf( |
|
557 | - esc_html__( |
|
558 | - 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
559 | - 'event_espresso' |
|
560 | - ) |
|
561 | - ) |
|
562 | - ); |
|
563 | - } |
|
564 | - if (! parent::is_valid()) { |
|
565 | - return false; |
|
566 | - } |
|
567 | - // ok so no general errors to this entire form section. |
|
568 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
569 | - $set_submission_errors = $this->submission_error_message() === ''; |
|
570 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
571 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
572 | - if ($set_submission_errors) { |
|
573 | - $this->set_submission_error_message( |
|
574 | - $subsection->get_validation_error_string() |
|
575 | - ); |
|
576 | - } |
|
577 | - return false; |
|
578 | - } |
|
579 | - } |
|
580 | - return true; |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * gets the default name of this form section if none is specified |
|
586 | - * |
|
587 | - * @return void |
|
588 | - */ |
|
589 | - protected function _set_default_name_if_empty() |
|
590 | - { |
|
591 | - if (! $this->_name) { |
|
592 | - $classname = get_class($this); |
|
593 | - $default_name = str_replace('EE_', '', $classname); |
|
594 | - $this->_name = $default_name; |
|
595 | - } |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
601 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
602 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
603 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
604 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
605 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
606 | - * any CSS. |
|
607 | - * |
|
608 | - * @throws InvalidArgumentException |
|
609 | - * @throws InvalidInterfaceException |
|
610 | - * @throws InvalidDataTypeException |
|
611 | - * @throws EE_Error |
|
612 | - */ |
|
613 | - public function get_html_and_js() |
|
614 | - { |
|
615 | - $this->enqueue_js(); |
|
616 | - return $this->get_html(); |
|
617 | - } |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
622 | - * |
|
623 | - * @param bool $display_previously_submitted_data |
|
624 | - * @return string |
|
625 | - * @throws InvalidArgumentException |
|
626 | - * @throws InvalidInterfaceException |
|
627 | - * @throws InvalidDataTypeException |
|
628 | - * @throws EE_Error |
|
629 | - * @throws EE_Error |
|
630 | - * @throws EE_Error |
|
631 | - */ |
|
632 | - public function get_html($display_previously_submitted_data = true) |
|
633 | - { |
|
634 | - $this->ensure_construct_finalized_called(); |
|
635 | - if ($display_previously_submitted_data) { |
|
636 | - $this->populate_from_session(); |
|
637 | - } |
|
638 | - return $this->_form_html_filter |
|
639 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
640 | - : $this->_layout_strategy->layout_form(); |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * enqueues JS and CSS for the form. |
|
646 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
647 | - * scripts and styles can be put in the header, but if called later |
|
648 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
649 | - * only be in the header; but in HTML5 its ok in the body. |
|
650 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
651 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
652 | - * |
|
653 | - * @return void |
|
654 | - * @throws EE_Error |
|
655 | - */ |
|
656 | - public function enqueue_js() |
|
657 | - { |
|
658 | - $this->_enqueue_and_localize_form_js(); |
|
659 | - foreach ($this->subsections() as $subsection) { |
|
660 | - $subsection->enqueue_js(); |
|
661 | - } |
|
662 | - } |
|
663 | - |
|
664 | - |
|
665 | - /** |
|
666 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
667 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
668 | - * the wp_enqueue_scripts hook. |
|
669 | - * However, registering the form js and localizing it can happen when we |
|
670 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
671 | - * could change until it's actually outputted) |
|
672 | - * |
|
673 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
674 | - * to be triggered automatically or not |
|
675 | - * @return void |
|
676 | - */ |
|
677 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
678 | - { |
|
679 | - wp_register_script( |
|
680 | - 'ee_form_section_validation', |
|
681 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
682 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
683 | - EVENT_ESPRESSO_VERSION, |
|
684 | - true |
|
685 | - ); |
|
686 | - wp_localize_script( |
|
687 | - 'ee_form_section_validation', |
|
688 | - 'ee_form_section_validation_init', |
|
689 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
690 | - ); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * gets the variables used by form_section_validation.js. |
|
696 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
697 | - * but before the wordpress hook wp_loaded |
|
698 | - * |
|
699 | - * @throws EE_Error |
|
700 | - */ |
|
701 | - public function _enqueue_and_localize_form_js() |
|
702 | - { |
|
703 | - $this->ensure_construct_finalized_called(); |
|
704 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
705 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
706 | - //and localize it just before the footer |
|
707 | - $this->localize_validation_rules(); |
|
708 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
709 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
710 | - } |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * add our form section data to a static variable accessible by all form sections |
|
715 | - * |
|
716 | - * @param bool $return_for_subsection |
|
717 | - * @return void |
|
718 | - * @throws EE_Error |
|
719 | - */ |
|
720 | - public function localize_validation_rules($return_for_subsection = false) |
|
721 | - { |
|
722 | - // we only want to localize vars ONCE for the entire form, |
|
723 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
724 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
725 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
726 | - 'form_section_id' => $this->html_id(true), |
|
727 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
728 | - 'other_data' => $this->get_other_js_data(), |
|
729 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
730 | - ); |
|
731 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
738 | - * This is primarily data added by inputs and forms in addition to any |
|
739 | - * scripts they might enqueue |
|
740 | - * |
|
741 | - * @param array $form_other_js_data |
|
742 | - * @return array |
|
743 | - * @throws EE_Error |
|
744 | - */ |
|
745 | - public function get_other_js_data($form_other_js_data = array()) |
|
746 | - { |
|
747 | - foreach ($this->subsections() as $subsection) { |
|
748 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
749 | - } |
|
750 | - return $form_other_js_data; |
|
751 | - } |
|
752 | - |
|
753 | - |
|
754 | - /** |
|
755 | - * Gets a flat array of inputs for this form section and its subsections. |
|
756 | - * Keys are their form names, and values are the inputs themselves |
|
757 | - * |
|
758 | - * @return EE_Form_Input_Base |
|
759 | - * @throws EE_Error |
|
760 | - */ |
|
761 | - public function inputs_in_subsections() |
|
762 | - { |
|
763 | - $inputs = array(); |
|
764 | - foreach ($this->subsections() as $subsection) { |
|
765 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
766 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
767 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
768 | - $inputs += $subsection->inputs_in_subsections(); |
|
769 | - } |
|
770 | - } |
|
771 | - return $inputs; |
|
772 | - } |
|
773 | - |
|
774 | - |
|
775 | - /** |
|
776 | - * Gets a flat array of all the validation errors. |
|
777 | - * Keys are html names (because those should be unique) |
|
778 | - * and values are a string of all their validation errors |
|
779 | - * |
|
780 | - * @return string[] |
|
781 | - * @throws EE_Error |
|
782 | - */ |
|
783 | - public function subsection_validation_errors_by_html_name() |
|
784 | - { |
|
785 | - $inputs = $this->inputs(); |
|
786 | - $errors = array(); |
|
787 | - foreach ($inputs as $form_input) { |
|
788 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
789 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
790 | - } |
|
791 | - } |
|
792 | - return $errors; |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
798 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
799 | - * |
|
800 | - * @throws InvalidArgumentException |
|
801 | - * @throws InvalidInterfaceException |
|
802 | - * @throws InvalidDataTypeException |
|
803 | - */ |
|
804 | - public static function localize_script_for_all_forms() |
|
805 | - { |
|
806 | - //allow inputs and stuff to hook in their JS and stuff here |
|
807 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
808 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
809 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
810 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
811 | - : 'wp_default'; |
|
812 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
813 | - wp_enqueue_script('ee_form_section_validation'); |
|
814 | - wp_localize_script( |
|
815 | - 'ee_form_section_validation', |
|
816 | - 'ee_form_section_vars', |
|
817 | - EE_Form_Section_Proper::$_js_localization |
|
818 | - ); |
|
819 | - } |
|
820 | - |
|
821 | - |
|
822 | - /** |
|
823 | - * ensure_scripts_localized |
|
824 | - * |
|
825 | - * @throws EE_Error |
|
826 | - */ |
|
827 | - public function ensure_scripts_localized() |
|
828 | - { |
|
829 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
830 | - $this->_enqueue_and_localize_form_js(); |
|
831 | - } |
|
832 | - } |
|
833 | - |
|
834 | - |
|
835 | - /** |
|
836 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
837 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
838 | - * |
|
839 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
840 | - */ |
|
841 | - private static function _get_localized_error_messages() |
|
842 | - { |
|
843 | - return array( |
|
844 | - 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
845 | - 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
846 | - ); |
|
847 | - } |
|
848 | - |
|
849 | - |
|
850 | - /** |
|
851 | - * @return array |
|
852 | - */ |
|
853 | - public static function js_localization() |
|
854 | - { |
|
855 | - return self::$_js_localization; |
|
856 | - } |
|
857 | - |
|
858 | - |
|
859 | - /** |
|
860 | - * @return void |
|
861 | - */ |
|
862 | - public static function reset_js_localization() |
|
863 | - { |
|
864 | - self::$_js_localization = array(); |
|
865 | - } |
|
866 | - |
|
867 | - |
|
868 | - /** |
|
869 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
870 | - * See parent function for more... |
|
871 | - * |
|
872 | - * @return array |
|
873 | - * @throws EE_Error |
|
874 | - */ |
|
875 | - public function get_jquery_validation_rules() |
|
876 | - { |
|
877 | - $jquery_validation_rules = array(); |
|
878 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
879 | - $jquery_validation_rules = array_merge( |
|
880 | - $jquery_validation_rules, |
|
881 | - $subsection->get_jquery_validation_rules() |
|
882 | - ); |
|
883 | - } |
|
884 | - return $jquery_validation_rules; |
|
885 | - } |
|
886 | - |
|
887 | - |
|
888 | - /** |
|
889 | - * Sanitizes all the data and sets the sanitized value of each field |
|
890 | - * |
|
891 | - * @param array $req_data like $_POST |
|
892 | - * @return void |
|
893 | - * @throws EE_Error |
|
894 | - */ |
|
895 | - protected function _normalize($req_data) |
|
896 | - { |
|
897 | - $this->_received_submission = true; |
|
898 | - $this->_validation_errors = array(); |
|
899 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
900 | - try { |
|
901 | - $subsection->_normalize($req_data); |
|
902 | - } catch (EE_Validation_Error $e) { |
|
903 | - $subsection->add_validation_error($e); |
|
904 | - } |
|
905 | - } |
|
906 | - } |
|
907 | - |
|
908 | - |
|
909 | - /** |
|
910 | - * Performs validation on this form section and its subsections. |
|
911 | - * For each subsection, |
|
912 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
913 | - * and passes it the subsection, then calls _validate on that subsection. |
|
914 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
915 | - * you would be best to override this _validate method, |
|
916 | - * calling parent::_validate() first. |
|
917 | - * |
|
918 | - * @throws EE_Error |
|
919 | - */ |
|
920 | - protected function _validate() |
|
921 | - { |
|
922 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
923 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
924 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
925 | - } |
|
926 | - $subsection->_validate(); |
|
927 | - } |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * Gets all the validated inputs for the form section |
|
933 | - * |
|
934 | - * @return array |
|
935 | - * @throws EE_Error |
|
936 | - */ |
|
937 | - public function valid_data() |
|
938 | - { |
|
939 | - $inputs = array(); |
|
940 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
941 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
942 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
943 | - } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
944 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
945 | - } |
|
946 | - } |
|
947 | - return $inputs; |
|
948 | - } |
|
949 | - |
|
950 | - |
|
951 | - /** |
|
952 | - * Gets all the inputs on this form section |
|
953 | - * |
|
954 | - * @return EE_Form_Input_Base[] |
|
955 | - * @throws EE_Error |
|
956 | - */ |
|
957 | - public function inputs() |
|
958 | - { |
|
959 | - $inputs = array(); |
|
960 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
961 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
962 | - $inputs[ $subsection_name ] = $subsection; |
|
963 | - } |
|
964 | - } |
|
965 | - return $inputs; |
|
966 | - } |
|
967 | - |
|
968 | - |
|
969 | - /** |
|
970 | - * Gets all the subsections which are a proper form |
|
971 | - * |
|
972 | - * @return EE_Form_Section_Proper[] |
|
973 | - * @throws EE_Error |
|
974 | - */ |
|
975 | - public function subforms() |
|
976 | - { |
|
977 | - $form_sections = array(); |
|
978 | - foreach ($this->subsections() as $name => $obj) { |
|
979 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
980 | - $form_sections[ $name ] = $obj; |
|
981 | - } |
|
982 | - } |
|
983 | - return $form_sections; |
|
984 | - } |
|
985 | - |
|
986 | - |
|
987 | - /** |
|
988 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
989 | - * Consider using inputs() or subforms() |
|
990 | - * if you only want form inputs or proper form sections. |
|
991 | - * |
|
992 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
993 | - * leave this as TRUE so that the inputs will be properly |
|
994 | - * configured. However, some client code may be ok with |
|
995 | - * construction finalize being called later |
|
996 | - * (realizing that the subsections' html names might not be |
|
997 | - * set yet, etc.) |
|
998 | - * @return EE_Form_Section_Proper[] |
|
999 | - * @throws EE_Error |
|
1000 | - */ |
|
1001 | - public function subsections($require_construction_to_be_finalized = true) |
|
1002 | - { |
|
1003 | - if ($require_construction_to_be_finalized) { |
|
1004 | - $this->ensure_construct_finalized_called(); |
|
1005 | - } |
|
1006 | - return $this->_subsections; |
|
1007 | - } |
|
1008 | - |
|
1009 | - |
|
1010 | - /** |
|
1011 | - * Returns a simple array where keys are input names, and values are their normalized |
|
1012 | - * values. (Similar to calling get_input_value on inputs) |
|
1013 | - * |
|
1014 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1015 | - * or just this forms' direct children inputs |
|
1016 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1017 | - * or allow multidimensional array |
|
1018 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1019 | - * with array keys being input names |
|
1020 | - * (regardless of whether they are from a subsection or not), |
|
1021 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1022 | - * where keys are always subsection names and values are either |
|
1023 | - * the input's normalized value, or an array like the top-level array |
|
1024 | - * @throws EE_Error |
|
1025 | - */ |
|
1026 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
1027 | - { |
|
1028 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1029 | - } |
|
1030 | - |
|
1031 | - |
|
1032 | - /** |
|
1033 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1034 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1035 | - * is not necessarily the value we want to display to users. This creates an array |
|
1036 | - * where keys are the input names, and values are their display values |
|
1037 | - * |
|
1038 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1039 | - * or just this forms' direct children inputs |
|
1040 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1041 | - * or allow multidimensional array |
|
1042 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1043 | - * with array keys being input names |
|
1044 | - * (regardless of whether they are from a subsection or not), |
|
1045 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1046 | - * where keys are always subsection names and values are either |
|
1047 | - * the input's normalized value, or an array like the top-level array |
|
1048 | - * @throws EE_Error |
|
1049 | - */ |
|
1050 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1051 | - { |
|
1052 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1053 | - } |
|
1054 | - |
|
1055 | - |
|
1056 | - /** |
|
1057 | - * Gets the input values from the form |
|
1058 | - * |
|
1059 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
1060 | - * or just the normalized value |
|
1061 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1062 | - * or just this forms' direct children inputs |
|
1063 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1064 | - * or allow multidimensional array |
|
1065 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1066 | - * input names (regardless of whether they are from a subsection or not), |
|
1067 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1068 | - * where keys are always subsection names and values are either |
|
1069 | - * the input's normalized value, or an array like the top-level array |
|
1070 | - * @throws EE_Error |
|
1071 | - */ |
|
1072 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1073 | - { |
|
1074 | - $input_values = array(); |
|
1075 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1076 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1077 | - $input_values[ $subsection_name ] = $pretty |
|
1078 | - ? $subsection->pretty_value() |
|
1079 | - : $subsection->normalized_value(); |
|
1080 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1081 | - $subform_input_values = $subsection->_input_values( |
|
1082 | - $pretty, |
|
1083 | - $include_subform_inputs, |
|
1084 | - $flatten |
|
1085 | - ); |
|
1086 | - if ($flatten) { |
|
1087 | - $input_values = array_merge($input_values, $subform_input_values); |
|
1088 | - } else { |
|
1089 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
1090 | - } |
|
1091 | - } |
|
1092 | - } |
|
1093 | - return $input_values; |
|
1094 | - } |
|
1095 | - |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * Gets the originally submitted input values from the form |
|
1099 | - * |
|
1100 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1101 | - * or just this forms' direct children inputs |
|
1102 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1103 | - * with array keys being input names |
|
1104 | - * (regardless of whether they are from a subsection or not), |
|
1105 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1106 | - * where keys are always subsection names and values are either |
|
1107 | - * the input's normalized value, or an array like the top-level array |
|
1108 | - * @throws EE_Error |
|
1109 | - */ |
|
1110 | - public function submitted_values($include_subforms = false) |
|
1111 | - { |
|
1112 | - $submitted_values = array(); |
|
1113 | - foreach ($this->subsections() as $subsection) { |
|
1114 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1115 | - // is this input part of an array of inputs? |
|
1116 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
1117 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1118 | - explode( |
|
1119 | - '[', |
|
1120 | - str_replace(']', '', $subsection->html_name()) |
|
1121 | - ), |
|
1122 | - $subsection->raw_value() |
|
1123 | - ); |
|
1124 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1125 | - } else { |
|
1126 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1127 | - } |
|
1128 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1129 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1130 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1131 | - } |
|
1132 | - } |
|
1133 | - return $submitted_values; |
|
1134 | - } |
|
1135 | - |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * Indicates whether or not this form has received a submission yet |
|
1139 | - * (ie, had receive_form_submission called on it yet) |
|
1140 | - * |
|
1141 | - * @return boolean |
|
1142 | - * @throws EE_Error |
|
1143 | - */ |
|
1144 | - public function has_received_submission() |
|
1145 | - { |
|
1146 | - $this->ensure_construct_finalized_called(); |
|
1147 | - return $this->_received_submission; |
|
1148 | - } |
|
1149 | - |
|
1150 | - |
|
1151 | - /** |
|
1152 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
1153 | - * Removes the listed inputs from the form |
|
1154 | - * |
|
1155 | - * @param array $inputs_to_exclude values are the input names |
|
1156 | - * @return void |
|
1157 | - */ |
|
1158 | - public function exclude(array $inputs_to_exclude = array()) |
|
1159 | - { |
|
1160 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1161 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
1162 | - } |
|
1163 | - } |
|
1164 | - |
|
1165 | - |
|
1166 | - /** |
|
1167 | - * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
1168 | - * @param array $inputs_to_hide |
|
1169 | - * @throws EE_Error |
|
1170 | - */ |
|
1171 | - public function hide(array $inputs_to_hide = array()) |
|
1172 | - { |
|
1173 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
1174 | - $input = $this->get_input($input_to_hide); |
|
1175 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1176 | - } |
|
1177 | - } |
|
1178 | - |
|
1179 | - |
|
1180 | - /** |
|
1181 | - * add_subsections |
|
1182 | - * Adds the listed subsections to the form section. |
|
1183 | - * If $subsection_name_to_target is provided, |
|
1184 | - * then new subsections are added before or after that subsection, |
|
1185 | - * otherwise to the start or end of the entire subsections array. |
|
1186 | - * |
|
1187 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1188 | - * where keys are their names |
|
1189 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1190 | - * should be added before or after |
|
1191 | - * IF $subsection_name_to_target is null, |
|
1192 | - * then $new_subsections will be added to |
|
1193 | - * the beginning or end of the entire subsections array |
|
1194 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
1195 | - * $subsection_name_to_target, |
|
1196 | - * or if $subsection_name_to_target is null, |
|
1197 | - * before or after entire subsections array |
|
1198 | - * @return void |
|
1199 | - * @throws EE_Error |
|
1200 | - */ |
|
1201 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1202 | - { |
|
1203 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
1204 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1205 | - EE_Error::add_error( |
|
1206 | - sprintf( |
|
1207 | - esc_html__( |
|
1208 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1209 | - 'event_espresso' |
|
1210 | - ), |
|
1211 | - get_class($subsection), |
|
1212 | - $subsection_name, |
|
1213 | - $this->name() |
|
1214 | - ) |
|
1215 | - ); |
|
1216 | - unset($new_subsections[ $subsection_name ]); |
|
1217 | - } |
|
1218 | - } |
|
1219 | - $this->_subsections = EEH_Array::insert_into_array( |
|
1220 | - $this->_subsections, |
|
1221 | - $new_subsections, |
|
1222 | - $subsection_name_to_target, |
|
1223 | - $add_before |
|
1224 | - ); |
|
1225 | - if ($this->_construction_finalized) { |
|
1226 | - foreach ($this->_subsections as $name => $subsection) { |
|
1227 | - $subsection->_construct_finalize($this, $name); |
|
1228 | - } |
|
1229 | - } |
|
1230 | - } |
|
1231 | - |
|
1232 | - |
|
1233 | - /** |
|
1234 | - * Just gets all validatable subsections to clean their sensitive data |
|
1235 | - * |
|
1236 | - * @throws EE_Error |
|
1237 | - */ |
|
1238 | - public function clean_sensitive_data() |
|
1239 | - { |
|
1240 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1241 | - $subsection->clean_sensitive_data(); |
|
1242 | - } |
|
1243 | - } |
|
1244 | - |
|
1245 | - |
|
1246 | - /** |
|
1247 | - * @param string $form_submission_error_message |
|
1248 | - */ |
|
1249 | - public function set_submission_error_message($form_submission_error_message = '') |
|
1250 | - { |
|
1251 | - $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
1252 | - ? $form_submission_error_message |
|
1253 | - : esc_html__('Form submission failed due to errors', 'event_espresso'); |
|
1254 | - } |
|
1255 | - |
|
1256 | - |
|
1257 | - /** |
|
1258 | - * @return string |
|
1259 | - */ |
|
1260 | - public function submission_error_message() |
|
1261 | - { |
|
1262 | - return $this->_form_submission_error_message; |
|
1263 | - } |
|
1264 | - |
|
1265 | - |
|
1266 | - /** |
|
1267 | - * @param string $form_submission_success_message |
|
1268 | - */ |
|
1269 | - public function set_submission_success_message($form_submission_success_message) |
|
1270 | - { |
|
1271 | - $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
1272 | - ? $form_submission_success_message |
|
1273 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1274 | - } |
|
1275 | - |
|
1276 | - |
|
1277 | - /** |
|
1278 | - * @return string |
|
1279 | - */ |
|
1280 | - public function submission_success_message() |
|
1281 | - { |
|
1282 | - return $this->_form_submission_success_message; |
|
1283 | - } |
|
1284 | - |
|
1285 | - |
|
1286 | - /** |
|
1287 | - * Returns the prefix that should be used on child of this form section for |
|
1288 | - * their html names. If this form section itself has a parent, prepends ITS |
|
1289 | - * prefix onto this form section's prefix. Used primarily by |
|
1290 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1291 | - * |
|
1292 | - * @return string |
|
1293 | - * @throws EE_Error |
|
1294 | - */ |
|
1295 | - public function html_name_prefix() |
|
1296 | - { |
|
1297 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1298 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1299 | - } |
|
1300 | - return $this->name(); |
|
1301 | - } |
|
1302 | - |
|
1303 | - |
|
1304 | - /** |
|
1305 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1306 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
1307 | - * was set, which is probably nothing, or the classname) |
|
1308 | - * |
|
1309 | - * @return string |
|
1310 | - * @throws EE_Error |
|
1311 | - */ |
|
1312 | - public function name() |
|
1313 | - { |
|
1314 | - $this->ensure_construct_finalized_called(); |
|
1315 | - return parent::name(); |
|
1316 | - } |
|
1317 | - |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * @return EE_Form_Section_Proper |
|
1321 | - * @throws EE_Error |
|
1322 | - */ |
|
1323 | - public function parent_section() |
|
1324 | - { |
|
1325 | - $this->ensure_construct_finalized_called(); |
|
1326 | - return parent::parent_section(); |
|
1327 | - } |
|
1328 | - |
|
1329 | - |
|
1330 | - /** |
|
1331 | - * make sure construction finalized was called, otherwise children might not be ready |
|
1332 | - * |
|
1333 | - * @return void |
|
1334 | - * @throws EE_Error |
|
1335 | - */ |
|
1336 | - public function ensure_construct_finalized_called() |
|
1337 | - { |
|
1338 | - if (! $this->_construction_finalized) { |
|
1339 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1340 | - } |
|
1341 | - } |
|
1342 | - |
|
1343 | - |
|
1344 | - /** |
|
1345 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1346 | - * are in teh form data. If any are found, returns true. Else false |
|
1347 | - * |
|
1348 | - * @param array $req_data |
|
1349 | - * @return boolean |
|
1350 | - * @throws EE_Error |
|
1351 | - */ |
|
1352 | - public function form_data_present_in($req_data = null) |
|
1353 | - { |
|
1354 | - if ($req_data === null) { |
|
1355 | - $req_data = $_POST; |
|
1356 | - } |
|
1357 | - foreach ($this->subsections() as $subsection) { |
|
1358 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1359 | - if ($subsection->form_data_present_in($req_data)) { |
|
1360 | - return true; |
|
1361 | - } |
|
1362 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1363 | - if ($subsection->form_data_present_in($req_data)) { |
|
1364 | - return true; |
|
1365 | - } |
|
1366 | - } |
|
1367 | - } |
|
1368 | - return false; |
|
1369 | - } |
|
1370 | - |
|
1371 | - |
|
1372 | - /** |
|
1373 | - * Gets validation errors for this form section and subsections |
|
1374 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1375 | - * gets the validation errors for ALL subsection |
|
1376 | - * |
|
1377 | - * @return EE_Validation_Error[] |
|
1378 | - * @throws EE_Error |
|
1379 | - */ |
|
1380 | - public function get_validation_errors_accumulated() |
|
1381 | - { |
|
1382 | - $validation_errors = $this->get_validation_errors(); |
|
1383 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1384 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
1385 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1386 | - } else { |
|
1387 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1388 | - } |
|
1389 | - if ($validation_errors_on_this_subsection) { |
|
1390 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1391 | - } |
|
1392 | - } |
|
1393 | - return $validation_errors; |
|
1394 | - } |
|
1395 | - |
|
1396 | - |
|
1397 | - /** |
|
1398 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
1399 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1400 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
1401 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1402 | - * which will be returned. |
|
1403 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1404 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1405 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1406 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1407 | - * Etc |
|
1408 | - * |
|
1409 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1410 | - * @return EE_Form_Section_Base |
|
1411 | - * @throws EE_Error |
|
1412 | - */ |
|
1413 | - public function find_section_from_path($form_section_path) |
|
1414 | - { |
|
1415 | - //check if we can find the input from purely going straight up the tree |
|
1416 | - $input = parent::find_section_from_path($form_section_path); |
|
1417 | - if ($input instanceof EE_Form_Section_Base) { |
|
1418 | - return $input; |
|
1419 | - } |
|
1420 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
1421 | - if ($next_slash_pos !== false) { |
|
1422 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1423 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1424 | - } else { |
|
1425 | - $child_section_name = $form_section_path; |
|
1426 | - $subpath = ''; |
|
1427 | - } |
|
1428 | - $child_section = $this->get_subsection($child_section_name); |
|
1429 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
1430 | - return $child_section->find_section_from_path($subpath); |
|
1431 | - } |
|
1432 | - return null; |
|
1433 | - } |
|
17 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
18 | + |
|
19 | + /** |
|
20 | + * Subsections |
|
21 | + * |
|
22 | + * @var EE_Form_Section_Validatable[] |
|
23 | + */ |
|
24 | + protected $_subsections = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * Strategy for laying out the form |
|
28 | + * |
|
29 | + * @var EE_Form_Section_Layout_Base |
|
30 | + */ |
|
31 | + protected $_layout_strategy; |
|
32 | + |
|
33 | + /** |
|
34 | + * Whether or not this form has received and validated a form submission yet |
|
35 | + * |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + protected $_received_submission = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * message displayed to users upon successful form submission |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + protected $_form_submission_success_message = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * message displayed to users upon unsuccessful form submission |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_form_submission_error_message = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * Stores all the data that will localized for form validation |
|
56 | + * |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + static protected $_js_localization = array(); |
|
60 | + |
|
61 | + /** |
|
62 | + * whether or not the form's localized validation JS vars have been set |
|
63 | + * |
|
64 | + * @type boolean |
|
65 | + */ |
|
66 | + static protected $_scripts_localized = false; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * when constructing a proper form section, calls _construct_finalize on children |
|
71 | + * so that they know who their parent is, and what name they've been given. |
|
72 | + * |
|
73 | + * @param array[] $options_array { |
|
74 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
75 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
76 | + * and in that order. This is handy if you want |
|
77 | + * the subsections to be ordered differently than the default, and if you override |
|
78 | + * which fields are shown |
|
79 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
80 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
81 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
82 | + * items from that list of inclusions) |
|
83 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
84 | + * } @see EE_Form_Section_Validatable::__construct() |
|
85 | + * @throws EE_Error |
|
86 | + */ |
|
87 | + public function __construct($options_array = array()) |
|
88 | + { |
|
89 | + $options_array = (array) apply_filters( |
|
90 | + 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
91 | + $options_array, |
|
92 | + $this |
|
93 | + ); |
|
94 | + //call parent first, as it may be setting the name |
|
95 | + parent::__construct($options_array); |
|
96 | + //if they've included subsections in the constructor, add them now |
|
97 | + if (isset($options_array['include'])) { |
|
98 | + //we are going to make sure we ONLY have those subsections to include |
|
99 | + //AND we are going to make sure they're in that specified order |
|
100 | + $reordered_subsections = array(); |
|
101 | + foreach ($options_array['include'] as $input_name) { |
|
102 | + if (isset($this->_subsections[ $input_name ])) { |
|
103 | + $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
104 | + } |
|
105 | + } |
|
106 | + $this->_subsections = $reordered_subsections; |
|
107 | + } |
|
108 | + if (isset($options_array['exclude'])) { |
|
109 | + $exclude = $options_array['exclude']; |
|
110 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
111 | + } |
|
112 | + if (isset($options_array['layout_strategy'])) { |
|
113 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
114 | + } |
|
115 | + if (! $this->_layout_strategy) { |
|
116 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
117 | + } |
|
118 | + $this->_layout_strategy->_construct_finalize($this); |
|
119 | + //ok so we are definitely going to want the forms JS, |
|
120 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
121 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
122 | + //ok so they've constructed this object after when they should have. |
|
123 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
124 | + EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
125 | + } else { |
|
126 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
127 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
128 | + } |
|
129 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
130 | + /** |
|
131 | + * Gives other plugins a chance to hook in before construct finalize is called. |
|
132 | + * The form probably doesn't yet have a parent form section. |
|
133 | + * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
134 | + * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
135 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
136 | + * |
|
137 | + * @since 4.9.32 |
|
138 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
139 | + * except maybe calling _construct_finalize has been done |
|
140 | + * @param array $options_array options passed into the constructor |
|
141 | + */ |
|
142 | + do_action( |
|
143 | + 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
144 | + $this, |
|
145 | + $options_array |
|
146 | + ); |
|
147 | + if (isset($options_array['name'])) { |
|
148 | + $this->_construct_finalize(null, $options_array['name']); |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * Finishes construction given the parent form section and this form section's name |
|
155 | + * |
|
156 | + * @param EE_Form_Section_Proper $parent_form_section |
|
157 | + * @param string $name |
|
158 | + * @throws EE_Error |
|
159 | + */ |
|
160 | + public function _construct_finalize($parent_form_section, $name) |
|
161 | + { |
|
162 | + parent::_construct_finalize($parent_form_section, $name); |
|
163 | + $this->_set_default_name_if_empty(); |
|
164 | + $this->_set_default_html_id_if_empty(); |
|
165 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
166 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
167 | + $subsection->_construct_finalize($this, $subsection_name); |
|
168 | + } else { |
|
169 | + throw new EE_Error( |
|
170 | + sprintf( |
|
171 | + esc_html__( |
|
172 | + 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
173 | + 'event_espresso' |
|
174 | + ), |
|
175 | + $subsection_name, |
|
176 | + get_class($this), |
|
177 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
178 | + ) |
|
179 | + ); |
|
180 | + } |
|
181 | + } |
|
182 | + /** |
|
183 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
184 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
185 | + * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
186 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
187 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
188 | + * ensured it has a name, HTML IDs, etc |
|
189 | + * |
|
190 | + * @param EE_Form_Section_Proper $this |
|
191 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
192 | + * @param string $name |
|
193 | + */ |
|
194 | + do_action( |
|
195 | + 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
196 | + $this, |
|
197 | + $parent_form_section, |
|
198 | + $name |
|
199 | + ); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Gets the layout strategy for this form section |
|
205 | + * |
|
206 | + * @return EE_Form_Section_Layout_Base |
|
207 | + */ |
|
208 | + public function get_layout_strategy() |
|
209 | + { |
|
210 | + return $this->_layout_strategy; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Gets the HTML for a single input for this form section according |
|
216 | + * to the layout strategy |
|
217 | + * |
|
218 | + * @param EE_Form_Input_Base $input |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + public function get_html_for_input($input) |
|
222 | + { |
|
223 | + return $this->_layout_strategy->layout_input($input); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * was_submitted - checks if form inputs are present in request data |
|
229 | + * Basically an alias for form_data_present_in() (which is used by both |
|
230 | + * proper form sections and form inputs) |
|
231 | + * |
|
232 | + * @param null $form_data |
|
233 | + * @return boolean |
|
234 | + * @throws EE_Error |
|
235 | + */ |
|
236 | + public function was_submitted($form_data = null) |
|
237 | + { |
|
238 | + return $this->form_data_present_in($form_data); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
244 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
245 | + * |
|
246 | + * @param array|null $req_data should usually be $_POST (the default). |
|
247 | + * However, you CAN supply a different array. |
|
248 | + * Consider using set_defaults() instead however. |
|
249 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
250 | + * the inputs will have the correct name in the request data for this function |
|
251 | + * to find them and populate the form with them. |
|
252 | + * If you have a flat form (with only input subsections), |
|
253 | + * you can supply a flat array where keys |
|
254 | + * are the form input names and values are their values) |
|
255 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
256 | + * of course, to validate that data, and set errors on the invalid values. |
|
257 | + * But if the data has already been validated |
|
258 | + * (eg you validated the data then stored it in the DB) |
|
259 | + * you may want to skip this step. |
|
260 | + * @throws InvalidArgumentException |
|
261 | + * @throws InvalidInterfaceException |
|
262 | + * @throws InvalidDataTypeException |
|
263 | + * @throws EE_Error |
|
264 | + */ |
|
265 | + public function receive_form_submission($req_data = null, $validate = true) |
|
266 | + { |
|
267 | + $req_data = apply_filters( |
|
268 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
269 | + $req_data, |
|
270 | + $this, |
|
271 | + $validate |
|
272 | + ); |
|
273 | + if ($req_data === null) { |
|
274 | + $req_data = array_merge($_GET, $_POST); |
|
275 | + } |
|
276 | + $req_data = apply_filters( |
|
277 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
278 | + $req_data, |
|
279 | + $this |
|
280 | + ); |
|
281 | + $this->_normalize($req_data); |
|
282 | + if ($validate) { |
|
283 | + $this->_validate(); |
|
284 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
285 | + if (! $this->is_valid()) { |
|
286 | + $this->store_submitted_form_data_in_session(); |
|
287 | + } |
|
288 | + } |
|
289 | + do_action( |
|
290 | + 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
291 | + $req_data, |
|
292 | + $this, |
|
293 | + $validate |
|
294 | + ); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * caches the originally submitted input values in the session |
|
300 | + * so that they can be used to repopulate the form if it failed validation |
|
301 | + * |
|
302 | + * @return boolean whether or not the data was successfully stored in the session |
|
303 | + * @throws InvalidArgumentException |
|
304 | + * @throws InvalidInterfaceException |
|
305 | + * @throws InvalidDataTypeException |
|
306 | + * @throws EE_Error |
|
307 | + */ |
|
308 | + protected function store_submitted_form_data_in_session() |
|
309 | + { |
|
310 | + return EE_Registry::instance()->SSN->set_session_data( |
|
311 | + array( |
|
312 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
313 | + ) |
|
314 | + ); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * retrieves the originally submitted input values in the session |
|
320 | + * so that they can be used to repopulate the form if it failed validation |
|
321 | + * |
|
322 | + * @return array |
|
323 | + * @throws InvalidArgumentException |
|
324 | + * @throws InvalidInterfaceException |
|
325 | + * @throws InvalidDataTypeException |
|
326 | + */ |
|
327 | + protected function get_submitted_form_data_from_session() |
|
328 | + { |
|
329 | + $session = EE_Registry::instance()->SSN; |
|
330 | + if ($session instanceof EE_Session) { |
|
331 | + return $session->get_session_data( |
|
332 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
333 | + ); |
|
334 | + } |
|
335 | + return array(); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * flushed the originally submitted input values from the session |
|
341 | + * |
|
342 | + * @return boolean whether or not the data was successfully removed from the session |
|
343 | + * @throws InvalidArgumentException |
|
344 | + * @throws InvalidInterfaceException |
|
345 | + * @throws InvalidDataTypeException |
|
346 | + */ |
|
347 | + protected function flush_submitted_form_data_from_session() |
|
348 | + { |
|
349 | + return EE_Registry::instance()->SSN->reset_data( |
|
350 | + array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
351 | + ); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Populates this form and its subsections with data from the session. |
|
357 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
358 | + * validation errors when displaying too) |
|
359 | + * Returns true if the form was populated from the session, false otherwise |
|
360 | + * |
|
361 | + * @return boolean |
|
362 | + * @throws InvalidArgumentException |
|
363 | + * @throws InvalidInterfaceException |
|
364 | + * @throws InvalidDataTypeException |
|
365 | + * @throws EE_Error |
|
366 | + */ |
|
367 | + public function populate_from_session() |
|
368 | + { |
|
369 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
370 | + if (empty($form_data_in_session)) { |
|
371 | + return false; |
|
372 | + } |
|
373 | + $this->receive_form_submission($form_data_in_session); |
|
374 | + $this->flush_submitted_form_data_from_session(); |
|
375 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
376 | + return true; |
|
377 | + } |
|
378 | + return false; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * Populates the default data for the form, given an array where keys are |
|
384 | + * the input names, and values are their values (preferably normalized to be their |
|
385 | + * proper PHP types, not all strings... although that should be ok too). |
|
386 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
387 | + * the value being an array formatted in teh same way |
|
388 | + * |
|
389 | + * @param array $default_data |
|
390 | + * @throws EE_Error |
|
391 | + */ |
|
392 | + public function populate_defaults($default_data) |
|
393 | + { |
|
394 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
395 | + if (isset($default_data[ $subsection_name ])) { |
|
396 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
397 | + $subsection->set_default($default_data[ $subsection_name ]); |
|
398 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
399 | + $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
400 | + } |
|
401 | + } |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * returns true if subsection exists |
|
408 | + * |
|
409 | + * @param string $name |
|
410 | + * @return boolean |
|
411 | + */ |
|
412 | + public function subsection_exists($name) |
|
413 | + { |
|
414 | + return isset($this->_subsections[ $name ]) ? true : false; |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * Gets the subsection specified by its name |
|
420 | + * |
|
421 | + * @param string $name |
|
422 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
423 | + * so that the inputs will be properly configured. |
|
424 | + * However, some client code may be ok |
|
425 | + * with construction finalize being called later |
|
426 | + * (realizing that the subsections' html names |
|
427 | + * might not be set yet, etc.) |
|
428 | + * @return EE_Form_Section_Base |
|
429 | + * @throws EE_Error |
|
430 | + */ |
|
431 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
432 | + { |
|
433 | + if ($require_construction_to_be_finalized) { |
|
434 | + $this->ensure_construct_finalized_called(); |
|
435 | + } |
|
436 | + return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * Gets all the validatable subsections of this form section |
|
442 | + * |
|
443 | + * @return EE_Form_Section_Validatable[] |
|
444 | + * @throws EE_Error |
|
445 | + */ |
|
446 | + public function get_validatable_subsections() |
|
447 | + { |
|
448 | + $validatable_subsections = array(); |
|
449 | + foreach ($this->subsections() as $name => $obj) { |
|
450 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
451 | + $validatable_subsections[ $name ] = $obj; |
|
452 | + } |
|
453 | + } |
|
454 | + return $validatable_subsections; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
460 | + * throw an EE_Error. |
|
461 | + * |
|
462 | + * @param string $name |
|
463 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
464 | + * leave this as TRUE so that the inputs will be properly |
|
465 | + * configured. However, some client code may be ok with |
|
466 | + * construction finalize being called later |
|
467 | + * (realizing that the subsections' html names might not be |
|
468 | + * set yet, etc.) |
|
469 | + * @return EE_Form_Input_Base |
|
470 | + * @throws EE_Error |
|
471 | + */ |
|
472 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
473 | + { |
|
474 | + $subsection = $this->get_subsection( |
|
475 | + $name, |
|
476 | + $require_construction_to_be_finalized |
|
477 | + ); |
|
478 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
479 | + throw new EE_Error( |
|
480 | + sprintf( |
|
481 | + esc_html__( |
|
482 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
483 | + 'event_espresso' |
|
484 | + ), |
|
485 | + $name, |
|
486 | + get_class($this), |
|
487 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
488 | + ) |
|
489 | + ); |
|
490 | + } |
|
491 | + return $subsection; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
497 | + * otherwise throws an EE_Error |
|
498 | + * |
|
499 | + * @param string $name |
|
500 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
501 | + * leave this as TRUE so that the inputs will be properly |
|
502 | + * configured. However, some client code may be ok with |
|
503 | + * construction finalize being called later |
|
504 | + * (realizing that the subsections' html names might not be |
|
505 | + * set yet, etc.) |
|
506 | + * @return EE_Form_Section_Proper |
|
507 | + * @throws EE_Error |
|
508 | + */ |
|
509 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
510 | + { |
|
511 | + $subsection = $this->get_subsection( |
|
512 | + $name, |
|
513 | + $require_construction_to_be_finalized |
|
514 | + ); |
|
515 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
516 | + throw new EE_Error( |
|
517 | + sprintf( |
|
518 | + esc_html__( |
|
519 | + "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
520 | + 'event_espresso' |
|
521 | + ), |
|
522 | + $name, |
|
523 | + get_class($this) |
|
524 | + ) |
|
525 | + ); |
|
526 | + } |
|
527 | + return $subsection; |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + /** |
|
532 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
533 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
534 | + * |
|
535 | + * @param string $name |
|
536 | + * @return mixed depending on the input's type and its normalization strategy |
|
537 | + * @throws EE_Error |
|
538 | + */ |
|
539 | + public function get_input_value($name) |
|
540 | + { |
|
541 | + $input = $this->get_input($name); |
|
542 | + return $input->normalized_value(); |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * Checks if this form section itself is valid, and then checks its subsections |
|
548 | + * |
|
549 | + * @throws EE_Error |
|
550 | + * @return boolean |
|
551 | + */ |
|
552 | + public function is_valid() |
|
553 | + { |
|
554 | + if (! $this->has_received_submission()) { |
|
555 | + throw new EE_Error( |
|
556 | + sprintf( |
|
557 | + esc_html__( |
|
558 | + 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
559 | + 'event_espresso' |
|
560 | + ) |
|
561 | + ) |
|
562 | + ); |
|
563 | + } |
|
564 | + if (! parent::is_valid()) { |
|
565 | + return false; |
|
566 | + } |
|
567 | + // ok so no general errors to this entire form section. |
|
568 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
569 | + $set_submission_errors = $this->submission_error_message() === ''; |
|
570 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
571 | + if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
572 | + if ($set_submission_errors) { |
|
573 | + $this->set_submission_error_message( |
|
574 | + $subsection->get_validation_error_string() |
|
575 | + ); |
|
576 | + } |
|
577 | + return false; |
|
578 | + } |
|
579 | + } |
|
580 | + return true; |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * gets the default name of this form section if none is specified |
|
586 | + * |
|
587 | + * @return void |
|
588 | + */ |
|
589 | + protected function _set_default_name_if_empty() |
|
590 | + { |
|
591 | + if (! $this->_name) { |
|
592 | + $classname = get_class($this); |
|
593 | + $default_name = str_replace('EE_', '', $classname); |
|
594 | + $this->_name = $default_name; |
|
595 | + } |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
601 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
602 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
603 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
604 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
605 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
606 | + * any CSS. |
|
607 | + * |
|
608 | + * @throws InvalidArgumentException |
|
609 | + * @throws InvalidInterfaceException |
|
610 | + * @throws InvalidDataTypeException |
|
611 | + * @throws EE_Error |
|
612 | + */ |
|
613 | + public function get_html_and_js() |
|
614 | + { |
|
615 | + $this->enqueue_js(); |
|
616 | + return $this->get_html(); |
|
617 | + } |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
622 | + * |
|
623 | + * @param bool $display_previously_submitted_data |
|
624 | + * @return string |
|
625 | + * @throws InvalidArgumentException |
|
626 | + * @throws InvalidInterfaceException |
|
627 | + * @throws InvalidDataTypeException |
|
628 | + * @throws EE_Error |
|
629 | + * @throws EE_Error |
|
630 | + * @throws EE_Error |
|
631 | + */ |
|
632 | + public function get_html($display_previously_submitted_data = true) |
|
633 | + { |
|
634 | + $this->ensure_construct_finalized_called(); |
|
635 | + if ($display_previously_submitted_data) { |
|
636 | + $this->populate_from_session(); |
|
637 | + } |
|
638 | + return $this->_form_html_filter |
|
639 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
640 | + : $this->_layout_strategy->layout_form(); |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * enqueues JS and CSS for the form. |
|
646 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
647 | + * scripts and styles can be put in the header, but if called later |
|
648 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
649 | + * only be in the header; but in HTML5 its ok in the body. |
|
650 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
651 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
652 | + * |
|
653 | + * @return void |
|
654 | + * @throws EE_Error |
|
655 | + */ |
|
656 | + public function enqueue_js() |
|
657 | + { |
|
658 | + $this->_enqueue_and_localize_form_js(); |
|
659 | + foreach ($this->subsections() as $subsection) { |
|
660 | + $subsection->enqueue_js(); |
|
661 | + } |
|
662 | + } |
|
663 | + |
|
664 | + |
|
665 | + /** |
|
666 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
667 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
668 | + * the wp_enqueue_scripts hook. |
|
669 | + * However, registering the form js and localizing it can happen when we |
|
670 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
671 | + * could change until it's actually outputted) |
|
672 | + * |
|
673 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
674 | + * to be triggered automatically or not |
|
675 | + * @return void |
|
676 | + */ |
|
677 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
678 | + { |
|
679 | + wp_register_script( |
|
680 | + 'ee_form_section_validation', |
|
681 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
682 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
683 | + EVENT_ESPRESSO_VERSION, |
|
684 | + true |
|
685 | + ); |
|
686 | + wp_localize_script( |
|
687 | + 'ee_form_section_validation', |
|
688 | + 'ee_form_section_validation_init', |
|
689 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
690 | + ); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * gets the variables used by form_section_validation.js. |
|
696 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
697 | + * but before the wordpress hook wp_loaded |
|
698 | + * |
|
699 | + * @throws EE_Error |
|
700 | + */ |
|
701 | + public function _enqueue_and_localize_form_js() |
|
702 | + { |
|
703 | + $this->ensure_construct_finalized_called(); |
|
704 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
705 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
706 | + //and localize it just before the footer |
|
707 | + $this->localize_validation_rules(); |
|
708 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
709 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
710 | + } |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * add our form section data to a static variable accessible by all form sections |
|
715 | + * |
|
716 | + * @param bool $return_for_subsection |
|
717 | + * @return void |
|
718 | + * @throws EE_Error |
|
719 | + */ |
|
720 | + public function localize_validation_rules($return_for_subsection = false) |
|
721 | + { |
|
722 | + // we only want to localize vars ONCE for the entire form, |
|
723 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
724 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
725 | + EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
726 | + 'form_section_id' => $this->html_id(true), |
|
727 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
728 | + 'other_data' => $this->get_other_js_data(), |
|
729 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
730 | + ); |
|
731 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
738 | + * This is primarily data added by inputs and forms in addition to any |
|
739 | + * scripts they might enqueue |
|
740 | + * |
|
741 | + * @param array $form_other_js_data |
|
742 | + * @return array |
|
743 | + * @throws EE_Error |
|
744 | + */ |
|
745 | + public function get_other_js_data($form_other_js_data = array()) |
|
746 | + { |
|
747 | + foreach ($this->subsections() as $subsection) { |
|
748 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
749 | + } |
|
750 | + return $form_other_js_data; |
|
751 | + } |
|
752 | + |
|
753 | + |
|
754 | + /** |
|
755 | + * Gets a flat array of inputs for this form section and its subsections. |
|
756 | + * Keys are their form names, and values are the inputs themselves |
|
757 | + * |
|
758 | + * @return EE_Form_Input_Base |
|
759 | + * @throws EE_Error |
|
760 | + */ |
|
761 | + public function inputs_in_subsections() |
|
762 | + { |
|
763 | + $inputs = array(); |
|
764 | + foreach ($this->subsections() as $subsection) { |
|
765 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
766 | + $inputs[ $subsection->html_name() ] = $subsection; |
|
767 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
768 | + $inputs += $subsection->inputs_in_subsections(); |
|
769 | + } |
|
770 | + } |
|
771 | + return $inputs; |
|
772 | + } |
|
773 | + |
|
774 | + |
|
775 | + /** |
|
776 | + * Gets a flat array of all the validation errors. |
|
777 | + * Keys are html names (because those should be unique) |
|
778 | + * and values are a string of all their validation errors |
|
779 | + * |
|
780 | + * @return string[] |
|
781 | + * @throws EE_Error |
|
782 | + */ |
|
783 | + public function subsection_validation_errors_by_html_name() |
|
784 | + { |
|
785 | + $inputs = $this->inputs(); |
|
786 | + $errors = array(); |
|
787 | + foreach ($inputs as $form_input) { |
|
788 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
789 | + $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
790 | + } |
|
791 | + } |
|
792 | + return $errors; |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
798 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
799 | + * |
|
800 | + * @throws InvalidArgumentException |
|
801 | + * @throws InvalidInterfaceException |
|
802 | + * @throws InvalidDataTypeException |
|
803 | + */ |
|
804 | + public static function localize_script_for_all_forms() |
|
805 | + { |
|
806 | + //allow inputs and stuff to hook in their JS and stuff here |
|
807 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
808 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
809 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
810 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
811 | + : 'wp_default'; |
|
812 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
813 | + wp_enqueue_script('ee_form_section_validation'); |
|
814 | + wp_localize_script( |
|
815 | + 'ee_form_section_validation', |
|
816 | + 'ee_form_section_vars', |
|
817 | + EE_Form_Section_Proper::$_js_localization |
|
818 | + ); |
|
819 | + } |
|
820 | + |
|
821 | + |
|
822 | + /** |
|
823 | + * ensure_scripts_localized |
|
824 | + * |
|
825 | + * @throws EE_Error |
|
826 | + */ |
|
827 | + public function ensure_scripts_localized() |
|
828 | + { |
|
829 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
830 | + $this->_enqueue_and_localize_form_js(); |
|
831 | + } |
|
832 | + } |
|
833 | + |
|
834 | + |
|
835 | + /** |
|
836 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
837 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
838 | + * |
|
839 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
840 | + */ |
|
841 | + private static function _get_localized_error_messages() |
|
842 | + { |
|
843 | + return array( |
|
844 | + 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
845 | + 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
846 | + ); |
|
847 | + } |
|
848 | + |
|
849 | + |
|
850 | + /** |
|
851 | + * @return array |
|
852 | + */ |
|
853 | + public static function js_localization() |
|
854 | + { |
|
855 | + return self::$_js_localization; |
|
856 | + } |
|
857 | + |
|
858 | + |
|
859 | + /** |
|
860 | + * @return void |
|
861 | + */ |
|
862 | + public static function reset_js_localization() |
|
863 | + { |
|
864 | + self::$_js_localization = array(); |
|
865 | + } |
|
866 | + |
|
867 | + |
|
868 | + /** |
|
869 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
870 | + * See parent function for more... |
|
871 | + * |
|
872 | + * @return array |
|
873 | + * @throws EE_Error |
|
874 | + */ |
|
875 | + public function get_jquery_validation_rules() |
|
876 | + { |
|
877 | + $jquery_validation_rules = array(); |
|
878 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
879 | + $jquery_validation_rules = array_merge( |
|
880 | + $jquery_validation_rules, |
|
881 | + $subsection->get_jquery_validation_rules() |
|
882 | + ); |
|
883 | + } |
|
884 | + return $jquery_validation_rules; |
|
885 | + } |
|
886 | + |
|
887 | + |
|
888 | + /** |
|
889 | + * Sanitizes all the data and sets the sanitized value of each field |
|
890 | + * |
|
891 | + * @param array $req_data like $_POST |
|
892 | + * @return void |
|
893 | + * @throws EE_Error |
|
894 | + */ |
|
895 | + protected function _normalize($req_data) |
|
896 | + { |
|
897 | + $this->_received_submission = true; |
|
898 | + $this->_validation_errors = array(); |
|
899 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
900 | + try { |
|
901 | + $subsection->_normalize($req_data); |
|
902 | + } catch (EE_Validation_Error $e) { |
|
903 | + $subsection->add_validation_error($e); |
|
904 | + } |
|
905 | + } |
|
906 | + } |
|
907 | + |
|
908 | + |
|
909 | + /** |
|
910 | + * Performs validation on this form section and its subsections. |
|
911 | + * For each subsection, |
|
912 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
913 | + * and passes it the subsection, then calls _validate on that subsection. |
|
914 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
915 | + * you would be best to override this _validate method, |
|
916 | + * calling parent::_validate() first. |
|
917 | + * |
|
918 | + * @throws EE_Error |
|
919 | + */ |
|
920 | + protected function _validate() |
|
921 | + { |
|
922 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
923 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
924 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
925 | + } |
|
926 | + $subsection->_validate(); |
|
927 | + } |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * Gets all the validated inputs for the form section |
|
933 | + * |
|
934 | + * @return array |
|
935 | + * @throws EE_Error |
|
936 | + */ |
|
937 | + public function valid_data() |
|
938 | + { |
|
939 | + $inputs = array(); |
|
940 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
941 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
942 | + $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
943 | + } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
944 | + $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
945 | + } |
|
946 | + } |
|
947 | + return $inputs; |
|
948 | + } |
|
949 | + |
|
950 | + |
|
951 | + /** |
|
952 | + * Gets all the inputs on this form section |
|
953 | + * |
|
954 | + * @return EE_Form_Input_Base[] |
|
955 | + * @throws EE_Error |
|
956 | + */ |
|
957 | + public function inputs() |
|
958 | + { |
|
959 | + $inputs = array(); |
|
960 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
961 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
962 | + $inputs[ $subsection_name ] = $subsection; |
|
963 | + } |
|
964 | + } |
|
965 | + return $inputs; |
|
966 | + } |
|
967 | + |
|
968 | + |
|
969 | + /** |
|
970 | + * Gets all the subsections which are a proper form |
|
971 | + * |
|
972 | + * @return EE_Form_Section_Proper[] |
|
973 | + * @throws EE_Error |
|
974 | + */ |
|
975 | + public function subforms() |
|
976 | + { |
|
977 | + $form_sections = array(); |
|
978 | + foreach ($this->subsections() as $name => $obj) { |
|
979 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
980 | + $form_sections[ $name ] = $obj; |
|
981 | + } |
|
982 | + } |
|
983 | + return $form_sections; |
|
984 | + } |
|
985 | + |
|
986 | + |
|
987 | + /** |
|
988 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
989 | + * Consider using inputs() or subforms() |
|
990 | + * if you only want form inputs or proper form sections. |
|
991 | + * |
|
992 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
993 | + * leave this as TRUE so that the inputs will be properly |
|
994 | + * configured. However, some client code may be ok with |
|
995 | + * construction finalize being called later |
|
996 | + * (realizing that the subsections' html names might not be |
|
997 | + * set yet, etc.) |
|
998 | + * @return EE_Form_Section_Proper[] |
|
999 | + * @throws EE_Error |
|
1000 | + */ |
|
1001 | + public function subsections($require_construction_to_be_finalized = true) |
|
1002 | + { |
|
1003 | + if ($require_construction_to_be_finalized) { |
|
1004 | + $this->ensure_construct_finalized_called(); |
|
1005 | + } |
|
1006 | + return $this->_subsections; |
|
1007 | + } |
|
1008 | + |
|
1009 | + |
|
1010 | + /** |
|
1011 | + * Returns a simple array where keys are input names, and values are their normalized |
|
1012 | + * values. (Similar to calling get_input_value on inputs) |
|
1013 | + * |
|
1014 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1015 | + * or just this forms' direct children inputs |
|
1016 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1017 | + * or allow multidimensional array |
|
1018 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1019 | + * with array keys being input names |
|
1020 | + * (regardless of whether they are from a subsection or not), |
|
1021 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1022 | + * where keys are always subsection names and values are either |
|
1023 | + * the input's normalized value, or an array like the top-level array |
|
1024 | + * @throws EE_Error |
|
1025 | + */ |
|
1026 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
1027 | + { |
|
1028 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1029 | + } |
|
1030 | + |
|
1031 | + |
|
1032 | + /** |
|
1033 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1034 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1035 | + * is not necessarily the value we want to display to users. This creates an array |
|
1036 | + * where keys are the input names, and values are their display values |
|
1037 | + * |
|
1038 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1039 | + * or just this forms' direct children inputs |
|
1040 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1041 | + * or allow multidimensional array |
|
1042 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1043 | + * with array keys being input names |
|
1044 | + * (regardless of whether they are from a subsection or not), |
|
1045 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1046 | + * where keys are always subsection names and values are either |
|
1047 | + * the input's normalized value, or an array like the top-level array |
|
1048 | + * @throws EE_Error |
|
1049 | + */ |
|
1050 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1051 | + { |
|
1052 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1053 | + } |
|
1054 | + |
|
1055 | + |
|
1056 | + /** |
|
1057 | + * Gets the input values from the form |
|
1058 | + * |
|
1059 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
1060 | + * or just the normalized value |
|
1061 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1062 | + * or just this forms' direct children inputs |
|
1063 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1064 | + * or allow multidimensional array |
|
1065 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1066 | + * input names (regardless of whether they are from a subsection or not), |
|
1067 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1068 | + * where keys are always subsection names and values are either |
|
1069 | + * the input's normalized value, or an array like the top-level array |
|
1070 | + * @throws EE_Error |
|
1071 | + */ |
|
1072 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1073 | + { |
|
1074 | + $input_values = array(); |
|
1075 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1076 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1077 | + $input_values[ $subsection_name ] = $pretty |
|
1078 | + ? $subsection->pretty_value() |
|
1079 | + : $subsection->normalized_value(); |
|
1080 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1081 | + $subform_input_values = $subsection->_input_values( |
|
1082 | + $pretty, |
|
1083 | + $include_subform_inputs, |
|
1084 | + $flatten |
|
1085 | + ); |
|
1086 | + if ($flatten) { |
|
1087 | + $input_values = array_merge($input_values, $subform_input_values); |
|
1088 | + } else { |
|
1089 | + $input_values[ $subsection_name ] = $subform_input_values; |
|
1090 | + } |
|
1091 | + } |
|
1092 | + } |
|
1093 | + return $input_values; |
|
1094 | + } |
|
1095 | + |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * Gets the originally submitted input values from the form |
|
1099 | + * |
|
1100 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1101 | + * or just this forms' direct children inputs |
|
1102 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1103 | + * with array keys being input names |
|
1104 | + * (regardless of whether they are from a subsection or not), |
|
1105 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1106 | + * where keys are always subsection names and values are either |
|
1107 | + * the input's normalized value, or an array like the top-level array |
|
1108 | + * @throws EE_Error |
|
1109 | + */ |
|
1110 | + public function submitted_values($include_subforms = false) |
|
1111 | + { |
|
1112 | + $submitted_values = array(); |
|
1113 | + foreach ($this->subsections() as $subsection) { |
|
1114 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1115 | + // is this input part of an array of inputs? |
|
1116 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
1117 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1118 | + explode( |
|
1119 | + '[', |
|
1120 | + str_replace(']', '', $subsection->html_name()) |
|
1121 | + ), |
|
1122 | + $subsection->raw_value() |
|
1123 | + ); |
|
1124 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1125 | + } else { |
|
1126 | + $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1127 | + } |
|
1128 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1129 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1130 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1131 | + } |
|
1132 | + } |
|
1133 | + return $submitted_values; |
|
1134 | + } |
|
1135 | + |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * Indicates whether or not this form has received a submission yet |
|
1139 | + * (ie, had receive_form_submission called on it yet) |
|
1140 | + * |
|
1141 | + * @return boolean |
|
1142 | + * @throws EE_Error |
|
1143 | + */ |
|
1144 | + public function has_received_submission() |
|
1145 | + { |
|
1146 | + $this->ensure_construct_finalized_called(); |
|
1147 | + return $this->_received_submission; |
|
1148 | + } |
|
1149 | + |
|
1150 | + |
|
1151 | + /** |
|
1152 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
1153 | + * Removes the listed inputs from the form |
|
1154 | + * |
|
1155 | + * @param array $inputs_to_exclude values are the input names |
|
1156 | + * @return void |
|
1157 | + */ |
|
1158 | + public function exclude(array $inputs_to_exclude = array()) |
|
1159 | + { |
|
1160 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1161 | + unset($this->_subsections[ $input_to_exclude_name ]); |
|
1162 | + } |
|
1163 | + } |
|
1164 | + |
|
1165 | + |
|
1166 | + /** |
|
1167 | + * Changes these inputs' display strategy to be EE_Hidden_Display_Strategy. |
|
1168 | + * @param array $inputs_to_hide |
|
1169 | + * @throws EE_Error |
|
1170 | + */ |
|
1171 | + public function hide(array $inputs_to_hide = array()) |
|
1172 | + { |
|
1173 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
1174 | + $input = $this->get_input($input_to_hide); |
|
1175 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1176 | + } |
|
1177 | + } |
|
1178 | + |
|
1179 | + |
|
1180 | + /** |
|
1181 | + * add_subsections |
|
1182 | + * Adds the listed subsections to the form section. |
|
1183 | + * If $subsection_name_to_target is provided, |
|
1184 | + * then new subsections are added before or after that subsection, |
|
1185 | + * otherwise to the start or end of the entire subsections array. |
|
1186 | + * |
|
1187 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1188 | + * where keys are their names |
|
1189 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1190 | + * should be added before or after |
|
1191 | + * IF $subsection_name_to_target is null, |
|
1192 | + * then $new_subsections will be added to |
|
1193 | + * the beginning or end of the entire subsections array |
|
1194 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
1195 | + * $subsection_name_to_target, |
|
1196 | + * or if $subsection_name_to_target is null, |
|
1197 | + * before or after entire subsections array |
|
1198 | + * @return void |
|
1199 | + * @throws EE_Error |
|
1200 | + */ |
|
1201 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1202 | + { |
|
1203 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
1204 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
1205 | + EE_Error::add_error( |
|
1206 | + sprintf( |
|
1207 | + esc_html__( |
|
1208 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1209 | + 'event_espresso' |
|
1210 | + ), |
|
1211 | + get_class($subsection), |
|
1212 | + $subsection_name, |
|
1213 | + $this->name() |
|
1214 | + ) |
|
1215 | + ); |
|
1216 | + unset($new_subsections[ $subsection_name ]); |
|
1217 | + } |
|
1218 | + } |
|
1219 | + $this->_subsections = EEH_Array::insert_into_array( |
|
1220 | + $this->_subsections, |
|
1221 | + $new_subsections, |
|
1222 | + $subsection_name_to_target, |
|
1223 | + $add_before |
|
1224 | + ); |
|
1225 | + if ($this->_construction_finalized) { |
|
1226 | + foreach ($this->_subsections as $name => $subsection) { |
|
1227 | + $subsection->_construct_finalize($this, $name); |
|
1228 | + } |
|
1229 | + } |
|
1230 | + } |
|
1231 | + |
|
1232 | + |
|
1233 | + /** |
|
1234 | + * Just gets all validatable subsections to clean their sensitive data |
|
1235 | + * |
|
1236 | + * @throws EE_Error |
|
1237 | + */ |
|
1238 | + public function clean_sensitive_data() |
|
1239 | + { |
|
1240 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1241 | + $subsection->clean_sensitive_data(); |
|
1242 | + } |
|
1243 | + } |
|
1244 | + |
|
1245 | + |
|
1246 | + /** |
|
1247 | + * @param string $form_submission_error_message |
|
1248 | + */ |
|
1249 | + public function set_submission_error_message($form_submission_error_message = '') |
|
1250 | + { |
|
1251 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
1252 | + ? $form_submission_error_message |
|
1253 | + : esc_html__('Form submission failed due to errors', 'event_espresso'); |
|
1254 | + } |
|
1255 | + |
|
1256 | + |
|
1257 | + /** |
|
1258 | + * @return string |
|
1259 | + */ |
|
1260 | + public function submission_error_message() |
|
1261 | + { |
|
1262 | + return $this->_form_submission_error_message; |
|
1263 | + } |
|
1264 | + |
|
1265 | + |
|
1266 | + /** |
|
1267 | + * @param string $form_submission_success_message |
|
1268 | + */ |
|
1269 | + public function set_submission_success_message($form_submission_success_message) |
|
1270 | + { |
|
1271 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
1272 | + ? $form_submission_success_message |
|
1273 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1274 | + } |
|
1275 | + |
|
1276 | + |
|
1277 | + /** |
|
1278 | + * @return string |
|
1279 | + */ |
|
1280 | + public function submission_success_message() |
|
1281 | + { |
|
1282 | + return $this->_form_submission_success_message; |
|
1283 | + } |
|
1284 | + |
|
1285 | + |
|
1286 | + /** |
|
1287 | + * Returns the prefix that should be used on child of this form section for |
|
1288 | + * their html names. If this form section itself has a parent, prepends ITS |
|
1289 | + * prefix onto this form section's prefix. Used primarily by |
|
1290 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1291 | + * |
|
1292 | + * @return string |
|
1293 | + * @throws EE_Error |
|
1294 | + */ |
|
1295 | + public function html_name_prefix() |
|
1296 | + { |
|
1297 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1298 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1299 | + } |
|
1300 | + return $this->name(); |
|
1301 | + } |
|
1302 | + |
|
1303 | + |
|
1304 | + /** |
|
1305 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1306 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
1307 | + * was set, which is probably nothing, or the classname) |
|
1308 | + * |
|
1309 | + * @return string |
|
1310 | + * @throws EE_Error |
|
1311 | + */ |
|
1312 | + public function name() |
|
1313 | + { |
|
1314 | + $this->ensure_construct_finalized_called(); |
|
1315 | + return parent::name(); |
|
1316 | + } |
|
1317 | + |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * @return EE_Form_Section_Proper |
|
1321 | + * @throws EE_Error |
|
1322 | + */ |
|
1323 | + public function parent_section() |
|
1324 | + { |
|
1325 | + $this->ensure_construct_finalized_called(); |
|
1326 | + return parent::parent_section(); |
|
1327 | + } |
|
1328 | + |
|
1329 | + |
|
1330 | + /** |
|
1331 | + * make sure construction finalized was called, otherwise children might not be ready |
|
1332 | + * |
|
1333 | + * @return void |
|
1334 | + * @throws EE_Error |
|
1335 | + */ |
|
1336 | + public function ensure_construct_finalized_called() |
|
1337 | + { |
|
1338 | + if (! $this->_construction_finalized) { |
|
1339 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1340 | + } |
|
1341 | + } |
|
1342 | + |
|
1343 | + |
|
1344 | + /** |
|
1345 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1346 | + * are in teh form data. If any are found, returns true. Else false |
|
1347 | + * |
|
1348 | + * @param array $req_data |
|
1349 | + * @return boolean |
|
1350 | + * @throws EE_Error |
|
1351 | + */ |
|
1352 | + public function form_data_present_in($req_data = null) |
|
1353 | + { |
|
1354 | + if ($req_data === null) { |
|
1355 | + $req_data = $_POST; |
|
1356 | + } |
|
1357 | + foreach ($this->subsections() as $subsection) { |
|
1358 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1359 | + if ($subsection->form_data_present_in($req_data)) { |
|
1360 | + return true; |
|
1361 | + } |
|
1362 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1363 | + if ($subsection->form_data_present_in($req_data)) { |
|
1364 | + return true; |
|
1365 | + } |
|
1366 | + } |
|
1367 | + } |
|
1368 | + return false; |
|
1369 | + } |
|
1370 | + |
|
1371 | + |
|
1372 | + /** |
|
1373 | + * Gets validation errors for this form section and subsections |
|
1374 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1375 | + * gets the validation errors for ALL subsection |
|
1376 | + * |
|
1377 | + * @return EE_Validation_Error[] |
|
1378 | + * @throws EE_Error |
|
1379 | + */ |
|
1380 | + public function get_validation_errors_accumulated() |
|
1381 | + { |
|
1382 | + $validation_errors = $this->get_validation_errors(); |
|
1383 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1384 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
1385 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1386 | + } else { |
|
1387 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1388 | + } |
|
1389 | + if ($validation_errors_on_this_subsection) { |
|
1390 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1391 | + } |
|
1392 | + } |
|
1393 | + return $validation_errors; |
|
1394 | + } |
|
1395 | + |
|
1396 | + |
|
1397 | + /** |
|
1398 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
1399 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1400 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
1401 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1402 | + * which will be returned. |
|
1403 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1404 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1405 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1406 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1407 | + * Etc |
|
1408 | + * |
|
1409 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1410 | + * @return EE_Form_Section_Base |
|
1411 | + * @throws EE_Error |
|
1412 | + */ |
|
1413 | + public function find_section_from_path($form_section_path) |
|
1414 | + { |
|
1415 | + //check if we can find the input from purely going straight up the tree |
|
1416 | + $input = parent::find_section_from_path($form_section_path); |
|
1417 | + if ($input instanceof EE_Form_Section_Base) { |
|
1418 | + return $input; |
|
1419 | + } |
|
1420 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
1421 | + if ($next_slash_pos !== false) { |
|
1422 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1423 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1424 | + } else { |
|
1425 | + $child_section_name = $form_section_path; |
|
1426 | + $subpath = ''; |
|
1427 | + } |
|
1428 | + $child_section = $this->get_subsection($child_section_name); |
|
1429 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
1430 | + return $child_section->find_section_from_path($subpath); |
|
1431 | + } |
|
1432 | + return null; |
|
1433 | + } |
|
1434 | 1434 | } |
1435 | 1435 |