@@ -21,8 +21,8 @@ |
||
21 | 21 | |
22 | 22 | |
23 | 23 | <div id="postbox-container-2" class="postbox-container"> |
24 | - <?php do_meta_boxes( $current_page, 'normal', NULL ); ?> |
|
25 | - <?php do_meta_boxes( $current_page, 'advanced', NULL ); ?> |
|
24 | + <?php do_meta_boxes($current_page, 'normal', NULL); ?> |
|
25 | + <?php do_meta_boxes($current_page, 'advanced', NULL); ?> |
|
26 | 26 | </div> |
27 | 27 | <!-- postbox-container-2 --> |
28 | 28 | <div class="clear"></div> |
@@ -259,7 +259,7 @@ |
||
259 | 259 | * @param int $ID |
260 | 260 | * @param $shortcode_class |
261 | 261 | * @param $shortcode_posts |
262 | - * @param $page_for_posts |
|
262 | + * @param string $page_for_posts |
|
263 | 263 | * @param bool $update_post_shortcodes |
264 | 264 | * @return bool |
265 | 265 | */ |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace EventEspresso\core\admin; |
3 | 3 | |
4 | 4 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
5 | - exit( 'No direct script access allowed' ); |
|
5 | + exit( 'No direct script access allowed' ); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -19,450 +19,450 @@ discard block |
||
19 | 19 | class PostShortcodeTracking |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * set_hooks_admin |
|
24 | - * |
|
25 | - * @access public |
|
26 | - */ |
|
27 | - public static function set_hooks_admin() |
|
28 | - { |
|
29 | - add_action( |
|
30 | - 'save_post', |
|
31 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save' ), |
|
32 | - 100, |
|
33 | - 2 |
|
34 | - ); |
|
35 | - add_action( |
|
36 | - 'delete_post', |
|
37 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete' ), |
|
38 | - 100, |
|
39 | - 1 |
|
40 | - ); |
|
41 | - add_action( |
|
42 | - 'add_option_page_for_posts', |
|
43 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set' ), |
|
44 | - 100, |
|
45 | - 2 |
|
46 | - ); |
|
47 | - add_action( |
|
48 | - 'update_option', |
|
49 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change' ), |
|
50 | - 100, |
|
51 | - 3 |
|
52 | - ); |
|
53 | - add_action( |
|
54 | - 'delete_option', |
|
55 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete' ), |
|
56 | - 100, |
|
57 | - 1 |
|
58 | - ); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * parse_post_content_on_save |
|
65 | - * any time a post is saved, we need to check for any EE shortcodes that may be embedded in the content, |
|
66 | - * and then track what posts those shortcodes are on, so that we can initialize shortcodes well before |
|
67 | - * the_content() runs. this allows us to do things like enqueue scripts for shortcodes ONLY on the pages the |
|
68 | - * shortcodes are actually used on |
|
69 | - * |
|
70 | - * @access public |
|
71 | - * @param int $post_ID |
|
72 | - * @param \WP_Post $post |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public static function parse_post_content_on_save( $post_ID, $post ) |
|
76 | - { |
|
77 | - // if the post is trashed, then let's remove our post shortcode tracking |
|
78 | - if ( $post instanceof \WP_Post && $post->post_status === 'trash' ) { |
|
79 | - PostShortcodeTracking::unset_post_shortcodes_on_delete( $post_ID ); |
|
80 | - return; |
|
81 | - } |
|
82 | - // default post types |
|
83 | - $post_types = array( 'post' => 0, 'page' => 1 ); |
|
84 | - // add CPTs |
|
85 | - $CPTs = \EE_Register_CPTs::get_CPTs(); |
|
86 | - $post_types = array_merge( $post_types, $CPTs ); |
|
87 | - // for default or CPT posts... |
|
88 | - if ( isset( $post_types[ $post->post_type ] ) ) { |
|
89 | - // post on frontpage ? |
|
90 | - $page_for_posts = \EE_Config::get_page_for_posts(); |
|
91 | - if ( $post->post_name === $page_for_posts ) { |
|
92 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $page_for_posts ); |
|
93 | - return; |
|
94 | - } |
|
95 | - // array of shortcodes indexed by post name |
|
96 | - \EE_Registry::CFG()->core->post_shortcodes = isset( \EE_Registry::CFG()->core->post_shortcodes ) |
|
97 | - ? \EE_Registry::CFG()->core->post_shortcodes |
|
98 | - : array(); |
|
99 | - // whether to proceed with update |
|
100 | - $update_post_shortcodes = false; |
|
101 | - // empty both arrays |
|
102 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ] = array(); |
|
103 | - // check that posts page is already being tracked |
|
104 | - if ( ! isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] ) ) { |
|
105 | - // if not, then ensure that it is properly added |
|
106 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
107 | - } |
|
108 | - // loop thru shortcodes |
|
109 | - foreach ( \EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir ) { |
|
110 | - // convert to UPPERCASE to get actual shortcode |
|
111 | - $EES_Shortcode = strtoupper( $EES_Shortcode ); |
|
112 | - // is the shortcode in the post_content ? |
|
113 | - if ( strpos( $post->post_content, $EES_Shortcode ) !== false ) { |
|
114 | - // map shortcode to post names and post IDs |
|
115 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] = $post_ID; |
|
116 | - // and add this shortcode to the tracking for the blog page |
|
117 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, |
|
118 | - $post_ID ); |
|
119 | - $update_post_shortcodes = true; |
|
120 | - } else { |
|
121 | - // shortcode is not present in post content, so check if we were tracking it previously |
|
122 | - // stop tracking if shortcode is not used in this specific post |
|
123 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ) ) { |
|
124 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ); |
|
125 | - $update_post_shortcodes = true; |
|
126 | - } |
|
127 | - // make sure that something is set for the shortcode posts (even though we may remove this) |
|
128 | - $shortcode_posts = isset( |
|
129 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
130 | - ) |
|
131 | - ? \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
132 | - : array(); |
|
133 | - // and stop tracking for this shortcode on the blog page if it is not used |
|
134 | - $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
135 | - $post_ID, |
|
136 | - $EES_Shortcode, |
|
137 | - $shortcode_posts, |
|
138 | - $page_for_posts, |
|
139 | - $update_post_shortcodes |
|
140 | - ) |
|
141 | - ? true |
|
142 | - : $update_post_shortcodes; |
|
143 | - } |
|
144 | - } |
|
145 | - if ( $update_post_shortcodes ) { |
|
146 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * set_post_shortcodes_for_posts_page (plz note: shortcodes is plural) |
|
155 | - * called when updating the WordPress Posts Page, |
|
156 | - * and adds shortcode tracking for the Posts Page, for all shortcodes currently tracked on individual posts |
|
157 | - * |
|
158 | - * @access protected |
|
159 | - * @param string $page_for_posts |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - protected static function set_post_shortcodes_for_posts_page( $page_for_posts ) |
|
163 | - { |
|
164 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
165 | - // loop thru shortcodes |
|
166 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
167 | - foreach ( $post_shortcodes as $EES_Shortcode => $post_ID ) { |
|
168 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ); |
|
169 | - } |
|
170 | - } |
|
171 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * set_post_shortcode_for_posts_page (plz note: shortcode is singular) |
|
178 | - * adds Posts Page shortcode tracking for the supplied shortcode for an individual post |
|
179 | - * |
|
180 | - * @access protected |
|
181 | - * @param string $page_for_posts |
|
182 | - * @param $EES_Shortcode |
|
183 | - * @param $post_ID |
|
184 | - */ |
|
185 | - protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ) |
|
186 | - { |
|
187 | - // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
188 | - $critical_shortcodes = \EE_Registry::CFG()->core->get_critical_pages_shortcodes_array(); |
|
189 | - // if the shortcode is NOT one of the critical page shortcodes like ESPRESSO_TXN_PAGE |
|
190 | - if ( in_array( $EES_Shortcode, $critical_shortcodes ) ) { |
|
191 | - return; |
|
192 | - } |
|
193 | - // add shortcode to "Posts page" tracking |
|
194 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
195 | - // make sure tracking is in form of an array |
|
196 | - if ( ! is_array( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
197 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( |
|
198 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] => true, |
|
199 | - ); |
|
200 | - } |
|
201 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] += array( $post_ID => true ); |
|
202 | - } else { |
|
203 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( $post_ID => true ); |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * unset_post_shortcodes_on_delete |
|
211 | - * |
|
212 | - * @access protected |
|
213 | - * @param int $ID |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - public static function unset_post_shortcodes_on_delete( $ID ) |
|
217 | - { |
|
218 | - $update_post_shortcodes = false; |
|
219 | - // post on frontpage ? |
|
220 | - $page_for_posts = \EE_Config::get_page_for_posts(); |
|
221 | - // looking for any references to this post |
|
222 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
223 | - // is this the "Posts Page" (blog) ? |
|
224 | - if ( $post_name === $page_for_posts ) { |
|
225 | - // loop thru shortcodes registered for the posts page |
|
226 | - foreach ( $post_shortcodes as $shortcode_class => $shortcode_posts ) { |
|
227 | - $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
228 | - $ID, |
|
229 | - $shortcode_class, |
|
230 | - $shortcode_posts, |
|
231 | - $page_for_posts, |
|
232 | - $update_post_shortcodes |
|
233 | - ) |
|
234 | - ? true |
|
235 | - : $update_post_shortcodes; |
|
236 | - } |
|
237 | - } else { |
|
238 | - // loop thru shortcodes registered for each page |
|
239 | - foreach ( $post_shortcodes as $shortcode_class => $post_ID ) { |
|
240 | - // if this is page is being deleted, then don't track any post shortcodes for it |
|
241 | - if ( $post_ID === $ID ) { |
|
242 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post_name ] ); |
|
243 | - $update_post_shortcodes = true; |
|
244 | - } |
|
245 | - } |
|
246 | - } |
|
247 | - } |
|
248 | - if ( $update_post_shortcodes ) { |
|
249 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * unset_post_shortcodes_on_delete |
|
257 | - * |
|
258 | - * @access protected |
|
259 | - * @param int $ID |
|
260 | - * @param $shortcode_class |
|
261 | - * @param $shortcode_posts |
|
262 | - * @param $page_for_posts |
|
263 | - * @param bool $update_post_shortcodes |
|
264 | - * @return bool |
|
265 | - */ |
|
266 | - protected static function unset_posts_page_shortcode_for_post( |
|
267 | - $ID, |
|
268 | - $shortcode_class, |
|
269 | - $shortcode_posts, |
|
270 | - $page_for_posts, |
|
271 | - $update_post_shortcodes = false |
|
272 | - ) { |
|
273 | - // make sure that an array of post IDs is being tracked for each shortcode |
|
274 | - if ( ! is_array( $shortcode_posts ) ) { |
|
275 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] = array( |
|
276 | - $shortcode_posts => true, |
|
277 | - ); |
|
278 | - $update_post_shortcodes = true; |
|
279 | - } |
|
280 | - // now if the ID of the post being deleted is in the $shortcode_posts array |
|
281 | - if ( is_array( $shortcode_posts ) && isset( $shortcode_posts[ $ID ] ) ) { |
|
282 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ][ $ID ] ); |
|
283 | - $update_post_shortcodes = true; |
|
284 | - } |
|
285 | - // if nothing is registered for that shortcode anymore, then delete the shortcode altogether |
|
286 | - if ( empty( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ) ) { |
|
287 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ); |
|
288 | - $update_post_shortcodes = true; |
|
289 | - } |
|
290 | - return $update_post_shortcodes; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * update_post_shortcodes |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @param $page_for_posts |
|
300 | - * @return void |
|
301 | - */ |
|
302 | - public static function update_post_shortcodes( $page_for_posts = '' ) |
|
303 | - { |
|
304 | - // make sure page_for_posts is set |
|
305 | - $page_for_posts = ! empty( $page_for_posts ) |
|
306 | - ? $page_for_posts |
|
307 | - : \EE_Config::get_page_for_posts(); |
|
308 | - // allow others to mess stuff up :D |
|
309 | - do_action( |
|
310 | - 'AHEE__\EventEspresso\core\admin\PostShortcodeTracking__update_post_shortcodes', |
|
311 | - \EE_Config::instance()->core->post_shortcodes, |
|
312 | - $page_for_posts |
|
313 | - ); |
|
314 | - // keep old hookpoint for now, will deprecate later |
|
315 | - do_action( |
|
316 | - 'AHEE__EE_Config__update_post_shortcodes', |
|
317 | - \EE_Config::instance()->core->post_shortcodes, |
|
318 | - $page_for_posts |
|
319 | - ); |
|
320 | - // verify that post_shortcodes is set |
|
321 | - \EE_Config::instance()->core->post_shortcodes = isset( \EE_Config::instance()->core->post_shortcodes ) |
|
322 | - && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
323 | - ? \EE_Config::instance()->core->post_shortcodes |
|
324 | - : array(); |
|
325 | - // cycle thru post_shortcodes |
|
326 | - foreach ( \EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes ) { |
|
327 | - // are there any shortcodes to track ? |
|
328 | - if ( ! empty( $shortcodes ) ) { |
|
329 | - // skip the posts page, because we want all shortcodes registered for it |
|
330 | - if ( $post_name === $page_for_posts ) { |
|
331 | - continue; |
|
332 | - } |
|
333 | - // loop thru list of tracked shortcodes |
|
334 | - foreach ( $shortcodes as $shortcode => $post_id ) { |
|
335 | - // make sure post still exists |
|
336 | - $post = get_post( $post_id ); |
|
337 | - // check that the post name matches what we have saved |
|
338 | - if ( $post && $post->post_name === $post_name ) { |
|
339 | - // if so, then break before hitting the unset below |
|
340 | - continue; |
|
341 | - } |
|
342 | - // we don't like missing posts around here >:( |
|
343 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
344 | - } |
|
345 | - } else { |
|
346 | - // you got no shortcodes to keep track of ! |
|
347 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
348 | - } |
|
349 | - } |
|
350 | - // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
351 | - $critical_shortcodes = \EE_Config::instance()->core->get_critical_pages_shortcodes_array(); |
|
352 | - $critical_shortcodes = array_flip( $critical_shortcodes ); |
|
353 | - foreach ( $critical_shortcodes as $critical_shortcode ) { |
|
354 | - unset( \EE_Config::instance()->core->post_shortcodes[ $page_for_posts ][ $critical_shortcode ] ); |
|
355 | - } |
|
356 | - //only show errors |
|
357 | - \EE_Config::instance()->update_espresso_config(); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * reset_page_for_posts_on_initial_set |
|
364 | - * if an admin is on the WP Reading Settings page and sets the option for "Posts page", |
|
365 | - * when it had previously been unset, |
|
366 | - * then we need to attribute any actively used shortcodes to the new blog page |
|
367 | - * |
|
368 | - * @access public |
|
369 | - * @param string $option |
|
370 | - * @param string $value |
|
371 | - * @return void |
|
372 | - */ |
|
373 | - public static function reset_page_for_posts_on_initial_set( $option, $value ) |
|
374 | - { |
|
375 | - PostShortcodeTracking::reset_page_for_posts_on_change( $option, '', $value ); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * reset_page_for_posts_on_change |
|
382 | - * if an admin is on the WP Reading Settings page and changes the option for "Posts page", |
|
383 | - * then we need to attribute any actively used shortcodes for the previous blog page to the new blog page |
|
384 | - * |
|
385 | - * @access public |
|
386 | - * @param string $option |
|
387 | - * @param string $old_value |
|
388 | - * @param string $value |
|
389 | - * @return void |
|
390 | - */ |
|
391 | - public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' ) |
|
392 | - { |
|
393 | - if ( $option === 'page_for_posts' ) { |
|
394 | - global $wpdb; |
|
395 | - $table = $wpdb->posts; |
|
396 | - $SQL = "SELECT post_name from $table WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
397 | - $new_page_for_posts = $value ? $wpdb->get_var( $wpdb->prepare( $SQL, $value ) ) : 'posts'; |
|
398 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $new_page_for_posts ); |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * reset_page_for_posts_on_delete |
|
406 | - * if an admin deletes a page designated as the WP "Posts page", |
|
407 | - * then we need to attribute any actively used shortcodes for that blog page to a generic 'posts' page |
|
408 | - * |
|
409 | - * @access public |
|
410 | - * @param string $option |
|
411 | - * @return void |
|
412 | - */ |
|
413 | - public static function reset_page_for_posts_on_delete( $option ) |
|
414 | - { |
|
415 | - if ( $option === 'page_for_posts' ) { |
|
416 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( 'posts' ); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * @param array|string $shortcodes |
|
424 | - * @param bool $index_results if passing more than one shortcode for the $shortcodes parameter above, |
|
425 | - * then setting this to true, will return as associative array indexed by |
|
426 | - * the shortcodes. If false, then the returned array will be unindexed |
|
427 | - * @return array |
|
428 | - */ |
|
429 | - public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true ) |
|
430 | - { |
|
431 | - $post_ids = array(); |
|
432 | - if ( is_array( $shortcodes ) ) { |
|
433 | - foreach ( $shortcodes as $shortcode ) { |
|
434 | - $new_post_ids = PostShortcodeTracking::get_post_ids_for_shortcode( |
|
435 | - $shortcode, |
|
436 | - $index_results |
|
437 | - ); |
|
438 | - foreach ( $new_post_ids as $new_post_id ) { |
|
439 | - if ( $index_results ) { |
|
440 | - $post_ids[ $shortcode ][ $new_post_id ] = $new_post_id; |
|
441 | - } else { |
|
442 | - $post_ids[ $new_post_id ] = $new_post_id; |
|
443 | - } |
|
444 | - } |
|
445 | - } |
|
446 | - } else { |
|
447 | - $shortcode = strtoupper( $shortcodes ); |
|
448 | - $shortcode = strpos( $shortcode, 'ESPRESSO_' ) !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
449 | - $page_for_posts = \EE_Config::get_page_for_posts(); |
|
450 | - // looking for any references to this post |
|
451 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
452 | - // if this is the "Posts Page" (blog), then skip it |
|
453 | - if ( $post_name === $page_for_posts ) { |
|
454 | - continue; |
|
455 | - } |
|
456 | - // loop thru shortcodes registered for each page, and grab post id for matches |
|
457 | - foreach ( (array) $post_shortcodes as $post_shortcode => $post_ID ) { |
|
458 | - if ( $post_shortcode === $shortcode ) { |
|
459 | - $post_ids[ $post_ID ] = $post_ID; |
|
460 | - } |
|
461 | - } |
|
462 | - } |
|
463 | - } |
|
464 | - return $post_ids; |
|
465 | - } |
|
22 | + /** |
|
23 | + * set_hooks_admin |
|
24 | + * |
|
25 | + * @access public |
|
26 | + */ |
|
27 | + public static function set_hooks_admin() |
|
28 | + { |
|
29 | + add_action( |
|
30 | + 'save_post', |
|
31 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save' ), |
|
32 | + 100, |
|
33 | + 2 |
|
34 | + ); |
|
35 | + add_action( |
|
36 | + 'delete_post', |
|
37 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete' ), |
|
38 | + 100, |
|
39 | + 1 |
|
40 | + ); |
|
41 | + add_action( |
|
42 | + 'add_option_page_for_posts', |
|
43 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set' ), |
|
44 | + 100, |
|
45 | + 2 |
|
46 | + ); |
|
47 | + add_action( |
|
48 | + 'update_option', |
|
49 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change' ), |
|
50 | + 100, |
|
51 | + 3 |
|
52 | + ); |
|
53 | + add_action( |
|
54 | + 'delete_option', |
|
55 | + array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete' ), |
|
56 | + 100, |
|
57 | + 1 |
|
58 | + ); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * parse_post_content_on_save |
|
65 | + * any time a post is saved, we need to check for any EE shortcodes that may be embedded in the content, |
|
66 | + * and then track what posts those shortcodes are on, so that we can initialize shortcodes well before |
|
67 | + * the_content() runs. this allows us to do things like enqueue scripts for shortcodes ONLY on the pages the |
|
68 | + * shortcodes are actually used on |
|
69 | + * |
|
70 | + * @access public |
|
71 | + * @param int $post_ID |
|
72 | + * @param \WP_Post $post |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public static function parse_post_content_on_save( $post_ID, $post ) |
|
76 | + { |
|
77 | + // if the post is trashed, then let's remove our post shortcode tracking |
|
78 | + if ( $post instanceof \WP_Post && $post->post_status === 'trash' ) { |
|
79 | + PostShortcodeTracking::unset_post_shortcodes_on_delete( $post_ID ); |
|
80 | + return; |
|
81 | + } |
|
82 | + // default post types |
|
83 | + $post_types = array( 'post' => 0, 'page' => 1 ); |
|
84 | + // add CPTs |
|
85 | + $CPTs = \EE_Register_CPTs::get_CPTs(); |
|
86 | + $post_types = array_merge( $post_types, $CPTs ); |
|
87 | + // for default or CPT posts... |
|
88 | + if ( isset( $post_types[ $post->post_type ] ) ) { |
|
89 | + // post on frontpage ? |
|
90 | + $page_for_posts = \EE_Config::get_page_for_posts(); |
|
91 | + if ( $post->post_name === $page_for_posts ) { |
|
92 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page( $page_for_posts ); |
|
93 | + return; |
|
94 | + } |
|
95 | + // array of shortcodes indexed by post name |
|
96 | + \EE_Registry::CFG()->core->post_shortcodes = isset( \EE_Registry::CFG()->core->post_shortcodes ) |
|
97 | + ? \EE_Registry::CFG()->core->post_shortcodes |
|
98 | + : array(); |
|
99 | + // whether to proceed with update |
|
100 | + $update_post_shortcodes = false; |
|
101 | + // empty both arrays |
|
102 | + \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ] = array(); |
|
103 | + // check that posts page is already being tracked |
|
104 | + if ( ! isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] ) ) { |
|
105 | + // if not, then ensure that it is properly added |
|
106 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
107 | + } |
|
108 | + // loop thru shortcodes |
|
109 | + foreach ( \EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir ) { |
|
110 | + // convert to UPPERCASE to get actual shortcode |
|
111 | + $EES_Shortcode = strtoupper( $EES_Shortcode ); |
|
112 | + // is the shortcode in the post_content ? |
|
113 | + if ( strpos( $post->post_content, $EES_Shortcode ) !== false ) { |
|
114 | + // map shortcode to post names and post IDs |
|
115 | + \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] = $post_ID; |
|
116 | + // and add this shortcode to the tracking for the blog page |
|
117 | + PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, |
|
118 | + $post_ID ); |
|
119 | + $update_post_shortcodes = true; |
|
120 | + } else { |
|
121 | + // shortcode is not present in post content, so check if we were tracking it previously |
|
122 | + // stop tracking if shortcode is not used in this specific post |
|
123 | + if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ) ) { |
|
124 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ); |
|
125 | + $update_post_shortcodes = true; |
|
126 | + } |
|
127 | + // make sure that something is set for the shortcode posts (even though we may remove this) |
|
128 | + $shortcode_posts = isset( |
|
129 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
130 | + ) |
|
131 | + ? \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
132 | + : array(); |
|
133 | + // and stop tracking for this shortcode on the blog page if it is not used |
|
134 | + $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
135 | + $post_ID, |
|
136 | + $EES_Shortcode, |
|
137 | + $shortcode_posts, |
|
138 | + $page_for_posts, |
|
139 | + $update_post_shortcodes |
|
140 | + ) |
|
141 | + ? true |
|
142 | + : $update_post_shortcodes; |
|
143 | + } |
|
144 | + } |
|
145 | + if ( $update_post_shortcodes ) { |
|
146 | + PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * set_post_shortcodes_for_posts_page (plz note: shortcodes is plural) |
|
155 | + * called when updating the WordPress Posts Page, |
|
156 | + * and adds shortcode tracking for the Posts Page, for all shortcodes currently tracked on individual posts |
|
157 | + * |
|
158 | + * @access protected |
|
159 | + * @param string $page_for_posts |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + protected static function set_post_shortcodes_for_posts_page( $page_for_posts ) |
|
163 | + { |
|
164 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
165 | + // loop thru shortcodes |
|
166 | + foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
167 | + foreach ( $post_shortcodes as $EES_Shortcode => $post_ID ) { |
|
168 | + PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ); |
|
169 | + } |
|
170 | + } |
|
171 | + PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * set_post_shortcode_for_posts_page (plz note: shortcode is singular) |
|
178 | + * adds Posts Page shortcode tracking for the supplied shortcode for an individual post |
|
179 | + * |
|
180 | + * @access protected |
|
181 | + * @param string $page_for_posts |
|
182 | + * @param $EES_Shortcode |
|
183 | + * @param $post_ID |
|
184 | + */ |
|
185 | + protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ) |
|
186 | + { |
|
187 | + // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
188 | + $critical_shortcodes = \EE_Registry::CFG()->core->get_critical_pages_shortcodes_array(); |
|
189 | + // if the shortcode is NOT one of the critical page shortcodes like ESPRESSO_TXN_PAGE |
|
190 | + if ( in_array( $EES_Shortcode, $critical_shortcodes ) ) { |
|
191 | + return; |
|
192 | + } |
|
193 | + // add shortcode to "Posts page" tracking |
|
194 | + if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
195 | + // make sure tracking is in form of an array |
|
196 | + if ( ! is_array( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
197 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( |
|
198 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] => true, |
|
199 | + ); |
|
200 | + } |
|
201 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] += array( $post_ID => true ); |
|
202 | + } else { |
|
203 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( $post_ID => true ); |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * unset_post_shortcodes_on_delete |
|
211 | + * |
|
212 | + * @access protected |
|
213 | + * @param int $ID |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + public static function unset_post_shortcodes_on_delete( $ID ) |
|
217 | + { |
|
218 | + $update_post_shortcodes = false; |
|
219 | + // post on frontpage ? |
|
220 | + $page_for_posts = \EE_Config::get_page_for_posts(); |
|
221 | + // looking for any references to this post |
|
222 | + foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
223 | + // is this the "Posts Page" (blog) ? |
|
224 | + if ( $post_name === $page_for_posts ) { |
|
225 | + // loop thru shortcodes registered for the posts page |
|
226 | + foreach ( $post_shortcodes as $shortcode_class => $shortcode_posts ) { |
|
227 | + $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
|
228 | + $ID, |
|
229 | + $shortcode_class, |
|
230 | + $shortcode_posts, |
|
231 | + $page_for_posts, |
|
232 | + $update_post_shortcodes |
|
233 | + ) |
|
234 | + ? true |
|
235 | + : $update_post_shortcodes; |
|
236 | + } |
|
237 | + } else { |
|
238 | + // loop thru shortcodes registered for each page |
|
239 | + foreach ( $post_shortcodes as $shortcode_class => $post_ID ) { |
|
240 | + // if this is page is being deleted, then don't track any post shortcodes for it |
|
241 | + if ( $post_ID === $ID ) { |
|
242 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $post_name ] ); |
|
243 | + $update_post_shortcodes = true; |
|
244 | + } |
|
245 | + } |
|
246 | + } |
|
247 | + } |
|
248 | + if ( $update_post_shortcodes ) { |
|
249 | + PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * unset_post_shortcodes_on_delete |
|
257 | + * |
|
258 | + * @access protected |
|
259 | + * @param int $ID |
|
260 | + * @param $shortcode_class |
|
261 | + * @param $shortcode_posts |
|
262 | + * @param $page_for_posts |
|
263 | + * @param bool $update_post_shortcodes |
|
264 | + * @return bool |
|
265 | + */ |
|
266 | + protected static function unset_posts_page_shortcode_for_post( |
|
267 | + $ID, |
|
268 | + $shortcode_class, |
|
269 | + $shortcode_posts, |
|
270 | + $page_for_posts, |
|
271 | + $update_post_shortcodes = false |
|
272 | + ) { |
|
273 | + // make sure that an array of post IDs is being tracked for each shortcode |
|
274 | + if ( ! is_array( $shortcode_posts ) ) { |
|
275 | + \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] = array( |
|
276 | + $shortcode_posts => true, |
|
277 | + ); |
|
278 | + $update_post_shortcodes = true; |
|
279 | + } |
|
280 | + // now if the ID of the post being deleted is in the $shortcode_posts array |
|
281 | + if ( is_array( $shortcode_posts ) && isset( $shortcode_posts[ $ID ] ) ) { |
|
282 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ][ $ID ] ); |
|
283 | + $update_post_shortcodes = true; |
|
284 | + } |
|
285 | + // if nothing is registered for that shortcode anymore, then delete the shortcode altogether |
|
286 | + if ( empty( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ) ) { |
|
287 | + unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ); |
|
288 | + $update_post_shortcodes = true; |
|
289 | + } |
|
290 | + return $update_post_shortcodes; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * update_post_shortcodes |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @param $page_for_posts |
|
300 | + * @return void |
|
301 | + */ |
|
302 | + public static function update_post_shortcodes( $page_for_posts = '' ) |
|
303 | + { |
|
304 | + // make sure page_for_posts is set |
|
305 | + $page_for_posts = ! empty( $page_for_posts ) |
|
306 | + ? $page_for_posts |
|
307 | + : \EE_Config::get_page_for_posts(); |
|
308 | + // allow others to mess stuff up :D |
|
309 | + do_action( |
|
310 | + 'AHEE__\EventEspresso\core\admin\PostShortcodeTracking__update_post_shortcodes', |
|
311 | + \EE_Config::instance()->core->post_shortcodes, |
|
312 | + $page_for_posts |
|
313 | + ); |
|
314 | + // keep old hookpoint for now, will deprecate later |
|
315 | + do_action( |
|
316 | + 'AHEE__EE_Config__update_post_shortcodes', |
|
317 | + \EE_Config::instance()->core->post_shortcodes, |
|
318 | + $page_for_posts |
|
319 | + ); |
|
320 | + // verify that post_shortcodes is set |
|
321 | + \EE_Config::instance()->core->post_shortcodes = isset( \EE_Config::instance()->core->post_shortcodes ) |
|
322 | + && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
323 | + ? \EE_Config::instance()->core->post_shortcodes |
|
324 | + : array(); |
|
325 | + // cycle thru post_shortcodes |
|
326 | + foreach ( \EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes ) { |
|
327 | + // are there any shortcodes to track ? |
|
328 | + if ( ! empty( $shortcodes ) ) { |
|
329 | + // skip the posts page, because we want all shortcodes registered for it |
|
330 | + if ( $post_name === $page_for_posts ) { |
|
331 | + continue; |
|
332 | + } |
|
333 | + // loop thru list of tracked shortcodes |
|
334 | + foreach ( $shortcodes as $shortcode => $post_id ) { |
|
335 | + // make sure post still exists |
|
336 | + $post = get_post( $post_id ); |
|
337 | + // check that the post name matches what we have saved |
|
338 | + if ( $post && $post->post_name === $post_name ) { |
|
339 | + // if so, then break before hitting the unset below |
|
340 | + continue; |
|
341 | + } |
|
342 | + // we don't like missing posts around here >:( |
|
343 | + unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
344 | + } |
|
345 | + } else { |
|
346 | + // you got no shortcodes to keep track of ! |
|
347 | + unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
348 | + } |
|
349 | + } |
|
350 | + // critical page shortcodes that we do NOT want added to the Posts page (blog) |
|
351 | + $critical_shortcodes = \EE_Config::instance()->core->get_critical_pages_shortcodes_array(); |
|
352 | + $critical_shortcodes = array_flip( $critical_shortcodes ); |
|
353 | + foreach ( $critical_shortcodes as $critical_shortcode ) { |
|
354 | + unset( \EE_Config::instance()->core->post_shortcodes[ $page_for_posts ][ $critical_shortcode ] ); |
|
355 | + } |
|
356 | + //only show errors |
|
357 | + \EE_Config::instance()->update_espresso_config(); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * reset_page_for_posts_on_initial_set |
|
364 | + * if an admin is on the WP Reading Settings page and sets the option for "Posts page", |
|
365 | + * when it had previously been unset, |
|
366 | + * then we need to attribute any actively used shortcodes to the new blog page |
|
367 | + * |
|
368 | + * @access public |
|
369 | + * @param string $option |
|
370 | + * @param string $value |
|
371 | + * @return void |
|
372 | + */ |
|
373 | + public static function reset_page_for_posts_on_initial_set( $option, $value ) |
|
374 | + { |
|
375 | + PostShortcodeTracking::reset_page_for_posts_on_change( $option, '', $value ); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * reset_page_for_posts_on_change |
|
382 | + * if an admin is on the WP Reading Settings page and changes the option for "Posts page", |
|
383 | + * then we need to attribute any actively used shortcodes for the previous blog page to the new blog page |
|
384 | + * |
|
385 | + * @access public |
|
386 | + * @param string $option |
|
387 | + * @param string $old_value |
|
388 | + * @param string $value |
|
389 | + * @return void |
|
390 | + */ |
|
391 | + public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' ) |
|
392 | + { |
|
393 | + if ( $option === 'page_for_posts' ) { |
|
394 | + global $wpdb; |
|
395 | + $table = $wpdb->posts; |
|
396 | + $SQL = "SELECT post_name from $table WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
397 | + $new_page_for_posts = $value ? $wpdb->get_var( $wpdb->prepare( $SQL, $value ) ) : 'posts'; |
|
398 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page( $new_page_for_posts ); |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * reset_page_for_posts_on_delete |
|
406 | + * if an admin deletes a page designated as the WP "Posts page", |
|
407 | + * then we need to attribute any actively used shortcodes for that blog page to a generic 'posts' page |
|
408 | + * |
|
409 | + * @access public |
|
410 | + * @param string $option |
|
411 | + * @return void |
|
412 | + */ |
|
413 | + public static function reset_page_for_posts_on_delete( $option ) |
|
414 | + { |
|
415 | + if ( $option === 'page_for_posts' ) { |
|
416 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page( 'posts' ); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * @param array|string $shortcodes |
|
424 | + * @param bool $index_results if passing more than one shortcode for the $shortcodes parameter above, |
|
425 | + * then setting this to true, will return as associative array indexed by |
|
426 | + * the shortcodes. If false, then the returned array will be unindexed |
|
427 | + * @return array |
|
428 | + */ |
|
429 | + public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true ) |
|
430 | + { |
|
431 | + $post_ids = array(); |
|
432 | + if ( is_array( $shortcodes ) ) { |
|
433 | + foreach ( $shortcodes as $shortcode ) { |
|
434 | + $new_post_ids = PostShortcodeTracking::get_post_ids_for_shortcode( |
|
435 | + $shortcode, |
|
436 | + $index_results |
|
437 | + ); |
|
438 | + foreach ( $new_post_ids as $new_post_id ) { |
|
439 | + if ( $index_results ) { |
|
440 | + $post_ids[ $shortcode ][ $new_post_id ] = $new_post_id; |
|
441 | + } else { |
|
442 | + $post_ids[ $new_post_id ] = $new_post_id; |
|
443 | + } |
|
444 | + } |
|
445 | + } |
|
446 | + } else { |
|
447 | + $shortcode = strtoupper( $shortcodes ); |
|
448 | + $shortcode = strpos( $shortcode, 'ESPRESSO_' ) !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
449 | + $page_for_posts = \EE_Config::get_page_for_posts(); |
|
450 | + // looking for any references to this post |
|
451 | + foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
452 | + // if this is the "Posts Page" (blog), then skip it |
|
453 | + if ( $post_name === $page_for_posts ) { |
|
454 | + continue; |
|
455 | + } |
|
456 | + // loop thru shortcodes registered for each page, and grab post id for matches |
|
457 | + foreach ( (array) $post_shortcodes as $post_shortcode => $post_ID ) { |
|
458 | + if ( $post_shortcode === $shortcode ) { |
|
459 | + $post_ids[ $post_ID ] = $post_ID; |
|
460 | + } |
|
461 | + } |
|
462 | + } |
|
463 | + } |
|
464 | + return $post_ids; |
|
465 | + } |
|
466 | 466 | |
467 | 467 | |
468 | 468 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\admin; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -28,31 +28,31 @@ discard block |
||
28 | 28 | { |
29 | 29 | add_action( |
30 | 30 | 'save_post', |
31 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save' ), |
|
31 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'parse_post_content_on_save'), |
|
32 | 32 | 100, |
33 | 33 | 2 |
34 | 34 | ); |
35 | 35 | add_action( |
36 | 36 | 'delete_post', |
37 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete' ), |
|
37 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'unset_post_shortcodes_on_delete'), |
|
38 | 38 | 100, |
39 | 39 | 1 |
40 | 40 | ); |
41 | 41 | add_action( |
42 | 42 | 'add_option_page_for_posts', |
43 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set' ), |
|
43 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_initial_set'), |
|
44 | 44 | 100, |
45 | 45 | 2 |
46 | 46 | ); |
47 | 47 | add_action( |
48 | 48 | 'update_option', |
49 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change' ), |
|
49 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_change'), |
|
50 | 50 | 100, |
51 | 51 | 3 |
52 | 52 | ); |
53 | 53 | add_action( |
54 | 54 | 'delete_option', |
55 | - array( 'EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete' ), |
|
55 | + array('EventEspresso\core\admin\PostShortcodeTracking', 'reset_page_for_posts_on_delete'), |
|
56 | 56 | 100, |
57 | 57 | 1 |
58 | 58 | ); |
@@ -72,63 +72,63 @@ discard block |
||
72 | 72 | * @param \WP_Post $post |
73 | 73 | * @return void |
74 | 74 | */ |
75 | - public static function parse_post_content_on_save( $post_ID, $post ) |
|
75 | + public static function parse_post_content_on_save($post_ID, $post) |
|
76 | 76 | { |
77 | 77 | // if the post is trashed, then let's remove our post shortcode tracking |
78 | - if ( $post instanceof \WP_Post && $post->post_status === 'trash' ) { |
|
79 | - PostShortcodeTracking::unset_post_shortcodes_on_delete( $post_ID ); |
|
78 | + if ($post instanceof \WP_Post && $post->post_status === 'trash') { |
|
79 | + PostShortcodeTracking::unset_post_shortcodes_on_delete($post_ID); |
|
80 | 80 | return; |
81 | 81 | } |
82 | 82 | // default post types |
83 | - $post_types = array( 'post' => 0, 'page' => 1 ); |
|
83 | + $post_types = array('post' => 0, 'page' => 1); |
|
84 | 84 | // add CPTs |
85 | 85 | $CPTs = \EE_Register_CPTs::get_CPTs(); |
86 | - $post_types = array_merge( $post_types, $CPTs ); |
|
86 | + $post_types = array_merge($post_types, $CPTs); |
|
87 | 87 | // for default or CPT posts... |
88 | - if ( isset( $post_types[ $post->post_type ] ) ) { |
|
88 | + if (isset($post_types[$post->post_type])) { |
|
89 | 89 | // post on frontpage ? |
90 | 90 | $page_for_posts = \EE_Config::get_page_for_posts(); |
91 | - if ( $post->post_name === $page_for_posts ) { |
|
92 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $page_for_posts ); |
|
91 | + if ($post->post_name === $page_for_posts) { |
|
92 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page($page_for_posts); |
|
93 | 93 | return; |
94 | 94 | } |
95 | 95 | // array of shortcodes indexed by post name |
96 | - \EE_Registry::CFG()->core->post_shortcodes = isset( \EE_Registry::CFG()->core->post_shortcodes ) |
|
96 | + \EE_Registry::CFG()->core->post_shortcodes = isset(\EE_Registry::CFG()->core->post_shortcodes) |
|
97 | 97 | ? \EE_Registry::CFG()->core->post_shortcodes |
98 | 98 | : array(); |
99 | 99 | // whether to proceed with update |
100 | 100 | $update_post_shortcodes = false; |
101 | 101 | // empty both arrays |
102 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ] = array(); |
|
102 | + \EE_Registry::CFG()->core->post_shortcodes[$post->post_name] = array(); |
|
103 | 103 | // check that posts page is already being tracked |
104 | - if ( ! isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] ) ) { |
|
104 | + if ( ! isset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts])) { |
|
105 | 105 | // if not, then ensure that it is properly added |
106 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
106 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts] = array(); |
|
107 | 107 | } |
108 | 108 | // loop thru shortcodes |
109 | - foreach ( \EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir ) { |
|
109 | + foreach (\EE_Registry::instance()->shortcodes as $EES_Shortcode => $shortcode_dir) { |
|
110 | 110 | // convert to UPPERCASE to get actual shortcode |
111 | - $EES_Shortcode = strtoupper( $EES_Shortcode ); |
|
111 | + $EES_Shortcode = strtoupper($EES_Shortcode); |
|
112 | 112 | // is the shortcode in the post_content ? |
113 | - if ( strpos( $post->post_content, $EES_Shortcode ) !== false ) { |
|
113 | + if (strpos($post->post_content, $EES_Shortcode) !== false) { |
|
114 | 114 | // map shortcode to post names and post IDs |
115 | - \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] = $post_ID; |
|
115 | + \EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode] = $post_ID; |
|
116 | 116 | // and add this shortcode to the tracking for the blog page |
117 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, |
|
118 | - $post_ID ); |
|
117 | + PostShortcodeTracking::set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, |
|
118 | + $post_ID); |
|
119 | 119 | $update_post_shortcodes = true; |
120 | 120 | } else { |
121 | 121 | // shortcode is not present in post content, so check if we were tracking it previously |
122 | 122 | // stop tracking if shortcode is not used in this specific post |
123 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ) ) { |
|
124 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post->post_name ][ $EES_Shortcode ] ); |
|
123 | + if (isset(\EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode])) { |
|
124 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$post->post_name][$EES_Shortcode]); |
|
125 | 125 | $update_post_shortcodes = true; |
126 | 126 | } |
127 | 127 | // make sure that something is set for the shortcode posts (even though we may remove this) |
128 | 128 | $shortcode_posts = isset( |
129 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
129 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] |
|
130 | 130 | ) |
131 | - ? \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] |
|
131 | + ? \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] |
|
132 | 132 | : array(); |
133 | 133 | // and stop tracking for this shortcode on the blog page if it is not used |
134 | 134 | $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | : $update_post_shortcodes; |
143 | 143 | } |
144 | 144 | } |
145 | - if ( $update_post_shortcodes ) { |
|
146 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
145 | + if ($update_post_shortcodes) { |
|
146 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | } |
@@ -159,16 +159,16 @@ discard block |
||
159 | 159 | * @param string $page_for_posts |
160 | 160 | * @return void |
161 | 161 | */ |
162 | - protected static function set_post_shortcodes_for_posts_page( $page_for_posts ) |
|
162 | + protected static function set_post_shortcodes_for_posts_page($page_for_posts) |
|
163 | 163 | { |
164 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ] = array(); |
|
164 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts] = array(); |
|
165 | 165 | // loop thru shortcodes |
166 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
167 | - foreach ( $post_shortcodes as $EES_Shortcode => $post_ID ) { |
|
168 | - PostShortcodeTracking::set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ); |
|
166 | + foreach (\EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
167 | + foreach ($post_shortcodes as $EES_Shortcode => $post_ID) { |
|
168 | + PostShortcodeTracking::set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, $post_ID); |
|
169 | 169 | } |
170 | 170 | } |
171 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
171 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | |
@@ -182,25 +182,25 @@ discard block |
||
182 | 182 | * @param $EES_Shortcode |
183 | 183 | * @param $post_ID |
184 | 184 | */ |
185 | - protected static function set_post_shortcode_for_posts_page( $page_for_posts, $EES_Shortcode, $post_ID ) |
|
185 | + protected static function set_post_shortcode_for_posts_page($page_for_posts, $EES_Shortcode, $post_ID) |
|
186 | 186 | { |
187 | 187 | // critical page shortcodes that we do NOT want added to the Posts page (blog) |
188 | 188 | $critical_shortcodes = \EE_Registry::CFG()->core->get_critical_pages_shortcodes_array(); |
189 | 189 | // if the shortcode is NOT one of the critical page shortcodes like ESPRESSO_TXN_PAGE |
190 | - if ( in_array( $EES_Shortcode, $critical_shortcodes ) ) { |
|
190 | + if (in_array($EES_Shortcode, $critical_shortcodes)) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | // add shortcode to "Posts page" tracking |
194 | - if ( isset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
194 | + if (isset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode])) { |
|
195 | 195 | // make sure tracking is in form of an array |
196 | - if ( ! is_array( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] ) ) { |
|
197 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( |
|
198 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] => true, |
|
196 | + if ( ! is_array(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode])) { |
|
197 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] = array( |
|
198 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] => true, |
|
199 | 199 | ); |
200 | 200 | } |
201 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] += array( $post_ID => true ); |
|
201 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] += array($post_ID => true); |
|
202 | 202 | } else { |
203 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $EES_Shortcode ] = array( $post_ID => true ); |
|
203 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$EES_Shortcode] = array($post_ID => true); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
@@ -213,17 +213,17 @@ discard block |
||
213 | 213 | * @param int $ID |
214 | 214 | * @return void |
215 | 215 | */ |
216 | - public static function unset_post_shortcodes_on_delete( $ID ) |
|
216 | + public static function unset_post_shortcodes_on_delete($ID) |
|
217 | 217 | { |
218 | 218 | $update_post_shortcodes = false; |
219 | 219 | // post on frontpage ? |
220 | 220 | $page_for_posts = \EE_Config::get_page_for_posts(); |
221 | 221 | // looking for any references to this post |
222 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
222 | + foreach (\EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
223 | 223 | // is this the "Posts Page" (blog) ? |
224 | - if ( $post_name === $page_for_posts ) { |
|
224 | + if ($post_name === $page_for_posts) { |
|
225 | 225 | // loop thru shortcodes registered for the posts page |
226 | - foreach ( $post_shortcodes as $shortcode_class => $shortcode_posts ) { |
|
226 | + foreach ($post_shortcodes as $shortcode_class => $shortcode_posts) { |
|
227 | 227 | $update_post_shortcodes = PostShortcodeTracking::unset_posts_page_shortcode_for_post( |
228 | 228 | $ID, |
229 | 229 | $shortcode_class, |
@@ -236,17 +236,17 @@ discard block |
||
236 | 236 | } |
237 | 237 | } else { |
238 | 238 | // loop thru shortcodes registered for each page |
239 | - foreach ( $post_shortcodes as $shortcode_class => $post_ID ) { |
|
239 | + foreach ($post_shortcodes as $shortcode_class => $post_ID) { |
|
240 | 240 | // if this is page is being deleted, then don't track any post shortcodes for it |
241 | - if ( $post_ID === $ID ) { |
|
242 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $post_name ] ); |
|
241 | + if ($post_ID === $ID) { |
|
242 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$post_name]); |
|
243 | 243 | $update_post_shortcodes = true; |
244 | 244 | } |
245 | 245 | } |
246 | 246 | } |
247 | 247 | } |
248 | - if ( $update_post_shortcodes ) { |
|
249 | - PostShortcodeTracking::update_post_shortcodes( $page_for_posts ); |
|
248 | + if ($update_post_shortcodes) { |
|
249 | + PostShortcodeTracking::update_post_shortcodes($page_for_posts); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 | |
@@ -271,20 +271,20 @@ discard block |
||
271 | 271 | $update_post_shortcodes = false |
272 | 272 | ) { |
273 | 273 | // make sure that an array of post IDs is being tracked for each shortcode |
274 | - if ( ! is_array( $shortcode_posts ) ) { |
|
275 | - \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] = array( |
|
274 | + if ( ! is_array($shortcode_posts)) { |
|
275 | + \EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class] = array( |
|
276 | 276 | $shortcode_posts => true, |
277 | 277 | ); |
278 | 278 | $update_post_shortcodes = true; |
279 | 279 | } |
280 | 280 | // now if the ID of the post being deleted is in the $shortcode_posts array |
281 | - if ( is_array( $shortcode_posts ) && isset( $shortcode_posts[ $ID ] ) ) { |
|
282 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ][ $ID ] ); |
|
281 | + if (is_array($shortcode_posts) && isset($shortcode_posts[$ID])) { |
|
282 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class][$ID]); |
|
283 | 283 | $update_post_shortcodes = true; |
284 | 284 | } |
285 | 285 | // if nothing is registered for that shortcode anymore, then delete the shortcode altogether |
286 | - if ( empty( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ) ) { |
|
287 | - unset( \EE_Registry::CFG()->core->post_shortcodes[ $page_for_posts ][ $shortcode_class ] ); |
|
286 | + if (empty(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class])) { |
|
287 | + unset(\EE_Registry::CFG()->core->post_shortcodes[$page_for_posts][$shortcode_class]); |
|
288 | 288 | $update_post_shortcodes = true; |
289 | 289 | } |
290 | 290 | return $update_post_shortcodes; |
@@ -299,10 +299,10 @@ discard block |
||
299 | 299 | * @param $page_for_posts |
300 | 300 | * @return void |
301 | 301 | */ |
302 | - public static function update_post_shortcodes( $page_for_posts = '' ) |
|
302 | + public static function update_post_shortcodes($page_for_posts = '') |
|
303 | 303 | { |
304 | 304 | // make sure page_for_posts is set |
305 | - $page_for_posts = ! empty( $page_for_posts ) |
|
305 | + $page_for_posts = ! empty($page_for_posts) |
|
306 | 306 | ? $page_for_posts |
307 | 307 | : \EE_Config::get_page_for_posts(); |
308 | 308 | // allow others to mess stuff up :D |
@@ -318,40 +318,40 @@ discard block |
||
318 | 318 | $page_for_posts |
319 | 319 | ); |
320 | 320 | // verify that post_shortcodes is set |
321 | - \EE_Config::instance()->core->post_shortcodes = isset( \EE_Config::instance()->core->post_shortcodes ) |
|
322 | - && is_array( \EE_Config::instance()->core->post_shortcodes ) |
|
321 | + \EE_Config::instance()->core->post_shortcodes = isset(\EE_Config::instance()->core->post_shortcodes) |
|
322 | + && is_array(\EE_Config::instance()->core->post_shortcodes) |
|
323 | 323 | ? \EE_Config::instance()->core->post_shortcodes |
324 | 324 | : array(); |
325 | 325 | // cycle thru post_shortcodes |
326 | - foreach ( \EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes ) { |
|
326 | + foreach (\EE_Config::instance()->core->post_shortcodes as $post_name => $shortcodes) { |
|
327 | 327 | // are there any shortcodes to track ? |
328 | - if ( ! empty( $shortcodes ) ) { |
|
328 | + if ( ! empty($shortcodes)) { |
|
329 | 329 | // skip the posts page, because we want all shortcodes registered for it |
330 | - if ( $post_name === $page_for_posts ) { |
|
330 | + if ($post_name === $page_for_posts) { |
|
331 | 331 | continue; |
332 | 332 | } |
333 | 333 | // loop thru list of tracked shortcodes |
334 | - foreach ( $shortcodes as $shortcode => $post_id ) { |
|
334 | + foreach ($shortcodes as $shortcode => $post_id) { |
|
335 | 335 | // make sure post still exists |
336 | - $post = get_post( $post_id ); |
|
336 | + $post = get_post($post_id); |
|
337 | 337 | // check that the post name matches what we have saved |
338 | - if ( $post && $post->post_name === $post_name ) { |
|
338 | + if ($post && $post->post_name === $post_name) { |
|
339 | 339 | // if so, then break before hitting the unset below |
340 | 340 | continue; |
341 | 341 | } |
342 | 342 | // we don't like missing posts around here >:( |
343 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
343 | + unset(\EE_Config::instance()->core->post_shortcodes[$post_name]); |
|
344 | 344 | } |
345 | 345 | } else { |
346 | 346 | // you got no shortcodes to keep track of ! |
347 | - unset( \EE_Config::instance()->core->post_shortcodes[ $post_name ] ); |
|
347 | + unset(\EE_Config::instance()->core->post_shortcodes[$post_name]); |
|
348 | 348 | } |
349 | 349 | } |
350 | 350 | // critical page shortcodes that we do NOT want added to the Posts page (blog) |
351 | 351 | $critical_shortcodes = \EE_Config::instance()->core->get_critical_pages_shortcodes_array(); |
352 | - $critical_shortcodes = array_flip( $critical_shortcodes ); |
|
353 | - foreach ( $critical_shortcodes as $critical_shortcode ) { |
|
354 | - unset( \EE_Config::instance()->core->post_shortcodes[ $page_for_posts ][ $critical_shortcode ] ); |
|
352 | + $critical_shortcodes = array_flip($critical_shortcodes); |
|
353 | + foreach ($critical_shortcodes as $critical_shortcode) { |
|
354 | + unset(\EE_Config::instance()->core->post_shortcodes[$page_for_posts][$critical_shortcode]); |
|
355 | 355 | } |
356 | 356 | //only show errors |
357 | 357 | \EE_Config::instance()->update_espresso_config(); |
@@ -370,9 +370,9 @@ discard block |
||
370 | 370 | * @param string $value |
371 | 371 | * @return void |
372 | 372 | */ |
373 | - public static function reset_page_for_posts_on_initial_set( $option, $value ) |
|
373 | + public static function reset_page_for_posts_on_initial_set($option, $value) |
|
374 | 374 | { |
375 | - PostShortcodeTracking::reset_page_for_posts_on_change( $option, '', $value ); |
|
375 | + PostShortcodeTracking::reset_page_for_posts_on_change($option, '', $value); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -388,14 +388,14 @@ discard block |
||
388 | 388 | * @param string $value |
389 | 389 | * @return void |
390 | 390 | */ |
391 | - public static function reset_page_for_posts_on_change( $option, $old_value = '', $value = '' ) |
|
391 | + public static function reset_page_for_posts_on_change($option, $old_value = '', $value = '') |
|
392 | 392 | { |
393 | - if ( $option === 'page_for_posts' ) { |
|
393 | + if ($option === 'page_for_posts') { |
|
394 | 394 | global $wpdb; |
395 | 395 | $table = $wpdb->posts; |
396 | 396 | $SQL = "SELECT post_name from $table WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
397 | - $new_page_for_posts = $value ? $wpdb->get_var( $wpdb->prepare( $SQL, $value ) ) : 'posts'; |
|
398 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( $new_page_for_posts ); |
|
397 | + $new_page_for_posts = $value ? $wpdb->get_var($wpdb->prepare($SQL, $value)) : 'posts'; |
|
398 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page($new_page_for_posts); |
|
399 | 399 | } |
400 | 400 | } |
401 | 401 | |
@@ -410,10 +410,10 @@ discard block |
||
410 | 410 | * @param string $option |
411 | 411 | * @return void |
412 | 412 | */ |
413 | - public static function reset_page_for_posts_on_delete( $option ) |
|
413 | + public static function reset_page_for_posts_on_delete($option) |
|
414 | 414 | { |
415 | - if ( $option === 'page_for_posts' ) { |
|
416 | - PostShortcodeTracking::set_post_shortcodes_for_posts_page( 'posts' ); |
|
415 | + if ($option === 'page_for_posts') { |
|
416 | + PostShortcodeTracking::set_post_shortcodes_for_posts_page('posts'); |
|
417 | 417 | } |
418 | 418 | } |
419 | 419 | |
@@ -426,37 +426,37 @@ discard block |
||
426 | 426 | * the shortcodes. If false, then the returned array will be unindexed |
427 | 427 | * @return array |
428 | 428 | */ |
429 | - public static function get_post_ids_for_shortcode( $shortcodes, $index_results = true ) |
|
429 | + public static function get_post_ids_for_shortcode($shortcodes, $index_results = true) |
|
430 | 430 | { |
431 | 431 | $post_ids = array(); |
432 | - if ( is_array( $shortcodes ) ) { |
|
433 | - foreach ( $shortcodes as $shortcode ) { |
|
432 | + if (is_array($shortcodes)) { |
|
433 | + foreach ($shortcodes as $shortcode) { |
|
434 | 434 | $new_post_ids = PostShortcodeTracking::get_post_ids_for_shortcode( |
435 | 435 | $shortcode, |
436 | 436 | $index_results |
437 | 437 | ); |
438 | - foreach ( $new_post_ids as $new_post_id ) { |
|
439 | - if ( $index_results ) { |
|
440 | - $post_ids[ $shortcode ][ $new_post_id ] = $new_post_id; |
|
438 | + foreach ($new_post_ids as $new_post_id) { |
|
439 | + if ($index_results) { |
|
440 | + $post_ids[$shortcode][$new_post_id] = $new_post_id; |
|
441 | 441 | } else { |
442 | - $post_ids[ $new_post_id ] = $new_post_id; |
|
442 | + $post_ids[$new_post_id] = $new_post_id; |
|
443 | 443 | } |
444 | 444 | } |
445 | 445 | } |
446 | 446 | } else { |
447 | - $shortcode = strtoupper( $shortcodes ); |
|
448 | - $shortcode = strpos( $shortcode, 'ESPRESSO_' ) !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
447 | + $shortcode = strtoupper($shortcodes); |
|
448 | + $shortcode = strpos($shortcode, 'ESPRESSO_') !== 0 ? "ESPRESSO_{$shortcode}" : $shortcode; |
|
449 | 449 | $page_for_posts = \EE_Config::get_page_for_posts(); |
450 | 450 | // looking for any references to this post |
451 | - foreach ( \EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes ) { |
|
451 | + foreach (\EE_Registry::CFG()->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
452 | 452 | // if this is the "Posts Page" (blog), then skip it |
453 | - if ( $post_name === $page_for_posts ) { |
|
453 | + if ($post_name === $page_for_posts) { |
|
454 | 454 | continue; |
455 | 455 | } |
456 | 456 | // loop thru shortcodes registered for each page, and grab post id for matches |
457 | - foreach ( (array) $post_shortcodes as $post_shortcode => $post_ID ) { |
|
458 | - if ( $post_shortcode === $shortcode ) { |
|
459 | - $post_ids[ $post_ID ] = $post_ID; |
|
457 | + foreach ((array) $post_shortcodes as $post_shortcode => $post_ID) { |
|
458 | + if ($post_shortcode === $shortcode) { |
|
459 | + $post_ids[$post_ID] = $post_ID; |
|
460 | 460 | } |
461 | 461 | } |
462 | 462 | } |
@@ -5,10 +5,10 @@ discard block |
||
5 | 5 | ?> |
6 | 6 | <div class="padding"> |
7 | 7 | |
8 | - <h2 class="ee-admin-settings-hdr"><?php _e('Countries and States/Provinces', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_select_info');?></h2> |
|
8 | + <h2 class="ee-admin-settings-hdr"><?php _e('Countries and States/Provinces', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_select_info'); ?></h2> |
|
9 | 9 | <table class="form-table"> |
10 | 10 | <tbody> |
11 | - <?php echo EEH_Form_Fields::generate_form_input( $countries ); ?> |
|
11 | + <?php echo EEH_Form_Fields::generate_form_input($countries); ?> |
|
12 | 12 | </tbody> |
13 | 13 | </table> |
14 | 14 | <br/> |
@@ -16,12 +16,12 @@ discard block |
||
16 | 16 | <?php _e('The country that is selected above will populate the Country Details settings and the options for States/Provinces. This information will be used throughout Event Espresso including for registration purposes and how currency is displayed. If you make a change to the country on this page, it is important that you also update your Contact Information on the Your Organization tab.', 'event_espresso'); ?> |
17 | 17 | </p> |
18 | 18 | <div id="country-details-settings-dv"> |
19 | - <h2 class="ee-admin-settings-hdr"><?php _e('Country Details', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_details_info');?></h2> |
|
19 | + <h2 class="ee-admin-settings-hdr"><?php _e('Country Details', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_details_info'); ?></h2> |
|
20 | 20 | <div id="country-details-dv"><?php echo $country_details_settings; ?></div> |
21 | 21 | </div> |
22 | 22 | |
23 | 23 | <div id="country-states-settings-dv"> |
24 | - <h2 class="ee-admin-settings-hdr"><?php _e( 'States/Provinces', 'event_espresso' );?> <?php echo EEH_Template::get_help_tab_link('country_states_info');?></h2> |
|
24 | + <h2 class="ee-admin-settings-hdr"><?php _e('States/Provinces', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('country_states_info'); ?></h2> |
|
25 | 25 | <div id="country-states-dv"><?php echo $country_states_settings; ?></div> |
26 | 26 | </div> |
27 | 27 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | ?> |
7 | 7 | <div class="padding"> |
8 | 8 | |
9 | - <?php do_action( 'AHEE__admin_option_settings__template__before', $template_args ); ?> |
|
9 | + <?php do_action('AHEE__admin_option_settings__template__before', $template_args); ?> |
|
10 | 10 | |
11 | 11 | <?php /* @todo put back once we have a dashboard widget to use |
12 | 12 | <h2 class="ee-admin-settings-hdr"> |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | </table> |
72 | 72 | <?php endif; */ ?> |
73 | 73 | |
74 | - <?php if ( EE_Registry::instance()->CAP->current_user_can( 'manage_options', 'display_admin_settings_options_promote_and_affiliate' ) ) : ?> |
|
74 | + <?php if (EE_Registry::instance()->CAP->current_user_can('manage_options', 'display_admin_settings_options_promote_and_affiliate')) : ?> |
|
75 | 75 | <h2 class="ee-admin-settings-hdr"> |
76 | 76 | <?php _e('Promote Event Espresso', 'event_espresso'); ?> <span id="affiliate_info"><?php echo EEH_Template::get_help_tab_link('affiliate_info'); ?></span> |
77 | 77 | </h2> |
@@ -86,14 +86,14 @@ discard block |
||
86 | 86 | </label> |
87 | 87 | </th> |
88 | 88 | <td> |
89 | - <?php echo EEH_Form_Fields::select_input('show_reg_footer', $values, $show_reg_footer ); ?> |
|
89 | + <?php echo EEH_Form_Fields::select_input('show_reg_footer', $values, $show_reg_footer); ?> |
|
90 | 90 | </td> |
91 | 91 | </tr> |
92 | 92 | |
93 | 93 | <tr> |
94 | 94 | <th> |
95 | 95 | <label for="affiliate_id"> |
96 | - <?php printf( __('Event Espresso %sAffiliate%s ID', 'event_espresso'), '<a href="http://eventespresso.com/affiliates/" target="_blank">', '</a>' ); ?> |
|
96 | + <?php printf(__('Event Espresso %sAffiliate%s ID', 'event_espresso'), '<a href="http://eventespresso.com/affiliates/" target="_blank">', '</a>'); ?> |
|
97 | 97 | </label> |
98 | 98 | </th> |
99 | 99 | <td> |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | </label> |
124 | 124 | </th> |
125 | 125 | <td> |
126 | - <?php echo EEH_Form_Fields::select_input('help_tour_activation', $values, $help_tour_activation ); ?> |
|
126 | + <?php echo EEH_Form_Fields::select_input('help_tour_activation', $values, $help_tour_activation); ?> |
|
127 | 127 | </td> |
128 | 128 | </tr> |
129 | 129 | </tbody> |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * This prepares data for message types that send messages for multiple registrations (that could span multiple |
@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | * @throws EE_Error |
21 | 21 | * @access protected |
22 | 22 | */ |
23 | - public function __construct( $data = array() ) { |
|
23 | + public function __construct($data = array()) { |
|
24 | 24 | |
25 | 25 | //validate that the first element in the array is an EE_Registration object. |
26 | - if ( ! reset( $data ) instanceof EE_Registration ) { |
|
27 | - throw new EE_Error( __( 'The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', 'event_espresso' ) ); |
|
26 | + if ( ! reset($data) instanceof EE_Registration) { |
|
27 | + throw new EE_Error(__('The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', 'event_espresso')); |
|
28 | 28 | } |
29 | - parent::__construct( $data ); |
|
29 | + parent::__construct($data); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | |
@@ -58,10 +58,10 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return EE_Registration[] The data being prepared for the db |
60 | 60 | */ |
61 | - static public function convert_data_for_persistent_storage( $registrations ) { |
|
61 | + static public function convert_data_for_persistent_storage($registrations) { |
|
62 | 62 | if ( |
63 | - ! is_array( $registrations ) |
|
64 | - || ! reset( $registrations ) instanceof EE_Registration |
|
63 | + ! is_array($registrations) |
|
64 | + || ! reset($registrations) instanceof EE_Registration |
|
65 | 65 | ) { |
66 | 66 | return array(); |
67 | 67 | } |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | |
71 | 71 | $registration_ids = array_filter( |
72 | 72 | array_map( |
73 | - function( $registration ) { |
|
74 | - if ( $registration instanceof EE_Registration ) { |
|
73 | + function($registration) { |
|
74 | + if ($registration instanceof EE_Registration) { |
|
75 | 75 | return $registration->ID(); |
76 | 76 | } |
77 | 77 | }, |
@@ -95,16 +95,16 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return EE_Registration[] |
97 | 97 | */ |
98 | - static public function convert_data_from_persistent_storage( $data ) { |
|
98 | + static public function convert_data_from_persistent_storage($data) { |
|
99 | 99 | //since this was added later, we need to account of possible back compat issues where data already queued for generation |
100 | 100 | //is in the old format, which is an array of EE_Registration objects. So if that's the case, then let's just return them |
101 | 101 | //@see https://events.codebasehq.com/projects/event-espresso/tickets/10127 |
102 | - if ( is_array( $data ) && reset( $data ) instanceof EE_Registration ) { |
|
102 | + if (is_array($data) && reset($data) instanceof EE_Registration) { |
|
103 | 103 | return $data; |
104 | 104 | } |
105 | 105 | |
106 | - $registrations = is_array( $data ) |
|
107 | - ? EEM_Registration::instance()->get_all( array( array( 'REG_ID' => array( 'IN', $data ) ) ) ) |
|
106 | + $registrations = is_array($data) |
|
107 | + ? EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $data)))) |
|
108 | 108 | : array(); |
109 | 109 | return $registrations; |
110 | 110 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * before the hook wp_enqueue_scripts is called (so that the form section can enqueue its needed scripts). |
8 | 8 | * However, you may output the form (usually by calling get_html) anywhere you like. |
9 | 9 | */ |
10 | -class EE_Form_Section_Proper extends EE_Form_Section_Validatable{ |
|
10 | +class EE_Form_Section_Proper extends EE_Form_Section_Validatable { |
|
11 | 11 | |
12 | 12 | const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
13 | 13 | |
@@ -71,49 +71,49 @@ discard block |
||
71 | 71 | * } @see EE_Form_Section_Validatable::__construct() |
72 | 72 | * @throws \EE_Error |
73 | 73 | */ |
74 | - public function __construct( $options_array = array() ){ |
|
75 | - $options_array = (array) apply_filters( 'FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, $this ); |
|
74 | + public function __construct($options_array = array()) { |
|
75 | + $options_array = (array) apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, $this); |
|
76 | 76 | //call parent first, as it may be setting the name |
77 | 77 | parent::__construct($options_array); |
78 | 78 | //if they've included subsections in the constructor, add them now |
79 | - if( isset( $options_array['include'] )){ |
|
79 | + if (isset($options_array['include'])) { |
|
80 | 80 | //we are going to make sure we ONLY have those subsections to include |
81 | 81 | //AND we are going to make sure they're in that specified order |
82 | 82 | $reordered_subsections = array(); |
83 | - foreach($options_array['include'] as $input_name){ |
|
84 | - if(isset($this->_subsections[$input_name])){ |
|
83 | + foreach ($options_array['include'] as $input_name) { |
|
84 | + if (isset($this->_subsections[$input_name])) { |
|
85 | 85 | $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
86 | 86 | } |
87 | 87 | } |
88 | 88 | $this->_subsections = $reordered_subsections; |
89 | 89 | } |
90 | - if(isset($options_array['exclude'])){ |
|
90 | + if (isset($options_array['exclude'])) { |
|
91 | 91 | $exclude = $options_array['exclude']; |
92 | 92 | $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
93 | 93 | } |
94 | - if(isset($options_array['layout_strategy'])){ |
|
94 | + if (isset($options_array['layout_strategy'])) { |
|
95 | 95 | $this->_layout_strategy = $options_array['layout_strategy']; |
96 | 96 | } |
97 | - if( ! $this->_layout_strategy){ |
|
97 | + if ( ! $this->_layout_strategy) { |
|
98 | 98 | $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
99 | 99 | } |
100 | 100 | $this->_layout_strategy->_construct_finalize($this); |
101 | 101 | |
102 | 102 | //ok so we are definitely going to want the forms JS, |
103 | 103 | //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
104 | - if( did_action( 'wp_enqueue_scripts' ) |
|
105 | - || did_action( 'admin_enqueue_scripts' ) ) { |
|
104 | + if (did_action('wp_enqueue_scripts') |
|
105 | + || did_action('admin_enqueue_scripts')) { |
|
106 | 106 | //ok so they've constructed this object after when they should have. |
107 | 107 | //just enqueue the generic form scripts and initialize the form immediately in the JS |
108 | - \EE_Form_Section_Proper::wp_enqueue_scripts( true ); |
|
108 | + \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
109 | 109 | } else { |
110 | - add_action( 'wp_enqueue_scripts', array( 'EE_Form_Section_Proper', 'wp_enqueue_scripts' )); |
|
111 | - add_action( 'admin_enqueue_scripts', array( 'EE_Form_Section_Proper', 'wp_enqueue_scripts' )); |
|
110 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
111 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
112 | 112 | } |
113 | - add_action( 'wp_footer', array( $this, 'ensure_scripts_localized' ), 1 ); |
|
113 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
114 | 114 | |
115 | - if( isset( $options_array[ 'name' ] ) ) { |
|
116 | - $this->_construct_finalize( null, $options_array[ 'name' ] ); |
|
115 | + if (isset($options_array['name'])) { |
|
116 | + $this->_construct_finalize(null, $options_array['name']); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
@@ -126,25 +126,25 @@ discard block |
||
126 | 126 | * @param string $name |
127 | 127 | * @throws \EE_Error |
128 | 128 | */ |
129 | - public function _construct_finalize( $parent_form_section, $name ) { |
|
129 | + public function _construct_finalize($parent_form_section, $name) { |
|
130 | 130 | parent::_construct_finalize($parent_form_section, $name); |
131 | 131 | $this->_set_default_name_if_empty(); |
132 | 132 | $this->_set_default_html_id_if_empty(); |
133 | - foreach( $this->_subsections as $subsection_name => $subsection ){ |
|
134 | - if ( $subsection instanceof EE_Form_Section_Base ) { |
|
135 | - $subsection->_construct_finalize( $this, $subsection_name ); |
|
133 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
134 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
135 | + $subsection->_construct_finalize($this, $subsection_name); |
|
136 | 136 | } else { |
137 | 137 | throw new EE_Error( |
138 | 138 | sprintf( |
139 | - __( 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', 'event_espresso' ), |
|
139 | + __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', 'event_espresso'), |
|
140 | 140 | $subsection_name, |
141 | 141 | get_class($this), |
142 | - $subsection ? get_class($subsection) : __( 'NULL', 'event_espresso' ) |
|
142 | + $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | } |
146 | 146 | } |
147 | - do_action( 'AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name ); |
|
147 | + do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * Gets the layout strategy for this form section |
154 | 154 | * @return EE_Form_Section_Layout_Base |
155 | 155 | */ |
156 | - public function get_layout_strategy(){ |
|
156 | + public function get_layout_strategy() { |
|
157 | 157 | return $this->_layout_strategy; |
158 | 158 | } |
159 | 159 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @param EE_Form_Input_Base $input |
166 | 166 | * @return string |
167 | 167 | */ |
168 | - public function get_html_for_input($input){ |
|
168 | + public function get_html_for_input($input) { |
|
169 | 169 | return $this->_layout_strategy->layout_input($input); |
170 | 170 | } |
171 | 171 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param null $form_data |
179 | 179 | * @return boolean |
180 | 180 | */ |
181 | - public function was_submitted($form_data = NULL){ |
|
181 | + public function was_submitted($form_data = NULL) { |
|
182 | 182 | return $this->form_data_present_in($form_data); |
183 | 183 | } |
184 | 184 | |
@@ -203,21 +203,21 @@ discard block |
||
203 | 203 | * (eg you validated the data then stored it in the DB) |
204 | 204 | * you may want to skip this step. |
205 | 205 | */ |
206 | - public function receive_form_submission( $req_data = null, $validate = true ){ |
|
207 | - $req_data = apply_filters( 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, $validate ); |
|
208 | - if( $req_data === null ){ |
|
209 | - $req_data = array_merge( $_GET, $_POST ); |
|
206 | + public function receive_form_submission($req_data = null, $validate = true) { |
|
207 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, $validate); |
|
208 | + if ($req_data === null) { |
|
209 | + $req_data = array_merge($_GET, $_POST); |
|
210 | 210 | } |
211 | - $req_data = apply_filters( 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, $this ); |
|
212 | - $this->_normalize( $req_data ); |
|
213 | - if( $validate ){ |
|
211 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, $this); |
|
212 | + $this->_normalize($req_data); |
|
213 | + if ($validate) { |
|
214 | 214 | $this->_validate(); |
215 | 215 | //if it's invalid, we're going to want to re-display so remember what they submitted |
216 | - if ( ! $this->is_valid() ) { |
|
216 | + if ( ! $this->is_valid()) { |
|
217 | 217 | $this->store_submitted_form_data_in_session(); |
218 | 218 | } |
219 | 219 | } |
220 | - do_action( 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate ); |
|
220 | + do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | protected function store_submitted_form_data_in_session() { |
232 | 232 | return EE_Registry::instance()->SSN->set_session_data( |
233 | 233 | array( |
234 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values( true ) |
|
234 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true) |
|
235 | 235 | ) |
236 | 236 | ); |
237 | 237 | } |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | */ |
247 | 247 | protected function get_submitted_form_data_from_session() { |
248 | 248 | $session = EE_Registry::instance()->SSN; |
249 | - if( $session instanceof EE_Session ) { |
|
249 | + if ($session instanceof EE_Session) { |
|
250 | 250 | return $session->get_session_data( |
251 | 251 | \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
252 | 252 | ); |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | */ |
265 | 265 | protected function flush_submitted_form_data_from_session() { |
266 | 266 | return EE_Registry::instance()->SSN->reset_data( |
267 | - array( \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY ) |
|
267 | + array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
268 | 268 | ); |
269 | 269 | } |
270 | 270 | |
@@ -280,12 +280,12 @@ discard block |
||
280 | 280 | */ |
281 | 281 | public function populate_from_session() { |
282 | 282 | $form_data_in_session = $this->get_submitted_form_data_from_session(); |
283 | - if ( empty( $form_data_in_session ) ) { |
|
283 | + if (empty($form_data_in_session)) { |
|
284 | 284 | return false; |
285 | 285 | } |
286 | - $this->receive_form_submission( $form_data_in_session ); |
|
286 | + $this->receive_form_submission($form_data_in_session); |
|
287 | 287 | $this->flush_submitted_form_data_from_session(); |
288 | - if ( $this->form_data_present_in( $form_data_in_session ) ) { |
|
288 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
289 | 289 | return true; |
290 | 290 | } else { |
291 | 291 | return false; |
@@ -302,12 +302,12 @@ discard block |
||
302 | 302 | * the value being an array formatted in teh same way |
303 | 303 | * @param array $default_data |
304 | 304 | */ |
305 | - public function populate_defaults($default_data){ |
|
306 | - foreach($this->subsections() as $subsection_name => $subsection){ |
|
307 | - if(isset($default_data[$subsection_name])){ |
|
308 | - if($subsection instanceof EE_Form_Input_Base){ |
|
305 | + public function populate_defaults($default_data) { |
|
306 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
307 | + if (isset($default_data[$subsection_name])) { |
|
308 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
309 | 309 | $subsection->set_default($default_data[$subsection_name]); |
310 | - }elseif($subsection instanceof EE_Form_Section_Proper){ |
|
310 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
311 | 311 | $subsection->populate_defaults($default_data[$subsection_name]); |
312 | 312 | } |
313 | 313 | } |
@@ -322,8 +322,8 @@ discard block |
||
322 | 322 | * @param string $name |
323 | 323 | * @return boolean |
324 | 324 | */ |
325 | - public function subsection_exists( $name ){ |
|
326 | - return isset( $this->_subsections[ $name ] ) ? true : false; |
|
325 | + public function subsection_exists($name) { |
|
326 | + return isset($this->_subsections[$name]) ? true : false; |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | |
@@ -341,11 +341,11 @@ discard block |
||
341 | 341 | * @return EE_Form_Section_Base |
342 | 342 | * @throws \EE_Error |
343 | 343 | */ |
344 | - public function get_subsection($name, $require_construction_to_be_finalized = TRUE ){ |
|
345 | - if( $require_construction_to_be_finalized ){ |
|
344 | + public function get_subsection($name, $require_construction_to_be_finalized = TRUE) { |
|
345 | + if ($require_construction_to_be_finalized) { |
|
346 | 346 | $this->ensure_construct_finalized_called(); |
347 | 347 | } |
348 | - return $this->subsection_exists( $name ) ? $this->_subsections[$name] : NULL; |
|
348 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : NULL; |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | |
@@ -354,10 +354,10 @@ discard block |
||
354 | 354 | * Gets all the validatable subsections of this form section |
355 | 355 | * @return EE_Form_Section_Validatable[] |
356 | 356 | */ |
357 | - public function get_validatable_subsections(){ |
|
357 | + public function get_validatable_subsections() { |
|
358 | 358 | $validatable_subsections = array(); |
359 | - foreach($this->subsections() as $name=>$obj){ |
|
360 | - if($obj instanceof EE_Form_Section_Validatable){ |
|
359 | + foreach ($this->subsections() as $name=>$obj) { |
|
360 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
361 | 361 | $validatable_subsections[$name] = $obj; |
362 | 362 | } |
363 | 363 | } |
@@ -377,9 +377,9 @@ discard block |
||
377 | 377 | * @return EE_Form_Input_Base |
378 | 378 | * @throws EE_Error |
379 | 379 | */ |
380 | - public function get_input($name, $require_construction_to_be_finalized = TRUE ){ |
|
380 | + public function get_input($name, $require_construction_to_be_finalized = TRUE) { |
|
381 | 381 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
382 | - if( ! $subsection instanceof EE_Form_Input_Base){ |
|
382 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
383 | 383 | throw new EE_Error( |
384 | 384 | sprintf( |
385 | 385 | __( |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | 'event_espresso' |
388 | 388 | ), |
389 | 389 | $name, |
390 | - get_class( $this ), |
|
391 | - $subsection ? get_class( $subsection ) : __( "NULL", 'event_espresso' ) |
|
390 | + get_class($this), |
|
391 | + $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
392 | 392 | ) |
393 | 393 | ); |
394 | 394 | } |
@@ -408,14 +408,14 @@ discard block |
||
408 | 408 | * @return EE_Form_Section_Proper |
409 | 409 | * @throws EE_Error |
410 | 410 | */ |
411 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = TRUE ){ |
|
412 | - $subsection = $this->get_subsection( $name, $require_construction_to_be_finalized ); |
|
413 | - if( ! $subsection instanceof EE_Form_Section_Proper){ |
|
411 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = TRUE) { |
|
412 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
413 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
414 | 414 | throw new EE_Error( |
415 | 415 | sprintf( |
416 | - __( "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso' ), |
|
416 | + __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
417 | 417 | $name, |
418 | - get_class( $this ) |
|
418 | + get_class($this) |
|
419 | 419 | ) |
420 | 420 | ); |
421 | 421 | } |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * @return mixed depending on the input's type and its normalization strategy |
433 | 433 | * @throws \EE_Error |
434 | 434 | */ |
435 | - public function get_input_value($name){ |
|
435 | + public function get_input_value($name) { |
|
436 | 436 | $input = $this->get_input($name); |
437 | 437 | return $input->normalized_value(); |
438 | 438 | } |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | * @return boolean |
446 | 446 | */ |
447 | 447 | public function is_valid() { |
448 | - if( ! $this->has_received_submission()){ |
|
448 | + if ( ! $this->has_received_submission()) { |
|
449 | 449 | throw new EE_Error( |
450 | 450 | sprintf( |
451 | 451 | __( |
@@ -455,16 +455,16 @@ discard block |
||
455 | 455 | ) |
456 | 456 | ); |
457 | 457 | } |
458 | - if( ! parent::is_valid() ) { |
|
458 | + if ( ! parent::is_valid()) { |
|
459 | 459 | return false; |
460 | 460 | } |
461 | 461 | // ok so no general errors to this entire form section. |
462 | 462 | // so let's check the subsections, but only set errors if that hasn't been done yet |
463 | 463 | $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
464 | - foreach( $this->get_validatable_subsections() as $subsection ){ |
|
465 | - if( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '' ){ |
|
466 | - if ( $set_submission_errors ) { |
|
467 | - $this->set_submission_error_message( $subsection->get_validation_error_string() ); |
|
464 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
465 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
466 | + if ($set_submission_errors) { |
|
467 | + $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
468 | 468 | } |
469 | 469 | return false; |
470 | 470 | } |
@@ -478,11 +478,11 @@ discard block |
||
478 | 478 | * gets teh default name of this form section if none is specified |
479 | 479 | * @return string |
480 | 480 | */ |
481 | - protected function _set_default_name_if_empty(){ |
|
482 | - if( ! $this->_name ){ |
|
481 | + protected function _set_default_name_if_empty() { |
|
482 | + if ( ! $this->_name) { |
|
483 | 483 | $classname = get_class($this); |
484 | 484 | $default_name = str_replace("EE_", "", $classname); |
485 | - $this->_name = $default_name; |
|
485 | + $this->_name = $default_name; |
|
486 | 486 | } |
487 | 487 | } |
488 | 488 | |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | * and get_html when you are about to display the form. |
499 | 499 | * @throws \EE_Error |
500 | 500 | */ |
501 | - public function get_html_and_js(){ |
|
501 | + public function get_html_and_js() { |
|
502 | 502 | //no doing_it_wrong yet because we ourselves are still doing it wrong... |
503 | 503 | //and theoretically this CAN be used properly, provided its used during "wp_enqueue_scripts" |
504 | 504 | $this->enqueue_js(); |
@@ -513,9 +513,9 @@ discard block |
||
513 | 513 | * @param bool $display_previously_submitted_data |
514 | 514 | * @return string |
515 | 515 | */ |
516 | - public function get_html( $display_previously_submitted_data = true ){ |
|
516 | + public function get_html($display_previously_submitted_data = true) { |
|
517 | 517 | $this->ensure_construct_finalized_called(); |
518 | - if ( $display_previously_submitted_data ) { |
|
518 | + if ($display_previously_submitted_data) { |
|
519 | 519 | $this->populate_from_session(); |
520 | 520 | } |
521 | 521 | return $this->_layout_strategy->layout_form(); |
@@ -529,9 +529,9 @@ discard block |
||
529 | 529 | * @return string |
530 | 530 | * @throws \EE_Error |
531 | 531 | */ |
532 | - public function enqueue_js(){ |
|
532 | + public function enqueue_js() { |
|
533 | 533 | $this->_enqueue_and_localize_form_js(); |
534 | - foreach( $this->subsections() as $subsection ) { |
|
534 | + foreach ($this->subsections() as $subsection) { |
|
535 | 535 | $subsection->enqueue_js(); |
536 | 536 | } |
537 | 537 | } |
@@ -550,19 +550,19 @@ discard block |
||
550 | 550 | * to be triggered automatically or not |
551 | 551 | * @return void |
552 | 552 | */ |
553 | - public static function wp_enqueue_scripts( $init_form_validation_automatically = true ){ |
|
554 | - add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
553 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) { |
|
554 | + add_filter('FHEE_load_jquery_validate', '__return_true'); |
|
555 | 555 | wp_register_script( |
556 | 556 | 'ee_form_section_validation', |
557 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
558 | - array( 'jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods' ), |
|
557 | + EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', |
|
558 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
559 | 559 | EVENT_ESPRESSO_VERSION, |
560 | 560 | true |
561 | 561 | ); |
562 | 562 | wp_localize_script( |
563 | 563 | 'ee_form_section_validation', |
564 | 564 | 'ee_form_section_validation_init', |
565 | - array( 'init' => $init_form_validation_automatically ? true : false ) |
|
565 | + array('init' => $init_form_validation_automatically ? true : false) |
|
566 | 566 | ); |
567 | 567 | } |
568 | 568 | |
@@ -573,14 +573,14 @@ discard block |
||
573 | 573 | * |
574 | 574 | * @throws \EE_Error |
575 | 575 | */ |
576 | - public function _enqueue_and_localize_form_js(){ |
|
576 | + public function _enqueue_and_localize_form_js() { |
|
577 | 577 | $this->ensure_construct_finalized_called(); |
578 | 578 | //actually, we don't want to localize just yet. There may be other forms on the page. |
579 | 579 | //so we need to add our form section data to a static variable accessible by all form sections |
580 | 580 | //and localize it just before the footer |
581 | 581 | $this->localize_validation_rules(); |
582 | - add_action( 'wp_footer', array( 'EE_Form_Section_Proper', 'localize_script_for_all_forms' ), 2 ); |
|
583 | - add_action( 'admin_footer', array( 'EE_Form_Section_Proper', 'localize_script_for_all_forms' ) ); |
|
582 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
583 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | |
@@ -592,12 +592,12 @@ discard block |
||
592 | 592 | * @return void |
593 | 593 | * @throws \EE_Error |
594 | 594 | */ |
595 | - public function localize_validation_rules( $return_for_subsection = FALSE ){ |
|
595 | + public function localize_validation_rules($return_for_subsection = FALSE) { |
|
596 | 596 | // we only want to localize vars ONCE for the entire form, |
597 | 597 | // so if the form section doesn't have a parent, then it must be the top dog |
598 | - if ( $return_for_subsection || ! $this->parent_section() ) { |
|
599 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
600 | - 'form_section_id'=> $this->html_id( TRUE ), |
|
598 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
599 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
600 | + 'form_section_id'=> $this->html_id(TRUE), |
|
601 | 601 | 'validation_rules'=> $this->get_jquery_validation_rules(), |
602 | 602 | 'other_data' => $this->get_other_js_data(), |
603 | 603 | 'errors'=> $this->subsection_validation_errors_by_html_name() |
@@ -613,9 +613,9 @@ discard block |
||
613 | 613 | * @param array $form_other_js_data |
614 | 614 | * @return array |
615 | 615 | */ |
616 | - public function get_other_js_data( $form_other_js_data = array() ) { |
|
617 | - foreach( $this->subsections() as $subsection ) { |
|
618 | - $form_other_js_data = $subsection->get_other_js_data( $form_other_js_data ); |
|
616 | + public function get_other_js_data($form_other_js_data = array()) { |
|
617 | + foreach ($this->subsections() as $subsection) { |
|
618 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
619 | 619 | } |
620 | 620 | return $form_other_js_data; |
621 | 621 | } |
@@ -626,12 +626,12 @@ discard block |
||
626 | 626 | * Keys are their form names, and values are the inputs themselves |
627 | 627 | * @return EE_Form_Input_Base |
628 | 628 | */ |
629 | - public function inputs_in_subsections(){ |
|
629 | + public function inputs_in_subsections() { |
|
630 | 630 | $inputs = array(); |
631 | - foreach($this->subsections() as $subsection){ |
|
632 | - if( $subsection instanceof EE_Form_Input_Base ){ |
|
633 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
634 | - }elseif($subsection instanceof EE_Form_Section_Proper ){ |
|
631 | + foreach ($this->subsections() as $subsection) { |
|
632 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
633 | + $inputs[$subsection->html_name()] = $subsection; |
|
634 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
635 | 635 | $inputs += $subsection->inputs_in_subsections(); |
636 | 636 | } |
637 | 637 | } |
@@ -644,12 +644,12 @@ discard block |
||
644 | 644 | * and values are a string of all their validation errors |
645 | 645 | * @return string[] |
646 | 646 | */ |
647 | - public function subsection_validation_errors_by_html_name(){ |
|
647 | + public function subsection_validation_errors_by_html_name() { |
|
648 | 648 | $inputs = $this->inputs(); |
649 | 649 | $errors = array(); |
650 | - foreach( $inputs as $form_input ){ |
|
651 | - if ( $form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors() ){ |
|
652 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
650 | + foreach ($inputs as $form_input) { |
|
651 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
652 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
653 | 653 | } |
654 | 654 | } |
655 | 655 | return $errors; |
@@ -661,15 +661,15 @@ discard block |
||
661 | 661 | * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
662 | 662 | * Should be setup by each form during the _enqueues_and_localize_form_js |
663 | 663 | */ |
664 | - public static function localize_script_for_all_forms(){ |
|
664 | + public static function localize_script_for_all_forms() { |
|
665 | 665 | //allow inputs and stuff to hook in their JS and stuff here |
666 | - do_action( 'AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin' ); |
|
666 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
667 | 667 | EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
668 | - $email_validation_level = isset( EE_Registry::instance()->CFG->registration->email_validation_level ) |
|
668 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
669 | 669 | ? EE_Registry::instance()->CFG->registration->email_validation_level |
670 | 670 | : 'wp_default'; |
671 | 671 | EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
672 | - wp_enqueue_script( 'ee_form_section_validation' ); |
|
672 | + wp_enqueue_script('ee_form_section_validation'); |
|
673 | 673 | wp_localize_script( |
674 | 674 | 'ee_form_section_validation', |
675 | 675 | 'ee_form_section_vars', |
@@ -682,8 +682,8 @@ discard block |
||
682 | 682 | /** |
683 | 683 | * ensure_scripts_localized |
684 | 684 | */ |
685 | - public function ensure_scripts_localized(){ |
|
686 | - if ( ! EE_Form_Section_Proper::$_scripts_localized ) { |
|
685 | + public function ensure_scripts_localized() { |
|
686 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
687 | 687 | $this->_enqueue_and_localize_form_js(); |
688 | 688 | } |
689 | 689 | } |
@@ -695,10 +695,10 @@ discard block |
||
695 | 695 | * is that the key here should be the same as the custom validation rule put in the JS file |
696 | 696 | * @return array keys are custom validation rules, and values are internationalized strings |
697 | 697 | */ |
698 | - private static function _get_localized_error_messages(){ |
|
698 | + private static function _get_localized_error_messages() { |
|
699 | 699 | return array( |
700 | 700 | 'validUrl'=> __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
701 | - 'regex' => __( 'Please check your input', 'event_espresso' ), |
|
701 | + 'regex' => __('Please check your input', 'event_espresso'), |
|
702 | 702 | ); |
703 | 703 | } |
704 | 704 | |
@@ -728,9 +728,9 @@ discard block |
||
728 | 728 | * |
729 | 729 | * @return array |
730 | 730 | */ |
731 | - public function get_jquery_validation_rules(){ |
|
731 | + public function get_jquery_validation_rules() { |
|
732 | 732 | $jquery_validation_rules = array(); |
733 | - foreach($this->get_validatable_subsections() as $subsection){ |
|
733 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
734 | 734 | $jquery_validation_rules = array_merge( |
735 | 735 | $jquery_validation_rules, |
736 | 736 | $subsection->get_jquery_validation_rules() |
@@ -747,14 +747,14 @@ discard block |
||
747 | 747 | * @param array $req_data like $_POST |
748 | 748 | * @return void |
749 | 749 | */ |
750 | - protected function _normalize( $req_data ) { |
|
750 | + protected function _normalize($req_data) { |
|
751 | 751 | $this->_received_submission = true; |
752 | 752 | $this->_validation_errors = array(); |
753 | - foreach ( $this->get_validatable_subsections() as $subsection ) { |
|
753 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
754 | 754 | try { |
755 | - $subsection->_normalize( $req_data ); |
|
756 | - } catch ( EE_Validation_Error $e ) { |
|
757 | - $subsection->add_validation_error( $e ); |
|
755 | + $subsection->_normalize($req_data); |
|
756 | + } catch (EE_Validation_Error $e) { |
|
757 | + $subsection->add_validation_error($e); |
|
758 | 758 | } |
759 | 759 | } |
760 | 760 | } |
@@ -771,9 +771,9 @@ discard block |
||
771 | 771 | * calling parent::_validate() first. |
772 | 772 | */ |
773 | 773 | protected function _validate() { |
774 | - foreach($this->get_validatable_subsections() as $subsection_name => $subsection){ |
|
775 | - if(method_exists($this,'_validate_'.$subsection_name)){ |
|
776 | - call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection)); |
|
774 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
775 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
776 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
777 | 777 | } |
778 | 778 | $subsection->_validate(); |
779 | 779 | } |
@@ -785,13 +785,13 @@ discard block |
||
785 | 785 | * Gets all the validated inputs for the form section |
786 | 786 | * @return array |
787 | 787 | */ |
788 | - public function valid_data(){ |
|
788 | + public function valid_data() { |
|
789 | 789 | $inputs = array(); |
790 | - foreach( $this->subsections() as $subsection_name =>$subsection ){ |
|
791 | - if ( $subsection instanceof EE_Form_Section_Proper ) { |
|
792 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
793 | - } else if ( $subsection instanceof EE_Form_Input_Base ){ |
|
794 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
790 | + foreach ($this->subsections() as $subsection_name =>$subsection) { |
|
791 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
792 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
793 | + } else if ($subsection instanceof EE_Form_Input_Base) { |
|
794 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
795 | 795 | } |
796 | 796 | } |
797 | 797 | return $inputs; |
@@ -803,11 +803,11 @@ discard block |
||
803 | 803 | * Gets all the inputs on this form section |
804 | 804 | * @return EE_Form_Input_Base[] |
805 | 805 | */ |
806 | - public function inputs(){ |
|
806 | + public function inputs() { |
|
807 | 807 | $inputs = array(); |
808 | - foreach( $this->subsections() as $subsection_name =>$subsection ){ |
|
809 | - if ( $subsection instanceof EE_Form_Input_Base ){ |
|
810 | - $inputs[ $subsection_name ] = $subsection; |
|
808 | + foreach ($this->subsections() as $subsection_name =>$subsection) { |
|
809 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
810 | + $inputs[$subsection_name] = $subsection; |
|
811 | 811 | } |
812 | 812 | } |
813 | 813 | return $inputs; |
@@ -819,10 +819,10 @@ discard block |
||
819 | 819 | * Gets all the subsections which are a proper form |
820 | 820 | * @return EE_Form_Section_Proper[] |
821 | 821 | */ |
822 | - public function subforms(){ |
|
822 | + public function subforms() { |
|
823 | 823 | $form_sections = array(); |
824 | - foreach($this->subsections() as $name=>$obj){ |
|
825 | - if($obj instanceof EE_Form_Section_Proper){ |
|
824 | + foreach ($this->subsections() as $name=>$obj) { |
|
825 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
826 | 826 | $form_sections[$name] = $obj; |
827 | 827 | } |
828 | 828 | } |
@@ -837,7 +837,7 @@ discard block |
||
837 | 837 | * if you only want form inputs or proper form sections. |
838 | 838 | * @return EE_Form_Section_Proper[] |
839 | 839 | */ |
840 | - public function subsections(){ |
|
840 | + public function subsections() { |
|
841 | 841 | $this->ensure_construct_finalized_called(); |
842 | 842 | return $this->_subsections; |
843 | 843 | } |
@@ -859,8 +859,8 @@ discard block |
||
859 | 859 | * where keys are always subsection names and values are either |
860 | 860 | * the input's normalized value, or an array like the top-level array |
861 | 861 | */ |
862 | - public function input_values( $include_subform_inputs = false, $flatten = false ){ |
|
863 | - return $this->_input_values( false, $include_subform_inputs, $flatten ); |
|
862 | + public function input_values($include_subform_inputs = false, $flatten = false) { |
|
863 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | /** |
@@ -880,8 +880,8 @@ discard block |
||
880 | 880 | * where keys are always subsection names and values are either |
881 | 881 | * the input's normalized value, or an array like the top-level array |
882 | 882 | */ |
883 | - public function input_pretty_values( $include_subform_inputs = false, $flatten = false ){ |
|
884 | - return $this->_input_values( true, $include_subform_inputs, $flatten ); |
|
883 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) { |
|
884 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | /** |
@@ -899,19 +899,19 @@ discard block |
||
899 | 899 | * where keys are always subsection names and values are either |
900 | 900 | * the input's normalized value, or an array like the top-level array |
901 | 901 | */ |
902 | - public function _input_values( $pretty = false, $include_subform_inputs = false, $flatten = false ) { |
|
902 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) { |
|
903 | 903 | $input_values = array(); |
904 | - foreach( $this->subsections() as $subsection_name => $subsection ) { |
|
905 | - if( $subsection instanceof EE_Form_Input_Base ) { |
|
906 | - $input_values[ $subsection_name ] = $pretty |
|
904 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
905 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
906 | + $input_values[$subsection_name] = $pretty |
|
907 | 907 | ? $subsection->pretty_value() |
908 | 908 | : $subsection->normalized_value(); |
909 | - } else if( $subsection instanceof EE_Form_Section_Proper && $include_subform_inputs ) { |
|
910 | - $subform_input_values = $subsection->_input_values( $pretty, $include_subform_inputs, $flatten ); |
|
911 | - if( $flatten ) { |
|
912 | - $input_values = array_merge( $input_values, $subform_input_values ); |
|
909 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
910 | + $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
911 | + if ($flatten) { |
|
912 | + $input_values = array_merge($input_values, $subform_input_values); |
|
913 | 913 | } else { |
914 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
914 | + $input_values[$subsection_name] = $subform_input_values; |
|
915 | 915 | } |
916 | 916 | } |
917 | 917 | } |
@@ -932,23 +932,23 @@ discard block |
||
932 | 932 | * where keys are always subsection names and values are either |
933 | 933 | * the input's normalized value, or an array like the top-level array |
934 | 934 | */ |
935 | - public function submitted_values( $include_subforms = false ) { |
|
935 | + public function submitted_values($include_subforms = false) { |
|
936 | 936 | $submitted_values = array(); |
937 | - foreach( $this->subsections() as $subsection ) { |
|
938 | - if( $subsection instanceof EE_Form_Input_Base ) { |
|
937 | + foreach ($this->subsections() as $subsection) { |
|
938 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
939 | 939 | // is this input part of an array of inputs? |
940 | - if ( strpos( $subsection->html_name(), '[' ) !== false ) { |
|
940 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
941 | 941 | $full_input_name = \EEH_Array::convert_array_values_to_keys( |
942 | - explode( '[', str_replace( ']', '', $subsection->html_name() ) ), |
|
942 | + explode('[', str_replace(']', '', $subsection->html_name())), |
|
943 | 943 | $subsection->raw_value() |
944 | 944 | ); |
945 | - $submitted_values = array_replace_recursive( $submitted_values, $full_input_name ); |
|
945 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
946 | 946 | } else { |
947 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
947 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
948 | 948 | } |
949 | - } else if( $subsection instanceof EE_Form_Section_Proper && $include_subforms ) { |
|
950 | - $subform_input_values = $subsection->submitted_values( $include_subforms ); |
|
951 | - $submitted_values = array_replace_recursive( $submitted_values, $subform_input_values ); |
|
949 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
950 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
951 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
952 | 952 | } |
953 | 953 | } |
954 | 954 | return $submitted_values; |
@@ -963,7 +963,7 @@ discard block |
||
963 | 963 | * @return boolean |
964 | 964 | * @throws \EE_Error |
965 | 965 | */ |
966 | - public function has_received_submission(){ |
|
966 | + public function has_received_submission() { |
|
967 | 967 | $this->ensure_construct_finalized_called(); |
968 | 968 | return $this->_received_submission; |
969 | 969 | } |
@@ -976,8 +976,8 @@ discard block |
||
976 | 976 | * @param array $inputs_to_exclude values are the input names |
977 | 977 | * @return void |
978 | 978 | */ |
979 | - public function exclude($inputs_to_exclude = array()){ |
|
980 | - foreach($inputs_to_exclude as $input_to_exclude_name){ |
|
979 | + public function exclude($inputs_to_exclude = array()) { |
|
980 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
981 | 981 | unset($this->_subsections[$input_to_exclude_name]); |
982 | 982 | } |
983 | 983 | } |
@@ -988,8 +988,8 @@ discard block |
||
988 | 988 | * @param array $inputs_to_hide |
989 | 989 | * @throws \EE_Error |
990 | 990 | */ |
991 | - public function hide($inputs_to_hide= array()){ |
|
992 | - foreach($inputs_to_hide as $input_to_hide){ |
|
991 | + public function hide($inputs_to_hide = array()) { |
|
992 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
993 | 993 | $input = $this->get_input($input_to_hide); |
994 | 994 | |
995 | 995 | $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
@@ -1019,21 +1019,21 @@ discard block |
||
1019 | 1019 | * @return void |
1020 | 1020 | * @throws \EE_Error |
1021 | 1021 | */ |
1022 | - public function add_subsections( $new_subsections, $subsection_name_to_target = NULL, $add_before = true ){ |
|
1023 | - foreach( $new_subsections as $subsection_name => $subsection ){ |
|
1024 | - if( ! $subsection instanceof EE_Form_Section_Base ){ |
|
1022 | + public function add_subsections($new_subsections, $subsection_name_to_target = NULL, $add_before = true) { |
|
1023 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
1024 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
1025 | 1025 | EE_Error::add_error( |
1026 | 1026 | sprintf( |
1027 | 1027 | __( |
1028 | 1028 | "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
1029 | 1029 | "event_espresso" |
1030 | 1030 | ), |
1031 | - get_class( $subsection ), |
|
1031 | + get_class($subsection), |
|
1032 | 1032 | $subsection_name, |
1033 | 1033 | $this->name() |
1034 | 1034 | ) |
1035 | 1035 | ); |
1036 | - unset( $new_subsections[ $subsection_name ] ); |
|
1036 | + unset($new_subsections[$subsection_name]); |
|
1037 | 1037 | } |
1038 | 1038 | } |
1039 | 1039 | $this->_subsections = EEH_Array::insert_into_array( |
@@ -1044,8 +1044,8 @@ discard block |
||
1044 | 1044 | ); |
1045 | 1045 | |
1046 | 1046 | |
1047 | - if( $this->_construction_finalized ){ |
|
1048 | - foreach($this->_subsections as $name => $subsection){ |
|
1047 | + if ($this->_construction_finalized) { |
|
1048 | + foreach ($this->_subsections as $name => $subsection) { |
|
1049 | 1049 | $subsection->_construct_finalize($this, $name); |
1050 | 1050 | } |
1051 | 1051 | } |
@@ -1056,8 +1056,8 @@ discard block |
||
1056 | 1056 | /** |
1057 | 1057 | * Just gets all validatable subsections to clean their sensitive data |
1058 | 1058 | */ |
1059 | - public function clean_sensitive_data(){ |
|
1060 | - foreach($this->get_validatable_subsections() as $subsection){ |
|
1059 | + public function clean_sensitive_data() { |
|
1060 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1061 | 1061 | $subsection->clean_sensitive_data(); |
1062 | 1062 | } |
1063 | 1063 | } |
@@ -1067,10 +1067,10 @@ discard block |
||
1067 | 1067 | /** |
1068 | 1068 | * @param string $form_submission_error_message |
1069 | 1069 | */ |
1070 | - public function set_submission_error_message( $form_submission_error_message = '' ) { |
|
1071 | - $this->_form_submission_error_message .= ! empty( $form_submission_error_message ) |
|
1070 | + public function set_submission_error_message($form_submission_error_message = '') { |
|
1071 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
1072 | 1072 | ? $form_submission_error_message |
1073 | - : __( 'Form submission failed due to errors', 'event_espresso' ); |
|
1073 | + : __('Form submission failed due to errors', 'event_espresso'); |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | |
@@ -1087,10 +1087,10 @@ discard block |
||
1087 | 1087 | /** |
1088 | 1088 | * @param string $form_submission_success_message |
1089 | 1089 | */ |
1090 | - public function set_submission_success_message( $form_submission_success_message ) { |
|
1091 | - $this->_form_submission_success_message .= ! empty( $form_submission_success_message ) |
|
1090 | + public function set_submission_success_message($form_submission_success_message) { |
|
1091 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
1092 | 1092 | ? $form_submission_success_message |
1093 | - : __( 'Form submitted successfully', 'event_espresso' ); |
|
1093 | + : __('Form submitted successfully', 'event_espresso'); |
|
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | |
@@ -1113,10 +1113,10 @@ discard block |
||
1113 | 1113 | * @return string |
1114 | 1114 | * @throws \EE_Error |
1115 | 1115 | */ |
1116 | - public function html_name_prefix(){ |
|
1117 | - if( $this->parent_section() instanceof EE_Form_Section_Proper ){ |
|
1118 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1119 | - }else{ |
|
1116 | + public function html_name_prefix() { |
|
1117 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1118 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
1119 | + } else { |
|
1120 | 1120 | return $this->name(); |
1121 | 1121 | } |
1122 | 1122 | } |
@@ -1131,7 +1131,7 @@ discard block |
||
1131 | 1131 | * @return string |
1132 | 1132 | * @throws \EE_Error |
1133 | 1133 | */ |
1134 | - public function name(){ |
|
1134 | + public function name() { |
|
1135 | 1135 | $this->ensure_construct_finalized_called(); |
1136 | 1136 | return parent::name(); |
1137 | 1137 | } |
@@ -1142,7 +1142,7 @@ discard block |
||
1142 | 1142 | * @return EE_Form_Section_Proper |
1143 | 1143 | * @throws \EE_Error |
1144 | 1144 | */ |
1145 | - public function parent_section(){ |
|
1145 | + public function parent_section() { |
|
1146 | 1146 | $this->ensure_construct_finalized_called(); |
1147 | 1147 | return parent::parent_section(); |
1148 | 1148 | } |
@@ -1155,9 +1155,9 @@ discard block |
||
1155 | 1155 | * @return void |
1156 | 1156 | * @throws \EE_Error |
1157 | 1157 | */ |
1158 | - public function ensure_construct_finalized_called(){ |
|
1159 | - if( ! $this->_construction_finalized ){ |
|
1160 | - $this->_construct_finalize($this->_parent_section, $this->_name ); |
|
1158 | + public function ensure_construct_finalized_called() { |
|
1159 | + if ( ! $this->_construction_finalized) { |
|
1160 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1161 | 1161 | } |
1162 | 1162 | } |
1163 | 1163 | |
@@ -1169,17 +1169,17 @@ discard block |
||
1169 | 1169 | * @param array $req_data |
1170 | 1170 | * @return boolean |
1171 | 1171 | */ |
1172 | - public function form_data_present_in( $req_data = NULL ) { |
|
1173 | - if( $req_data === NULL){ |
|
1172 | + public function form_data_present_in($req_data = NULL) { |
|
1173 | + if ($req_data === NULL) { |
|
1174 | 1174 | $req_data = $_POST; |
1175 | 1175 | } |
1176 | - foreach( $this->subsections() as $subsection ) { |
|
1177 | - if($subsection instanceof EE_Form_Input_Base ) { |
|
1178 | - if( $subsection->form_data_present_in( $req_data ) ) { |
|
1176 | + foreach ($this->subsections() as $subsection) { |
|
1177 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1178 | + if ($subsection->form_data_present_in($req_data)) { |
|
1179 | 1179 | return TRUE; |
1180 | 1180 | } |
1181 | - }elseif( $subsection instanceof EE_Form_Section_Proper ) { |
|
1182 | - if( $subsection->form_data_present_in( $req_data ) ) { |
|
1181 | + }elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1182 | + if ($subsection->form_data_present_in($req_data)) { |
|
1183 | 1183 | return TRUE; |
1184 | 1184 | } |
1185 | 1185 | } |
@@ -1196,14 +1196,14 @@ discard block |
||
1196 | 1196 | */ |
1197 | 1197 | public function get_validation_errors_accumulated() { |
1198 | 1198 | $validation_errors = $this->get_validation_errors(); |
1199 | - foreach($this->get_validatable_subsections() as $subsection ) { |
|
1200 | - if( $subsection instanceof EE_Form_Section_Proper ) { |
|
1199 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1200 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
1201 | 1201 | $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
1202 | 1202 | } else { |
1203 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1203 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1204 | 1204 | } |
1205 | - if( $validation_errors_on_this_subsection ){ |
|
1206 | - $validation_errors = array_merge( $validation_errors, $validation_errors_on_this_subsection ); |
|
1205 | + if ($validation_errors_on_this_subsection) { |
|
1206 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1207 | 1207 | } |
1208 | 1208 | } |
1209 | 1209 | return $validation_errors; |
@@ -1225,24 +1225,24 @@ discard block |
||
1225 | 1225 | * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
1226 | 1226 | * @return EE_Form_Section_Base |
1227 | 1227 | */ |
1228 | - public function find_section_from_path( $form_section_path ) { |
|
1228 | + public function find_section_from_path($form_section_path) { |
|
1229 | 1229 | //check if we can find the input from purely going straight up the tree |
1230 | - $input = parent::find_section_from_path( $form_section_path ); |
|
1231 | - if( $input instanceof EE_Form_Section_Base ) { |
|
1230 | + $input = parent::find_section_from_path($form_section_path); |
|
1231 | + if ($input instanceof EE_Form_Section_Base) { |
|
1232 | 1232 | return $input; |
1233 | 1233 | } |
1234 | 1234 | |
1235 | - $next_slash_pos = strpos( $form_section_path, '/' ); |
|
1236 | - if( $next_slash_pos !== false ) { |
|
1237 | - $child_section_name = substr( $form_section_path, 0, $next_slash_pos ); |
|
1238 | - $subpath = substr( $form_section_path, $next_slash_pos + 1 ); |
|
1235 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
1236 | + if ($next_slash_pos !== false) { |
|
1237 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1238 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1239 | 1239 | } else { |
1240 | 1240 | $child_section_name = $form_section_path; |
1241 | 1241 | $subpath = ''; |
1242 | 1242 | } |
1243 | - $child_section = $this->get_subsection( $child_section_name ); |
|
1244 | - if ( $child_section instanceof EE_Form_Section_Base ) { |
|
1245 | - return $child_section->find_section_from_path( $subpath ); |
|
1243 | + $child_section = $this->get_subsection($child_section_name); |
|
1244 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
1245 | + return $child_section->find_section_from_path($subpath); |
|
1246 | 1246 | } else { |
1247 | 1247 | return null; |
1248 | 1248 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage |
9 | 9 | * @author Mike Nelson |
10 | 10 | */ |
11 | -abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable{ |
|
11 | +abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * the input's name attribute |
@@ -143,54 +143,54 @@ discard block |
||
143 | 143 | * @type EE_Validation_Strategy_Base[] $validation_strategies |
144 | 144 | * } |
145 | 145 | */ |
146 | - public function __construct( $input_args = array() ){ |
|
147 | - $input_args = (array) apply_filters( 'FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this ); |
|
146 | + public function __construct($input_args = array()) { |
|
147 | + $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
148 | 148 | // the following properties must be cast as arrays |
149 | - if ( isset( $input_args['validation_strategies'] ) ) { |
|
150 | - foreach ( (array) $input_args['validation_strategies'] as $validation_strategy ) { |
|
151 | - if ( $validation_strategy instanceof EE_Validation_Strategy_Base ) { |
|
152 | - $this->_validation_strategies[ get_class( $validation_strategy ) ] = $validation_strategy; |
|
149 | + if (isset($input_args['validation_strategies'])) { |
|
150 | + foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
151 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
152 | + $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
153 | 153 | } |
154 | 154 | } |
155 | - unset( $input_args['validation_strategies'] ); |
|
155 | + unset($input_args['validation_strategies']); |
|
156 | 156 | } |
157 | 157 | // loop thru incoming options |
158 | - foreach( $input_args as $key => $value ) { |
|
158 | + foreach ($input_args as $key => $value) { |
|
159 | 159 | // add underscore to $key to match property names |
160 | - $_key = '_' . $key; |
|
161 | - if ( property_exists( $this, $_key )) { |
|
160 | + $_key = '_'.$key; |
|
161 | + if (property_exists($this, $_key)) { |
|
162 | 162 | $this->{$_key} = $value; |
163 | 163 | } |
164 | 164 | } |
165 | 165 | // ensure that "required" is set correctly |
166 | 166 | $this->set_required( |
167 | - $this->_required, isset( $input_args[ 'required_validation_error_message' ] ) |
|
168 | - ? $input_args[ 'required_validation_error_message' ] |
|
167 | + $this->_required, isset($input_args['required_validation_error_message']) |
|
168 | + ? $input_args['required_validation_error_message'] |
|
169 | 169 | : null |
170 | 170 | ); |
171 | 171 | |
172 | 172 | //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
173 | 173 | |
174 | 174 | $this->_display_strategy->_construct_finalize($this); |
175 | - foreach( $this->_validation_strategies as $validation_strategy ){ |
|
175 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
176 | 176 | $validation_strategy->_construct_finalize($this); |
177 | 177 | } |
178 | 178 | |
179 | - if( ! $this->_normalization_strategy){ |
|
179 | + if ( ! $this->_normalization_strategy) { |
|
180 | 180 | $this->_normalization_strategy = new EE_Text_Normalization(); |
181 | 181 | } |
182 | 182 | $this->_normalization_strategy->_construct_finalize($this); |
183 | 183 | |
184 | 184 | //at least we can use the normalization strategy to populate the default |
185 | - if( isset( $input_args[ 'default' ] ) ) { |
|
186 | - $this->set_default( $input_args[ 'default' ] ); |
|
185 | + if (isset($input_args['default'])) { |
|
186 | + $this->set_default($input_args['default']); |
|
187 | 187 | } |
188 | 188 | |
189 | - if( ! $this->_sensitive_data_removal_strategy){ |
|
189 | + if ( ! $this->_sensitive_data_removal_strategy) { |
|
190 | 190 | $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
191 | 191 | } |
192 | 192 | $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
193 | - parent::__construct( $input_args ); |
|
193 | + parent::__construct($input_args); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | |
@@ -201,11 +201,11 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @throws \EE_Error |
203 | 203 | */ |
204 | - protected function _set_default_html_name_if_empty(){ |
|
205 | - if( ! $this->_html_name){ |
|
204 | + protected function _set_default_html_name_if_empty() { |
|
205 | + if ( ! $this->_html_name) { |
|
206 | 206 | $this->_html_name = $this->name(); |
207 | - if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper){ |
|
208 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
207 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
208 | + $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]"; |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | } |
@@ -220,10 +220,10 @@ discard block |
||
220 | 220 | public function _construct_finalize($parent_form_section, $name) { |
221 | 221 | parent::_construct_finalize($parent_form_section, $name); |
222 | 222 | $this->_set_default_html_name_if_empty(); |
223 | - if( $this->_html_label === null && $this->_html_label_text === null ){ |
|
224 | - $this->_html_label_text = ucwords( str_replace("_"," ",$name)); |
|
223 | + if ($this->_html_label === null && $this->_html_label_text === null) { |
|
224 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
225 | 225 | } |
226 | - do_action( 'AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name ); |
|
226 | + do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -231,8 +231,8 @@ discard block |
||
231 | 231 | * @return EE_Display_Strategy_Base |
232 | 232 | * @throws EE_Error |
233 | 233 | */ |
234 | - protected function _get_display_strategy(){ |
|
235 | - if( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base){ |
|
234 | + protected function _get_display_strategy() { |
|
235 | + if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
236 | 236 | throw new EE_Error( |
237 | 237 | sprintf( |
238 | 238 | __( |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $this->html_id() |
244 | 244 | ) |
245 | 245 | ); |
246 | - }else{ |
|
246 | + } else { |
|
247 | 247 | return $this->_display_strategy; |
248 | 248 | } |
249 | 249 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * Sets the display strategy. |
252 | 252 | * @param EE_Display_Strategy_Base $strategy |
253 | 253 | */ |
254 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy){ |
|
254 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) { |
|
255 | 255 | $this->_display_strategy = $strategy; |
256 | 256 | } |
257 | 257 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * Sets the sanitization strategy |
260 | 260 | * @param EE_Normalization_Strategy_Base $strategy |
261 | 261 | */ |
262 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy){ |
|
262 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) { |
|
263 | 263 | $this->_normalization_strategy = $strategy; |
264 | 264 | } |
265 | 265 | |
@@ -285,14 +285,14 @@ discard block |
||
285 | 285 | * Gets the display strategy for this input |
286 | 286 | * @return EE_Display_Strategy_Base |
287 | 287 | */ |
288 | - public function get_display_strategy(){ |
|
288 | + public function get_display_strategy() { |
|
289 | 289 | return $this->_display_strategy; |
290 | 290 | } |
291 | 291 | /** |
292 | 292 | * Overwrites the display strategy |
293 | 293 | * @param EE_Display_Strategy_Base $display_strategy |
294 | 294 | */ |
295 | - public function set_display_strategy($display_strategy){ |
|
295 | + public function set_display_strategy($display_strategy) { |
|
296 | 296 | $this->_display_strategy = $display_strategy; |
297 | 297 | $this->_display_strategy->_construct_finalize($this); |
298 | 298 | } |
@@ -300,14 +300,14 @@ discard block |
||
300 | 300 | * Gets the normalization strategy set on this input |
301 | 301 | * @return EE_Normalization_Strategy_Base |
302 | 302 | */ |
303 | - public function get_normalization_strategy(){ |
|
303 | + public function get_normalization_strategy() { |
|
304 | 304 | return $this->_normalization_strategy; |
305 | 305 | } |
306 | 306 | /** |
307 | 307 | * Overwrites the normalization strategy |
308 | 308 | * @param EE_Normalization_Strategy_Base $normalization_strategy |
309 | 309 | */ |
310 | - public function set_normalization_strategy($normalization_strategy){ |
|
310 | + public function set_normalization_strategy($normalization_strategy) { |
|
311 | 311 | $this->_normalization_strategy = $normalization_strategy; |
312 | 312 | $this->_normalization_strategy->_construct_finalize($this); |
313 | 313 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * Returns all teh validation strategies which apply to this field, numerically indexed |
317 | 317 | * @return EE_Validation_Strategy_Base[] |
318 | 318 | */ |
319 | - public function get_validation_strategies(){ |
|
319 | + public function get_validation_strategies() { |
|
320 | 320 | return $this->_validation_strategies; |
321 | 321 | } |
322 | 322 | |
@@ -327,8 +327,8 @@ discard block |
||
327 | 327 | * @param EE_Validation_Strategy_Base $validation_strategy |
328 | 328 | * @return void |
329 | 329 | */ |
330 | - protected function _add_validation_strategy( EE_Validation_Strategy_Base $validation_strategy ){ |
|
331 | - $validation_strategy->_construct_finalize( $this ); |
|
330 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) { |
|
331 | + $validation_strategy->_construct_finalize($this); |
|
332 | 332 | $this->_validation_strategies[] = $validation_strategy; |
333 | 333 | } |
334 | 334 | |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | * @param EE_Validation_Strategy_Base $validation_strategy |
340 | 340 | * @return void |
341 | 341 | */ |
342 | - public function add_validation_strategy( EE_Validation_Strategy_Base $validation_strategy ) { |
|
343 | - $this->_add_validation_strategy( $validation_strategy ); |
|
342 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) { |
|
343 | + $this->_add_validation_strategy($validation_strategy); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | |
@@ -350,13 +350,13 @@ discard block |
||
350 | 350 | * |
351 | 351 | * @param string $validation_strategy_classname |
352 | 352 | */ |
353 | - public function remove_validation_strategy( $validation_strategy_classname ) { |
|
354 | - foreach( $this->_validation_strategies as $key => $validation_strategy ){ |
|
355 | - if( |
|
353 | + public function remove_validation_strategy($validation_strategy_classname) { |
|
354 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
355 | + if ( |
|
356 | 356 | $validation_strategy instanceof $validation_strategy_classname |
357 | - || is_subclass_of( $validation_strategy, $validation_strategy_classname ) |
|
357 | + || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
358 | 358 | ) { |
359 | - unset( $this->_validation_strategies[ $key ] ); |
|
359 | + unset($this->_validation_strategies[$key]); |
|
360 | 360 | } |
361 | 361 | } |
362 | 362 | } |
@@ -369,12 +369,12 @@ discard block |
||
369 | 369 | * @param array $validation_strategy_classnames |
370 | 370 | * @return bool |
371 | 371 | */ |
372 | - public function has_validation_strategy( $validation_strategy_classnames ) { |
|
373 | - $validation_strategy_classnames = is_array( $validation_strategy_classnames ) |
|
372 | + public function has_validation_strategy($validation_strategy_classnames) { |
|
373 | + $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
374 | 374 | ? $validation_strategy_classnames |
375 | - : array( $validation_strategy_classnames ); |
|
376 | - foreach( $this->_validation_strategies as $key => $validation_strategy ){ |
|
377 | - if( in_array( $key, $validation_strategy_classnames ) ) { |
|
375 | + : array($validation_strategy_classnames); |
|
376 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
377 | + if (in_array($key, $validation_strategy_classnames)) { |
|
378 | 378 | return true; |
379 | 379 | } |
380 | 380 | } |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | * Gets the HTML |
388 | 388 | * @return string |
389 | 389 | */ |
390 | - public function get_html(){ |
|
390 | + public function get_html() { |
|
391 | 391 | return $this->_parent_section->get_html_for_input($this); |
392 | 392 | } |
393 | 393 | |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | * @return string |
402 | 402 | * @throws \EE_Error |
403 | 403 | */ |
404 | - public function get_html_for_input(){ |
|
404 | + public function get_html_for_input() { |
|
405 | 405 | return $this->_get_display_strategy()->display(); |
406 | 406 | } |
407 | 407 | |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | * @return string |
412 | 412 | */ |
413 | 413 | public function html_other_attributes() { |
414 | - return ! empty( $this->_html_other_attributes ) ? ' ' . $this->_html_other_attributes : ''; |
|
414 | + return ! empty($this->_html_other_attributes) ? ' '.$this->_html_other_attributes : ''; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | /** |
420 | 420 | * @param string $html_other_attributes |
421 | 421 | */ |
422 | - public function set_html_other_attributes( $html_other_attributes ) { |
|
422 | + public function set_html_other_attributes($html_other_attributes) { |
|
423 | 423 | $this->_html_other_attributes = $html_other_attributes; |
424 | 424 | } |
425 | 425 | |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * according to the form section's layout strategy |
429 | 429 | * @return string |
430 | 430 | */ |
431 | - public function get_html_for_label(){ |
|
431 | + public function get_html_for_label() { |
|
432 | 432 | return $this->_parent_section->get_layout_strategy()->display_label($this); |
433 | 433 | } |
434 | 434 | /** |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * according to the form section's layout strategy |
437 | 437 | * @return string |
438 | 438 | */ |
439 | - public function get_html_for_errors(){ |
|
439 | + public function get_html_for_errors() { |
|
440 | 440 | return $this->_parent_section->get_layout_strategy()->display_errors($this); |
441 | 441 | } |
442 | 442 | /** |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | * according to the form section's layout strategy |
445 | 445 | * @return string |
446 | 446 | */ |
447 | - public function get_html_for_help(){ |
|
447 | + public function get_html_for_help() { |
|
448 | 448 | return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
449 | 449 | } |
450 | 450 | /** |
@@ -453,18 +453,18 @@ discard block |
||
453 | 453 | * @return boolean |
454 | 454 | */ |
455 | 455 | protected function _validate() { |
456 | - foreach($this->_validation_strategies as $validation_strategy){ |
|
457 | - if ( $validation_strategy instanceof EE_Validation_Strategy_Base ) { |
|
458 | - try{ |
|
456 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
457 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
458 | + try { |
|
459 | 459 | $validation_strategy->validate($this->normalized_value()); |
460 | - }catch(EE_Validation_Error $e){ |
|
460 | + } catch (EE_Validation_Error $e) { |
|
461 | 461 | $this->add_validation_error($e); |
462 | 462 | } |
463 | 463 | } |
464 | 464 | } |
465 | - if( $this->get_validation_errors()){ |
|
465 | + if ($this->get_validation_errors()) { |
|
466 | 466 | return false; |
467 | - }else{ |
|
467 | + } else { |
|
468 | 468 | return true; |
469 | 469 | } |
470 | 470 | } |
@@ -478,8 +478,8 @@ discard block |
||
478 | 478 | * @param string $value |
479 | 479 | * @return null|string |
480 | 480 | */ |
481 | - private function _sanitize( $value ) { |
|
482 | - return $value !== null ? stripslashes( html_entity_decode( trim( $value ) ) ) : null; |
|
481 | + private function _sanitize($value) { |
|
482 | + return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | |
@@ -493,25 +493,25 @@ discard block |
||
493 | 493 | * @return boolean whether or not there was an error |
494 | 494 | * @throws \EE_Error |
495 | 495 | */ |
496 | - protected function _normalize( $req_data ) { |
|
496 | + protected function _normalize($req_data) { |
|
497 | 497 | //any existing validation errors don't apply so clear them |
498 | 498 | $this->_validation_errors = array(); |
499 | 499 | try { |
500 | - $raw_input = $this->find_form_data_for_this_section( $req_data ); |
|
500 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
501 | 501 | //super simple sanitization for now |
502 | - if ( is_array( $raw_input )) { |
|
502 | + if (is_array($raw_input)) { |
|
503 | 503 | $raw_value = array(); |
504 | - foreach( $raw_input as $key => $value ) { |
|
505 | - $raw_value[ $key ] = $this->_sanitize( $value ); |
|
504 | + foreach ($raw_input as $key => $value) { |
|
505 | + $raw_value[$key] = $this->_sanitize($value); |
|
506 | 506 | } |
507 | - $this->_set_raw_value( $raw_value ); |
|
507 | + $this->_set_raw_value($raw_value); |
|
508 | 508 | } else { |
509 | - $this->_set_raw_value( $this->_sanitize( $raw_input ) ); |
|
509 | + $this->_set_raw_value($this->_sanitize($raw_input)); |
|
510 | 510 | } |
511 | 511 | //we want to mostly leave the input alone in case we need to re-display it to the user |
512 | - $this->_set_normalized_value( $this->_normalization_strategy->normalize( $this->raw_value() ) ); |
|
513 | - } catch ( EE_Validation_Error $e ) { |
|
514 | - $this->add_validation_error( $e ); |
|
512 | + $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
513 | + } catch (EE_Validation_Error $e) { |
|
514 | + $this->add_validation_error($e); |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | /** |
521 | 521 | * @return string |
522 | 522 | */ |
523 | - public function html_name(){ |
|
523 | + public function html_name() { |
|
524 | 524 | return $this->_html_name; |
525 | 525 | } |
526 | 526 | |
@@ -529,8 +529,8 @@ discard block |
||
529 | 529 | /** |
530 | 530 | * @return string |
531 | 531 | */ |
532 | - public function html_label_id(){ |
|
533 | - return ! empty( $this->_html_label_id ) ? $this->_html_label_id : $this->_html_id . '-lbl'; |
|
532 | + public function html_label_id() { |
|
533 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->_html_id.'-lbl'; |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | /** |
539 | 539 | * @return string |
540 | 540 | */ |
541 | - public function html_label_class(){ |
|
541 | + public function html_label_class() { |
|
542 | 542 | return $this->_html_label_class; |
543 | 543 | } |
544 | 544 | |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | /** |
548 | 548 | * @return string |
549 | 549 | */ |
550 | - public function html_label_style(){ |
|
550 | + public function html_label_style() { |
|
551 | 551 | return $this->_html_label_style; |
552 | 552 | } |
553 | 553 | |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | /** |
557 | 557 | * @return string |
558 | 558 | */ |
559 | - public function html_label_text(){ |
|
559 | + public function html_label_text() { |
|
560 | 560 | return $this->_html_label_text; |
561 | 561 | } |
562 | 562 | |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | /** |
566 | 566 | * @return string |
567 | 567 | */ |
568 | - public function html_help_text(){ |
|
568 | + public function html_help_text() { |
|
569 | 569 | return $this->_html_help_text; |
570 | 570 | } |
571 | 571 | |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | /** |
575 | 575 | * @return string |
576 | 576 | */ |
577 | - public function html_help_class(){ |
|
577 | + public function html_help_class() { |
|
578 | 578 | return $this->_html_help_class; |
579 | 579 | } |
580 | 580 | |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | /** |
584 | 584 | * @return string |
585 | 585 | */ |
586 | - public function html_help_style(){ |
|
586 | + public function html_help_style() { |
|
587 | 587 | return $this->_html_style; |
588 | 588 | } |
589 | 589 | /** |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | * in which case, we would have stored the malicious content to our database. |
597 | 597 | * @return string |
598 | 598 | */ |
599 | - public function raw_value(){ |
|
599 | + public function raw_value() { |
|
600 | 600 | return $this->_raw_value; |
601 | 601 | } |
602 | 602 | /** |
@@ -604,15 +604,15 @@ discard block |
||
604 | 604 | * it escapes all html entities |
605 | 605 | * @return string |
606 | 606 | */ |
607 | - public function raw_value_in_form(){ |
|
608 | - return htmlentities($this->raw_value(),ENT_QUOTES, 'UTF-8'); |
|
607 | + public function raw_value_in_form() { |
|
608 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
609 | 609 | } |
610 | 610 | /** |
611 | 611 | * returns the value after it's been sanitized, and then converted into it's proper type |
612 | 612 | * in PHP. Eg, a string, an int, an array, |
613 | 613 | * @return mixed |
614 | 614 | */ |
615 | - public function normalized_value(){ |
|
615 | + public function normalized_value() { |
|
616 | 616 | return $this->_normalized_value; |
617 | 617 | } |
618 | 618 | |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | * the best thing to display |
623 | 623 | * @return string |
624 | 624 | */ |
625 | - public function pretty_value(){ |
|
625 | + public function pretty_value() { |
|
626 | 626 | return $this->_normalized_value; |
627 | 627 | } |
628 | 628 | /** |
@@ -641,19 +641,19 @@ discard block |
||
641 | 641 | }</code> |
642 | 642 | * @return array |
643 | 643 | */ |
644 | - public function get_jquery_validation_rules(){ |
|
644 | + public function get_jquery_validation_rules() { |
|
645 | 645 | $jquery_validation_js = array(); |
646 | 646 | $jquery_validation_rules = array(); |
647 | - foreach($this->get_validation_strategies() as $validation_strategy){ |
|
647 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
648 | 648 | $jquery_validation_rules = array_replace_recursive( |
649 | 649 | $jquery_validation_rules, |
650 | 650 | $validation_strategy->get_jquery_validation_rule_array() |
651 | 651 | ); |
652 | 652 | } |
653 | 653 | |
654 | - if(! empty($jquery_validation_rules)){ |
|
655 | - foreach( $this->get_display_strategy()->get_html_input_ids( true ) as $html_id_with_pound_sign ) { |
|
656 | - $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules; |
|
654 | + if ( ! empty($jquery_validation_rules)) { |
|
655 | + foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
656 | + $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | return $jquery_validation_js; |
@@ -665,16 +665,16 @@ discard block |
||
665 | 665 | * @param mixed $value |
666 | 666 | * @return void |
667 | 667 | */ |
668 | - public function set_default($value){ |
|
669 | - $this->_set_normalized_value( $value ); |
|
670 | - $this->_set_raw_value( $value ); |
|
668 | + public function set_default($value) { |
|
669 | + $this->_set_normalized_value($value); |
|
670 | + $this->_set_raw_value($value); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
674 | 674 | * Sets the normalized value on this input |
675 | 675 | * @param mixed $value |
676 | 676 | */ |
677 | - protected function _set_normalized_value( $value ) { |
|
677 | + protected function _set_normalized_value($value) { |
|
678 | 678 | $this->_normalized_value = $value; |
679 | 679 | } |
680 | 680 | |
@@ -682,8 +682,8 @@ discard block |
||
682 | 682 | * Sets the raw value on this input (ie, exactly as the user submitted it) |
683 | 683 | * @param mixed $value |
684 | 684 | */ |
685 | - protected function _set_raw_value( $value ) { |
|
686 | - $this->_raw_value = $this->_normalization_strategy->unnormalize( $value ); |
|
685 | + protected function _set_raw_value($value) { |
|
686 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | /** |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | * @param string $label |
692 | 692 | * @return void |
693 | 693 | */ |
694 | - public function set_html_label_text($label){ |
|
694 | + public function set_html_label_text($label) { |
|
695 | 695 | $this->_html_label_text = $label; |
696 | 696 | } |
697 | 697 | |
@@ -705,13 +705,13 @@ discard block |
||
705 | 705 | * @param boolean $required boolean |
706 | 706 | * @param null $required_text |
707 | 707 | */ |
708 | - public function set_required($required = true, $required_text = NULL ){ |
|
709 | - $required = filter_var( $required, FILTER_VALIDATE_BOOLEAN ); |
|
708 | + public function set_required($required = true, $required_text = NULL) { |
|
709 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
710 | 710 | //whether $required is a string or a boolean, we want to add a required validation strategy |
711 | - if ( $required ) { |
|
712 | - $this->_add_validation_strategy( new EE_Required_Validation_Strategy( $required_text ) ); |
|
711 | + if ($required) { |
|
712 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
713 | 713 | } else { |
714 | - $this->remove_validation_strategy( 'EE_Required_Validation_Strategy' ); |
|
714 | + $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
715 | 715 | } |
716 | 716 | $this->_required = $required; |
717 | 717 | } |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | * Returns whether or not this field is required |
720 | 720 | * @return boolean |
721 | 721 | */ |
722 | - public function required(){ |
|
722 | + public function required() { |
|
723 | 723 | return $this->_required; |
724 | 724 | } |
725 | 725 | |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | /** |
729 | 729 | * @param string $required_css_class |
730 | 730 | */ |
731 | - public function set_required_css_class( $required_css_class ) { |
|
731 | + public function set_required_css_class($required_css_class) { |
|
732 | 732 | $this->_required_css_class = $required_css_class; |
733 | 733 | } |
734 | 734 | |
@@ -747,7 +747,7 @@ discard block |
||
747 | 747 | * Sets the help text, in case |
748 | 748 | * @param string $text |
749 | 749 | */ |
750 | - public function set_html_help_text($text){ |
|
750 | + public function set_html_help_text($text) { |
|
751 | 751 | $this->_html_help_text = $text; |
752 | 752 | } |
753 | 753 | /** |
@@ -759,9 +759,9 @@ discard block |
||
759 | 759 | public function clean_sensitive_data() { |
760 | 760 | //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
761 | 761 | //if we need more logic than this we'll make a strategy for it |
762 | - if( $this->_sensitive_data_removal_strategy && |
|
763 | - ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal ){ |
|
764 | - $this->_set_raw_value( null ); |
|
762 | + if ($this->_sensitive_data_removal_strategy && |
|
763 | + ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal) { |
|
764 | + $this->_set_raw_value(null); |
|
765 | 765 | } |
766 | 766 | //and clean the normalized value according to the appropriate strategy |
767 | 767 | $this->_set_normalized_value( |
@@ -778,10 +778,10 @@ discard block |
||
778 | 778 | * @param string $button_size |
779 | 779 | * @param string $other_attributes |
780 | 780 | */ |
781 | - public function set_button_css_attributes( $primary = TRUE, $button_size = '', $other_attributes = '' ) { |
|
781 | + public function set_button_css_attributes($primary = TRUE, $button_size = '', $other_attributes = '') { |
|
782 | 782 | $button_css_attributes = 'button'; |
783 | 783 | $button_css_attributes .= $primary === TRUE ? ' button-primary' : ' button-secondary'; |
784 | - switch ( $button_size ) { |
|
784 | + switch ($button_size) { |
|
785 | 785 | case 'xs' : |
786 | 786 | case 'extra-small' : |
787 | 787 | $button_css_attributes .= ' button-xs'; |
@@ -802,8 +802,8 @@ discard block |
||
802 | 802 | default : |
803 | 803 | $button_css_attributes .= ''; |
804 | 804 | } |
805 | - $this->_button_css_attributes .= ! empty( $other_attributes ) |
|
806 | - ? $button_css_attributes . ' ' . $other_attributes |
|
805 | + $this->_button_css_attributes .= ! empty($other_attributes) |
|
806 | + ? $button_css_attributes.' '.$other_attributes |
|
807 | 807 | : $button_css_attributes; |
808 | 808 | } |
809 | 809 | |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | * @return string |
814 | 814 | */ |
815 | 815 | public function button_css_attributes() { |
816 | - if ( empty( $this->_button_css_attributes )) { |
|
816 | + if (empty($this->_button_css_attributes)) { |
|
817 | 817 | $this->set_button_css_attributes(); |
818 | 818 | } |
819 | 819 | return $this->_button_css_attributes; |
@@ -835,26 +835,26 @@ discard block |
||
835 | 835 | * @return mixed whatever the raw value of this form section is in the request data |
836 | 836 | * @throws \EE_Error |
837 | 837 | */ |
838 | - public function find_form_data_for_this_section( $req_data ){ |
|
838 | + public function find_form_data_for_this_section($req_data) { |
|
839 | 839 | // break up the html name by "[]" |
840 | - if ( strpos( $this->html_name(), '[' ) !== FALSE ) { |
|
841 | - $before_any_brackets = substr( $this->html_name(), 0, strpos($this->html_name(), '[') ); |
|
840 | + if (strpos($this->html_name(), '[') !== FALSE) { |
|
841 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
842 | 842 | } else { |
843 | 843 | $before_any_brackets = $this->html_name(); |
844 | 844 | } |
845 | 845 | // grab all of the segments |
846 | - preg_match_all('~\[([^]]*)\]~',$this->html_name(), $matches); |
|
847 | - if( isset( $matches[ 1 ] ) && is_array( $matches[ 1 ] ) ){ |
|
848 | - $name_parts = $matches[ 1 ]; |
|
846 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
847 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
848 | + $name_parts = $matches[1]; |
|
849 | 849 | array_unshift($name_parts, $before_any_brackets); |
850 | - }else{ |
|
851 | - $name_parts = array( $before_any_brackets ); |
|
850 | + } else { |
|
851 | + $name_parts = array($before_any_brackets); |
|
852 | 852 | } |
853 | 853 | // now get the value for the input |
854 | 854 | $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
855 | 855 | // check if this thing's name is at the TOP level of the request data |
856 | - if( $value === null && isset( $req_data[ $this->name() ] ) ){ |
|
857 | - $value = $req_data[ $this->name() ]; |
|
856 | + if ($value === null && isset($req_data[$this->name()])) { |
|
857 | + $value = $req_data[$this->name()]; |
|
858 | 858 | } |
859 | 859 | return $value; |
860 | 860 | } |
@@ -867,18 +867,18 @@ discard block |
||
867 | 867 | * @param array $req_data |
868 | 868 | * @return array | NULL |
869 | 869 | */ |
870 | - public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data){ |
|
871 | - $first_part_to_consider = array_shift( $html_name_parts ); |
|
872 | - if( isset( $req_data[ $first_part_to_consider ] ) ){ |
|
873 | - if( empty($html_name_parts ) ){ |
|
874 | - return $req_data[ $first_part_to_consider ]; |
|
875 | - }else{ |
|
870 | + public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) { |
|
871 | + $first_part_to_consider = array_shift($html_name_parts); |
|
872 | + if (isset($req_data[$first_part_to_consider])) { |
|
873 | + if (empty($html_name_parts)) { |
|
874 | + return $req_data[$first_part_to_consider]; |
|
875 | + } else { |
|
876 | 876 | return $this->_find_form_data_for_this_section_using_name_parts( |
877 | 877 | $html_name_parts, |
878 | - $req_data[ $first_part_to_consider ] |
|
878 | + $req_data[$first_part_to_consider] |
|
879 | 879 | ); |
880 | 880 | } |
881 | - }else{ |
|
881 | + } else { |
|
882 | 882 | return NULL; |
883 | 883 | } |
884 | 884 | } |
@@ -892,14 +892,14 @@ discard block |
||
892 | 892 | * @return boolean |
893 | 893 | * @throws \EE_Error |
894 | 894 | */ |
895 | - public function form_data_present_in($req_data = NULL){ |
|
896 | - if( $req_data === NULL ){ |
|
895 | + public function form_data_present_in($req_data = NULL) { |
|
896 | + if ($req_data === NULL) { |
|
897 | 897 | $req_data = $_POST; |
898 | 898 | } |
899 | - $checked_value = $this->find_form_data_for_this_section( $req_data ); |
|
900 | - if( $checked_value !== null ){ |
|
899 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
900 | + if ($checked_value !== null) { |
|
901 | 901 | return TRUE; |
902 | - }else{ |
|
902 | + } else { |
|
903 | 903 | return FALSE; |
904 | 904 | } |
905 | 905 | } |
@@ -910,8 +910,8 @@ discard block |
||
910 | 910 | * @param array $form_other_js_data |
911 | 911 | * @return array |
912 | 912 | */ |
913 | - public function get_other_js_data( $form_other_js_data = array() ) { |
|
914 | - $form_other_js_data = $this->get_other_js_data_from_strategies( $form_other_js_data ); |
|
913 | + public function get_other_js_data($form_other_js_data = array()) { |
|
914 | + $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
915 | 915 | return $form_other_js_data; |
916 | 916 | } |
917 | 917 | |
@@ -924,10 +924,10 @@ discard block |
||
924 | 924 | * @param array $form_other_js_data |
925 | 925 | * @return array |
926 | 926 | */ |
927 | - public function get_other_js_data_from_strategies( $form_other_js_data = array() ) { |
|
928 | - $form_other_js_data = $this->get_display_strategy()->get_other_js_data( $form_other_js_data ); |
|
929 | - foreach( $this->get_validation_strategies() as $validation_strategy ) { |
|
930 | - $form_other_js_data = $validation_strategy->get_other_js_data( $form_other_js_data ); |
|
927 | + public function get_other_js_data_from_strategies($form_other_js_data = array()) { |
|
928 | + $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
929 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
930 | + $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
931 | 931 | } |
932 | 932 | return $form_other_js_data; |
933 | 933 | } |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
937 | 937 | * @return void |
938 | 938 | */ |
939 | - public function enqueue_js(){ |
|
939 | + public function enqueue_js() { |
|
940 | 940 | //ask our display strategy and validation strategies if they have js to enqueue |
941 | 941 | $this->enqueue_js_from_strategies(); |
942 | 942 | } |
@@ -947,7 +947,7 @@ discard block |
||
947 | 947 | */ |
948 | 948 | public function enqueue_js_from_strategies() { |
949 | 949 | $this->get_display_strategy()->enqueue_js(); |
950 | - foreach( $this->get_validation_strategies() as $validation_strategy ) { |
|
950 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
951 | 951 | $validation_strategy->enqueue_js(); |
952 | 952 | } |
953 | 953 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ){ |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | /** |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | |
27 | 27 | |
28 | 28 | protected function _setup_data() { |
29 | - $this->_data = $this->_get_messages( $this->_per_page, $this->_view ); |
|
30 | - $this->_all_data_count = $this->_get_messages( $this->_per_page, $this->_view, true ); |
|
29 | + $this->_data = $this->_get_messages($this->_per_page, $this->_view); |
|
30 | + $this->_all_data_count = $this->_get_messages($this->_per_page, $this->_view, true); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | |
@@ -35,32 +35,32 @@ discard block |
||
35 | 35 | |
36 | 36 | protected function _set_properties() { |
37 | 37 | $this->_wp_list_args = array( |
38 | - 'singular' => __( 'Message', 'event_espresso' ), |
|
39 | - 'plural' => __( 'Messages', 'event_espresso' ), |
|
38 | + 'singular' => __('Message', 'event_espresso'), |
|
39 | + 'plural' => __('Messages', 'event_espresso'), |
|
40 | 40 | 'ajax' => true, |
41 | 41 | 'screen' => $this->get_admin_page()->get_current_screen()->id |
42 | 42 | ); |
43 | 43 | |
44 | 44 | $this->_columns = array( |
45 | 45 | 'cb' => '<input type="checkbox" />', |
46 | - 'to' => __( 'To', 'event_espresso' ), |
|
47 | - 'from' => __( 'From', 'event_espresso' ), |
|
48 | - 'messenger' => __( 'Messenger', 'event_espresso' ), |
|
49 | - 'message_type' => __( 'Message Type', 'event_espresso' ), |
|
50 | - 'context' => __( 'Context', 'event_espresso' ), |
|
51 | - 'modified' => __( 'Modified', 'event_espresso' ), |
|
52 | - 'action' => __( 'Actions', 'event_espresso' ), |
|
53 | - 'msg_id' => __( 'ID', 'event_espresso' ), |
|
46 | + 'to' => __('To', 'event_espresso'), |
|
47 | + 'from' => __('From', 'event_espresso'), |
|
48 | + 'messenger' => __('Messenger', 'event_espresso'), |
|
49 | + 'message_type' => __('Message Type', 'event_espresso'), |
|
50 | + 'context' => __('Context', 'event_espresso'), |
|
51 | + 'modified' => __('Modified', 'event_espresso'), |
|
52 | + 'action' => __('Actions', 'event_espresso'), |
|
53 | + 'msg_id' => __('ID', 'event_espresso'), |
|
54 | 54 | ); |
55 | 55 | |
56 | 56 | $this->_sortable_columns = array( |
57 | - 'modified' => array( 'MSG_modified' => true ), |
|
58 | - 'message_type' => array( 'MSG_message_type' => false ), |
|
59 | - 'messenger' => array( 'MSG_messenger' => false ), |
|
60 | - 'to' => array( 'MSG_to' => false ), |
|
61 | - 'from' => array( 'MSG_from' => false ), |
|
62 | - 'context' => array( 'MSG_context' => false ), |
|
63 | - 'msg_id' => array( 'MSG_ID', false ), |
|
57 | + 'modified' => array('MSG_modified' => true), |
|
58 | + 'message_type' => array('MSG_message_type' => false), |
|
59 | + 'messenger' => array('MSG_messenger' => false), |
|
60 | + 'to' => array('MSG_to' => false), |
|
61 | + 'from' => array('MSG_from' => false), |
|
62 | + 'context' => array('MSG_context' => false), |
|
63 | + 'msg_id' => array('MSG_ID', false), |
|
64 | 64 | ); |
65 | 65 | |
66 | 66 | $this->_primary_column = 'to'; |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | * @param object $item the current item |
79 | 79 | * @return string |
80 | 80 | */ |
81 | - protected function _get_row_class( $item ) { |
|
82 | - $class = parent::_get_row_class( $item ); |
|
81 | + protected function _get_row_class($item) { |
|
82 | + $class = parent::_get_row_class($item); |
|
83 | 83 | //add status class |
84 | - $class .= ' ee-status-strip msg-status-' . $item->STS_ID(); |
|
85 | - if ( $this->_has_checkbox_column ) { |
|
84 | + $class .= ' ee-status-strip msg-status-'.$item->STS_ID(); |
|
85 | + if ($this->_has_checkbox_column) { |
|
86 | 86 | $class .= ' has-checkbox-column'; |
87 | 87 | } |
88 | 88 | return $class; |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | ); |
111 | 111 | |
112 | 112 | //set filters to select inputs if they aren't empty |
113 | - foreach ( $select_inputs as $select_input ) { |
|
114 | - if ( $select_input ) { |
|
113 | + foreach ($select_inputs as $select_input) { |
|
114 | + if ($select_input) { |
|
115 | 115 | $filters[] = $select_input; |
116 | 116 | } |
117 | 117 | } |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | |
122 | 122 | |
123 | 123 | protected function _add_view_counts() { |
124 | - foreach ( $this->_views as $view => $args ) { |
|
125 | - $this->_views[ $view ]['count'] = $this->_get_messages( $this->_per_page, $view, true, true ); |
|
124 | + foreach ($this->_views as $view => $args) { |
|
125 | + $this->_views[$view]['count'] = $this->_get_messages($this->_per_page, $view, true, true); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | * @return string checkbox |
134 | 134 | * @throws \EE_Error |
135 | 135 | */ |
136 | - public function column_cb( $message ) { |
|
137 | - return sprintf( '<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID() ); |
|
136 | + public function column_cb($message) { |
|
137 | + return sprintf('<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID()); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return string |
145 | 145 | * @throws \EE_Error |
146 | 146 | */ |
147 | - public function column_msg_id( EE_Message $message ) { |
|
147 | + public function column_msg_id(EE_Message $message) { |
|
148 | 148 | return $message->ID(); |
149 | 149 | } |
150 | 150 | |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | * @return string The recipient of the message |
156 | 156 | * @throws \EE_Error |
157 | 157 | */ |
158 | - public function column_to( EE_Message $message ) { |
|
159 | - EE_Registry::instance()->load_helper( 'URL' ); |
|
158 | + public function column_to(EE_Message $message) { |
|
159 | + EE_Registry::instance()->load_helper('URL'); |
|
160 | 160 | $actions = array(); |
161 | 161 | $actions['delete'] = '<a href="' |
162 | 162 | . EEH_URL::add_query_args_and_nonce( |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | 'action' => 'delete_ee_message', |
166 | 166 | 'MSG_ID' => $message->ID() |
167 | 167 | ), |
168 | - admin_url( 'admin.php' ) |
|
168 | + admin_url('admin.php') |
|
169 | 169 | ) |
170 | - . '">' . __( 'Delete', 'event_espresso' ) . '</a>'; |
|
171 | - return esc_html( $message->to() ) . $this->row_actions( $actions ); |
|
170 | + . '">'.__('Delete', 'event_espresso').'</a>'; |
|
171 | + return esc_html($message->to()).$this->row_actions($actions); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | * @param EE_Message $message |
177 | 177 | * @return string The sender of the message |
178 | 178 | */ |
179 | - public function column_from( EE_Message $message ) { |
|
180 | - return esc_html( $message->from() ); |
|
179 | + public function column_from(EE_Message $message) { |
|
180 | + return esc_html($message->from()); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * @param EE_Message $message |
187 | 187 | * @return string The messenger used to send the message. |
188 | 188 | */ |
189 | - public function column_messenger( EE_Message $message ) { |
|
190 | - return ucwords( $message->messenger_label() ); |
|
189 | + public function column_messenger(EE_Message $message) { |
|
190 | + return ucwords($message->messenger_label()); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | * @param EE_Message $message |
196 | 196 | * @return string The message type used to generate the message. |
197 | 197 | */ |
198 | - public function column_message_type( EE_Message $message ) { |
|
199 | - return ucwords( $message->message_type_label() ); |
|
198 | + public function column_message_type(EE_Message $message) { |
|
199 | + return ucwords($message->message_type_label()); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @param EE_Message $message |
205 | 205 | * @return string The context the message was generated for. |
206 | 206 | */ |
207 | - public function column_context( EE_Message $message ) { |
|
207 | + public function column_context(EE_Message $message) { |
|
208 | 208 | return $message->context_label(); |
209 | 209 | } |
210 | 210 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @param EE_Message $message |
214 | 214 | * @return string The timestamp when this message was last modified. |
215 | 215 | */ |
216 | - public function column_modified( EE_Message $message ) { |
|
216 | + public function column_modified(EE_Message $message) { |
|
217 | 217 | return $message->modified(); |
218 | 218 | } |
219 | 219 | |
@@ -222,36 +222,36 @@ discard block |
||
222 | 222 | * @param EE_Message $message |
223 | 223 | * @return string Actions that can be done on the current message. |
224 | 224 | */ |
225 | - public function column_action( EE_Message $message ) { |
|
226 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
225 | + public function column_action(EE_Message $message) { |
|
226 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
227 | 227 | $action_links = array( |
228 | - 'view' => EEH_MSG_Template::get_message_action_link( 'view', $message ), |
|
229 | - 'error' => EEH_MSG_Template::get_message_action_link( 'error', $message ), |
|
230 | - 'generate_now' => EEH_MSG_Template::get_message_action_link( 'generate_now', $message ), |
|
231 | - 'send_now' => EEH_MSG_Template::get_message_action_link( 'send_now', $message ), |
|
232 | - 'queue_for_resending' => EEH_MSG_Template::get_message_action_link( 'queue_for_resending', $message ), |
|
233 | - 'view_transaction' => EEH_MSG_Template::get_message_action_link( 'view_transaction', $message ), |
|
228 | + 'view' => EEH_MSG_Template::get_message_action_link('view', $message), |
|
229 | + 'error' => EEH_MSG_Template::get_message_action_link('error', $message), |
|
230 | + 'generate_now' => EEH_MSG_Template::get_message_action_link('generate_now', $message), |
|
231 | + 'send_now' => EEH_MSG_Template::get_message_action_link('send_now', $message), |
|
232 | + 'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message), |
|
233 | + 'view_transaction' => EEH_MSG_Template::get_message_action_link('view_transaction', $message), |
|
234 | 234 | ); |
235 | 235 | $content = ''; |
236 | - switch ( $message->STS_ID() ) { |
|
236 | + switch ($message->STS_ID()) { |
|
237 | 237 | case EEM_Message::status_sent : |
238 | - $content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction']; |
|
238 | + $content = $action_links['view'].$action_links['queue_for_resending'].$action_links['view_transaction']; |
|
239 | 239 | break; |
240 | 240 | case EEM_Message::status_resend : |
241 | - $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
241 | + $content = $action_links['view'].$action_links['send_now'].$action_links['view_transaction']; |
|
242 | 242 | break; |
243 | 243 | case EEM_Message::status_retry : |
244 | - $content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction']; |
|
244 | + $content = $action_links['view'].$action_links['send_now'].$action_links['error'].$action_links['view_transaction']; |
|
245 | 245 | break; |
246 | 246 | case EEM_Message::status_failed : |
247 | 247 | case EEM_Message::status_debug_only : |
248 | - $content = $action_links['error'] . $action_links['view_transaction']; |
|
248 | + $content = $action_links['error'].$action_links['view_transaction']; |
|
249 | 249 | break; |
250 | 250 | case EEM_Message::status_idle : |
251 | - $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction']; |
|
251 | + $content = $action_links['view'].$action_links['send_now'].$action_links['view_transaction']; |
|
252 | 252 | break; |
253 | 253 | case EEM_Message::status_incomplete; |
254 | - $content = $action_links['generate_now'] . $action_links['view_transaction']; |
|
254 | + $content = $action_links['generate_now'].$action_links['view_transaction']; |
|
255 | 255 | break; |
256 | 256 | } |
257 | 257 | return $content; |
@@ -269,54 +269,54 @@ discard block |
||
269 | 269 | * @return int | EE_Message[] |
270 | 270 | * @throws \EE_Error |
271 | 271 | */ |
272 | - protected function _get_messages( $perpage = 10, $view = 'all', $count = false, $all = false ) { |
|
272 | + protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false) { |
|
273 | 273 | |
274 | - $current_page = isset( $this->_req_data['paged'] ) && ! empty( $this->_req_data['paged'] ) |
|
274 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
275 | 275 | ? $this->_req_data['paged'] |
276 | 276 | : 1; |
277 | 277 | |
278 | - $per_page = isset( $this->_req_data['perpage'] ) && ! empty( $this->_req_data['perpage'] ) |
|
278 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
279 | 279 | ? $this->_req_data['perpage'] |
280 | 280 | : $perpage; |
281 | 281 | |
282 | - $offset = ( $current_page - 1 ) * $per_page; |
|
283 | - $limit = $all || $count ? null : array( $offset, $per_page ); |
|
282 | + $offset = ($current_page - 1) * $per_page; |
|
283 | + $limit = $all || $count ? null : array($offset, $per_page); |
|
284 | 284 | $query_params = array( |
285 | - 'order_by' => empty( $this->_req_data[ 'orderby' ] ) ? 'MSG_modified' : $this->_req_data[ 'orderby' ], |
|
286 | - 'order' => empty( $this->_req_data[ 'order' ] ) ? 'DESC' : $this->_req_data[ 'order' ], |
|
285 | + 'order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'], |
|
286 | + 'order' => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'], |
|
287 | 287 | 'limit' => $limit, |
288 | 288 | ); |
289 | 289 | |
290 | 290 | /** |
291 | 291 | * Any filters coming in from other routes? |
292 | 292 | */ |
293 | - if ( isset( $this->_req_data['filterby'] ) ) { |
|
294 | - $query_params = array_merge( $query_params, EEM_Message::instance()->filter_by_query_params() ); |
|
295 | - if ( ! $count ) { |
|
293 | + if (isset($this->_req_data['filterby'])) { |
|
294 | + $query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params()); |
|
295 | + if ( ! $count) { |
|
296 | 296 | $query_params['group_by'] = 'MSG_ID'; |
297 | 297 | } |
298 | 298 | } |
299 | 299 | |
300 | 300 | //view conditionals |
301 | - if ( $view !== 'all' && $count && $all ) { |
|
301 | + if ($view !== 'all' && $count && $all) { |
|
302 | 302 | $query_params[0]['AND*view_conditional'] = array( |
303 | - 'STS_ID' => strtoupper( $view ), |
|
303 | + 'STS_ID' => strtoupper($view), |
|
304 | 304 | ); |
305 | 305 | } |
306 | 306 | |
307 | - if ( ! $all && ! empty( $this->_req_data['status'] ) && $this->_req_data['status'] !== 'all' ) { |
|
307 | + if ( ! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') { |
|
308 | 308 | $query_params[0]['AND*view_conditional'] = array( |
309 | - 'STS_ID' => strtoupper( $this->_req_data['status'] ), |
|
309 | + 'STS_ID' => strtoupper($this->_req_data['status']), |
|
310 | 310 | ); |
311 | 311 | } |
312 | 312 | |
313 | - if ( ! $all && ! empty( $this->_req_data['s'] ) ) { |
|
314 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
313 | + if ( ! $all && ! empty($this->_req_data['s'])) { |
|
314 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
315 | 315 | $query_params[0]['OR'] = array( |
316 | - 'MSG_to' => array( 'LIKE', $search_string ), |
|
317 | - 'MSG_from' => array( 'LIKE', $search_string ), |
|
318 | - 'MSG_subject' => array( 'LIKE', $search_string ), |
|
319 | - 'MSG_content' => array( 'LIKE', $search_string ), |
|
316 | + 'MSG_to' => array('LIKE', $search_string), |
|
317 | + 'MSG_from' => array('LIKE', $search_string), |
|
318 | + 'MSG_subject' => array('LIKE', $search_string), |
|
319 | + 'MSG_content' => array('LIKE', $search_string), |
|
320 | 320 | ); |
321 | 321 | } |
322 | 322 | |
@@ -324,16 +324,16 @@ discard block |
||
324 | 324 | //the messages system is in debug mode. |
325 | 325 | //Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only |
326 | 326 | //messages in the database. |
327 | - if ( ! EEM_Message::debug() ) { |
|
327 | + if ( ! EEM_Message::debug()) { |
|
328 | 328 | $query_params[0]['AND*debug_only_conditional'] = array( |
329 | - 'STS_ID' => array( '!=', EEM_Message::status_debug_only ) |
|
329 | + 'STS_ID' => array('!=', EEM_Message::status_debug_only) |
|
330 | 330 | ); |
331 | 331 | } |
332 | 332 | |
333 | 333 | //account for filters |
334 | 334 | if ( |
335 | 335 | ! $all |
336 | - && isset( $this->_req_data['ee_messenger_filter_by'] ) |
|
336 | + && isset($this->_req_data['ee_messenger_filter_by']) |
|
337 | 337 | && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected' |
338 | 338 | ) { |
339 | 339 | $query_params[0]['AND*messenger_filter'] = array( |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | } |
343 | 343 | if ( |
344 | 344 | ! $all |
345 | - && ! empty( $this->_req_data['ee_message_type_filter_by'] ) |
|
345 | + && ! empty($this->_req_data['ee_message_type_filter_by']) |
|
346 | 346 | && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected' |
347 | 347 | ) { |
348 | 348 | $query_params[0]['AND*message_type_filter'] = array( |
@@ -352,17 +352,17 @@ discard block |
||
352 | 352 | |
353 | 353 | if ( |
354 | 354 | ! $all |
355 | - && ! empty( $this->_req_data['ee_context_filter_by'] ) |
|
355 | + && ! empty($this->_req_data['ee_context_filter_by']) |
|
356 | 356 | && $this->_req_data['ee_context_filter_by'] !== 'none_selected' |
357 | 357 | ) { |
358 | 358 | $query_params[0]['AND*context_filter'] = array( |
359 | - 'MSG_context' => array( 'IN', explode( ',', $this->_req_data['ee_context_filter_by'] ) ) |
|
359 | + 'MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by'])) |
|
360 | 360 | ); |
361 | 361 | } |
362 | 362 | |
363 | 363 | return $count |
364 | - ? EEM_Message::instance()->count( $query_params, null, true ) |
|
365 | - : EEM_Message::instance()->get_all( $query_params ); |
|
364 | + ? EEM_Message::instance()->count($query_params, null, true) |
|
365 | + : EEM_Message::instance()->get_all($query_params); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | |
@@ -372,15 +372,15 @@ discard block |
||
372 | 372 | */ |
373 | 373 | protected function _get_messengers_dropdown_filter() { |
374 | 374 | $messenger_options = array(); |
375 | - $active_messages_grouped_by_messenger = EEM_Message::instance()->get_all( array( 'group_by' => 'MSG_messenger' ) ); |
|
375 | + $active_messages_grouped_by_messenger = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger')); |
|
376 | 376 | |
377 | 377 | //setup array of messenger options |
378 | - foreach ( $active_messages_grouped_by_messenger as $active_message ) { |
|
379 | - if ( $active_message instanceof EE_Message ) { |
|
380 | - $messenger_options[ $active_message->messenger() ] = ucwords( $active_message->messenger_label() ); |
|
378 | + foreach ($active_messages_grouped_by_messenger as $active_message) { |
|
379 | + if ($active_message instanceof EE_Message) { |
|
380 | + $messenger_options[$active_message->messenger()] = ucwords($active_message->messenger_label()); |
|
381 | 381 | } |
382 | 382 | } |
383 | - return $this->get_admin_page()->get_messengers_select_input( $messenger_options ); |
|
383 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | |
@@ -391,15 +391,15 @@ discard block |
||
391 | 391 | */ |
392 | 392 | protected function _get_message_types_dropdown_filter() { |
393 | 393 | $message_type_options = array(); |
394 | - $active_messages_grouped_by_message_type = EEM_Message::instance()->get_all( array( 'group_by' => 'MSG_message_type' ) ); |
|
394 | + $active_messages_grouped_by_message_type = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type')); |
|
395 | 395 | |
396 | 396 | //setup array of message type options |
397 | - foreach ( $active_messages_grouped_by_message_type as $active_message ) { |
|
398 | - if ( $active_message instanceof EE_Message ) { |
|
399 | - $message_type_options[ $active_message->message_type() ] = ucwords( $active_message->message_type_label() ); |
|
397 | + foreach ($active_messages_grouped_by_message_type as $active_message) { |
|
398 | + if ($active_message instanceof EE_Message) { |
|
399 | + $message_type_options[$active_message->message_type()] = ucwords($active_message->message_type_label()); |
|
400 | 400 | } |
401 | 401 | } |
402 | - return $this->get_admin_page()->get_message_types_select_input( $message_type_options ); |
|
402 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | |
@@ -409,21 +409,21 @@ discard block |
||
409 | 409 | */ |
410 | 410 | protected function _get_contexts_for_message_types_dropdown_filter() { |
411 | 411 | $context_options = array(); |
412 | - $active_messages_grouped_by_context = EEM_Message::instance()->get_all( array( 'group_by' => 'MSG_context' ) ); |
|
412 | + $active_messages_grouped_by_context = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context')); |
|
413 | 413 | |
414 | 414 | //setup array of context options |
415 | - foreach ( $active_messages_grouped_by_context as $active_message ) { |
|
416 | - if ( $active_message instanceof EE_Message ) { |
|
415 | + foreach ($active_messages_grouped_by_context as $active_message) { |
|
416 | + if ($active_message instanceof EE_Message) { |
|
417 | 417 | $message_type = $active_message->message_type_object(); |
418 | - if ( $message_type instanceof EE_message_type ) { |
|
419 | - foreach ( $message_type->get_contexts() as $context => $context_details ) { |
|
420 | - if ( isset( $context_details['label'] ) ) { |
|
421 | - $context_options[ $context ] = $context_details['label']; |
|
418 | + if ($message_type instanceof EE_message_type) { |
|
419 | + foreach ($message_type->get_contexts() as $context => $context_details) { |
|
420 | + if (isset($context_details['label'])) { |
|
421 | + $context_options[$context] = $context_details['label']; |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | } |
425 | 425 | } |
426 | 426 | } |
427 | - return $this->get_admin_page()->get_contexts_for_message_types_select_input( $context_options ); |
|
427 | + return $this->get_admin_page()->get_contexts_for_message_types_select_input($context_options); |
|
428 | 428 | } |
429 | 429 | } //end EE_Message_List_Table class |
430 | 430 | \ No newline at end of file |
@@ -27,14 +27,14 @@ discard block |
||
27 | 27 | * @throws EE_Error |
28 | 28 | * @access protected |
29 | 29 | */ |
30 | - public function __construct( $data = array() ) { |
|
30 | + public function __construct($data = array()) { |
|
31 | 31 | |
32 | 32 | //validate that the first element in the array is an EE_Attendee object. Note that the array may be indexed by REG_ID so we will just shift off the first element. |
33 | - $ctc_chk = reset( $data ); |
|
34 | - if ( ! $ctc_chk instanceof EE_Attendee ) |
|
35 | - throw new EE_Error(__('The EE_Message_Contacts_incoming_data class expects an array of EE_Attendee objects.', 'event_espresso') ); |
|
33 | + $ctc_chk = reset($data); |
|
34 | + if ( ! $ctc_chk instanceof EE_Attendee) |
|
35 | + throw new EE_Error(__('The EE_Message_Contacts_incoming_data class expects an array of EE_Attendee objects.', 'event_espresso')); |
|
36 | 36 | |
37 | - parent::__construct( $data ); |
|
37 | + parent::__construct($data); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | * @param array $attendees |
44 | 44 | * @return array |
45 | 45 | */ |
46 | - public static function convert_data_for_persistent_storage( $attendees ) { |
|
46 | + public static function convert_data_for_persistent_storage($attendees) { |
|
47 | 47 | $attendee_ids = array_filter( |
48 | 48 | array_map( |
49 | - function( $attendee ) { |
|
50 | - if ( $attendee instanceof EE_Attendee ) { |
|
49 | + function($attendee) { |
|
50 | + if ($attendee instanceof EE_Attendee) { |
|
51 | 51 | return $attendee->ID(); |
52 | 52 | } |
53 | 53 | return false; |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | * @param array $attendee_ids |
67 | 67 | * @return EE_Attendee[] |
68 | 68 | */ |
69 | - public static function convert_data_from_persistent_storage( $attendee_ids ) { |
|
69 | + public static function convert_data_from_persistent_storage($attendee_ids) { |
|
70 | 70 | $attendee_ids = (array) $attendee_ids; |
71 | 71 | $attendees = EEM_Attendee::instance()->get_all( |
72 | 72 | array( |
73 | - array( 'ATT_ID' => array( 'IN', $attendee_ids ) ) |
|
73 | + array('ATT_ID' => array('IN', $attendee_ids)) |
|
74 | 74 | ) |
75 | 75 | ); |
76 | 76 | return $attendees; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $this->payment = NULL; |
100 | 100 | $this->billing = array(); |
101 | 101 | $this->reg_objs = array(); |
102 | - $this->attendees = $this->events = $this->tickets = $this->datetimes = $this->questions = $this->answer = $this->registrations = array(); |
|
102 | + $this->attendees = $this->events = $this->tickets = $this->datetimes = $this->questions = $this->answer = $this->registrations = array(); |
|
103 | 103 | $this->total_ticket_count = 0; |
104 | 104 | $this->primary_attendee_data = array( |
105 | 105 | 'registration_id' => 0, |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | 'primary_reg_obj' => NULL |
110 | 110 | ); |
111 | 111 | |
112 | - foreach ( $this->_data as $contact ) { |
|
112 | + foreach ($this->_data as $contact) { |
|
113 | 113 | $id = $contact->ID(); |
114 | 114 | $reg = $contact->get_first_related('Registration'); |
115 | 115 | $this->attendees[$id]['att_obj'] = $contact; |
@@ -5,7 +5,9 @@ discard block |
||
5 | 5 | * @subpackage helpers |
6 | 6 | * @since 4.3.0 |
7 | 7 | */ |
8 | -if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
8 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
9 | + exit('No direct script access allowed'); |
|
10 | +} |
|
9 | 11 | |
10 | 12 | /** |
11 | 13 | * This prepares data for message types that send messages for multiple contacts and handles |
@@ -31,8 +33,9 @@ discard block |
||
31 | 33 | |
32 | 34 | //validate that the first element in the array is an EE_Attendee object. Note that the array may be indexed by REG_ID so we will just shift off the first element. |
33 | 35 | $ctc_chk = reset( $data ); |
34 | - if ( ! $ctc_chk instanceof EE_Attendee ) |
|
35 | - throw new EE_Error(__('The EE_Message_Contacts_incoming_data class expects an array of EE_Attendee objects.', 'event_espresso') ); |
|
36 | + if ( ! $ctc_chk instanceof EE_Attendee ) { |
|
37 | + throw new EE_Error(__('The EE_Message_Contacts_incoming_data class expects an array of EE_Attendee objects.', 'event_espresso') ); |
|
38 | + } |
|
36 | 39 | |
37 | 40 | parent::__construct( $data ); |
38 | 41 | } |