@@ -144,7 +144,7 @@ |
||
144 | 144 | * |
145 | 145 | * @since 1.0.0 |
146 | 146 | * |
147 | - * @return WordPoints_Hook_Reaction_Validator|null The validator or null if none. |
|
147 | + * @return WordPoints_Hook_Reaction_Validator The validator or null if none. |
|
148 | 148 | */ |
149 | 149 | public function get_validator() { |
150 | 150 | return $this->validator; |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @param WordPoints_Class_Registry_Persistent $reactors The reactors registry. |
35 | 35 | */ |
36 | -function wordpoints_hook_reactors_init( $reactors ) { |
|
36 | +function wordpoints_hook_reactors_init($reactors) { |
|
37 | 37 | |
38 | - $reactors->register( 'points', 'WordPoints_Hook_Reactor_Points' ); |
|
38 | + $reactors->register('points', 'WordPoints_Hook_Reactor_Points'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param WordPoints_Class_Registry_Children $reaction_stores The store registry. |
49 | 49 | */ |
50 | -function wordpoints_hook_reaction_stores_init( $reaction_stores ) { |
|
50 | +function wordpoints_hook_reaction_stores_init($reaction_stores) { |
|
51 | 51 | |
52 | 52 | $reaction_stores->register( |
53 | 53 | 'points' |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | , 'WordPoints_Hook_Reaction_Store_Options' |
56 | 56 | ); |
57 | 57 | |
58 | - if ( is_wordpoints_network_active() ) { |
|
58 | + if (is_wordpoints_network_active()) { |
|
59 | 59 | $reaction_stores->register( |
60 | 60 | 'points' |
61 | 61 | , 'network' |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @param WordPoints_Class_Registry_Persistent $extensions The extension registry. |
75 | 75 | */ |
76 | -function wordpoints_hook_extension_init( $extensions ) { |
|
76 | +function wordpoints_hook_extension_init($extensions) { |
|
77 | 77 | |
78 | - $extensions->register( 'blocker', 'WordPoints_Hook_Extension_Blocker' ); |
|
79 | - $extensions->register( 'conditions', 'WordPoints_Hook_Extension_Conditions' ); |
|
80 | - $extensions->register( 'periods', 'WordPoints_Hook_Extension_Periods' ); |
|
78 | + $extensions->register('blocker', 'WordPoints_Hook_Extension_Blocker'); |
|
79 | + $extensions->register('conditions', 'WordPoints_Hook_Extension_Conditions'); |
|
80 | + $extensions->register('periods', 'WordPoints_Hook_Extension_Periods'); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @param WordPoints_Class_Registry_Children $conditions The conditions registry. |
91 | 91 | */ |
92 | -function wordpoints_hook_conditions_init( $conditions ) { |
|
92 | +function wordpoints_hook_conditions_init($conditions) { |
|
93 | 93 | |
94 | 94 | $conditions->register( |
95 | 95 | 'text' |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @param WordPoints_Hook_Actions $actions The action registry. |
127 | 127 | */ |
128 | -function wordpoints_hook_actions_init( $actions ) { |
|
128 | +function wordpoints_hook_actions_init($actions) { |
|
129 | 129 | |
130 | 130 | $actions->register( |
131 | 131 | 'comment_approve' |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | , array( |
134 | 134 | 'action' => 'transition_comment_status', |
135 | 135 | 'data' => array( |
136 | - 'arg_index' => array( 'comment' => 2 ), |
|
137 | - 'requirements' => array( 0 => 'approved' ), |
|
136 | + 'arg_index' => array('comment' => 2), |
|
137 | + 'requirements' => array(0 => 'approved'), |
|
138 | 138 | ), |
139 | 139 | ) |
140 | 140 | ); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | , array( |
146 | 146 | 'action' => 'wp_insert_comment', |
147 | 147 | 'data' => array( |
148 | - 'arg_index' => array( 'comment' => 1 ), |
|
148 | + 'arg_index' => array('comment' => 1), |
|
149 | 149 | ), |
150 | 150 | ) |
151 | 151 | ); |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | , array( |
157 | 157 | 'action' => 'transition_comment_status', |
158 | 158 | 'data' => array( |
159 | - 'arg_index' => array( 'comment' => 2 ), |
|
160 | - 'requirements' => array( 1 => 'approved' ), |
|
159 | + 'arg_index' => array('comment' => 2), |
|
160 | + 'requirements' => array(1 => 'approved'), |
|
161 | 161 | ), |
162 | 162 | ) |
163 | 163 | ); |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | , array( |
170 | 170 | 'action' => 'transition_post_status', |
171 | 171 | 'data' => array( |
172 | - 'arg_index' => array( 'post' => 2 ), |
|
173 | - 'requirements' => array( 0 => 'publish' ), |
|
172 | + 'arg_index' => array('post' => 2), |
|
173 | + 'requirements' => array(0 => 'publish'), |
|
174 | 174 | ), |
175 | 175 | ) |
176 | 176 | ); |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | , array( |
182 | 182 | 'action' => 'transition_post_status', |
183 | 183 | 'data' => array( |
184 | - 'arg_index' => array( 'post' => 2 ), |
|
185 | - 'requirements' => array( 1 => 'publish' ), |
|
184 | + 'arg_index' => array('post' => 2), |
|
185 | + 'requirements' => array(1 => 'publish'), |
|
186 | 186 | ), |
187 | 187 | ) |
188 | 188 | ); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | , array( |
194 | 194 | 'action' => 'add_attachment', |
195 | 195 | 'data' => array( |
196 | - 'arg_index' => array( 'post\attachment' => 0 ), |
|
196 | + 'arg_index' => array('post\attachment' => 0), |
|
197 | 197 | ), |
198 | 198 | ) |
199 | 199 | ); |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | , array( |
205 | 205 | 'action' => 'delete_post', |
206 | 206 | 'data' => array( |
207 | - 'arg_index' => array( 'post' => 0 ), |
|
207 | + 'arg_index' => array('post' => 0), |
|
208 | 208 | ), |
209 | 209 | ) |
210 | 210 | ); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | , array( |
216 | 216 | 'action' => 'user_register', |
217 | 217 | 'data' => array( |
218 | - 'arg_index' => array( 'user' => 0 ), |
|
218 | + 'arg_index' => array('user' => 0), |
|
219 | 219 | ), |
220 | 220 | ) |
221 | 221 | ); |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | , array( |
227 | 227 | 'action' => is_multisite() ? 'wpmu_delete_user' : 'delete_user', |
228 | 228 | 'data' => array( |
229 | - 'arg_index' => array( 'user' => 0 ), |
|
229 | + 'arg_index' => array('user' => 0), |
|
230 | 230 | ), |
231 | 231 | ) |
232 | 232 | ); |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @param WordPoints_Hook_Events $events The event registry. |
251 | 251 | */ |
252 | -function wordpoints_hook_events_init( $events ) { |
|
252 | +function wordpoints_hook_events_init($events) { |
|
253 | 253 | |
254 | 254 | $events->register( |
255 | 255 | 'user_register' |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | ); |
280 | 280 | |
281 | 281 | // Register events for all of the public post types. |
282 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
282 | + $post_types = get_post_types(array('public' => true)); |
|
283 | 283 | |
284 | 284 | /** |
285 | 285 | * Filter which post types to register hook events for. |
@@ -288,20 +288,20 @@ discard block |
||
288 | 288 | * |
289 | 289 | * @param string[] The post type slugs ("names"). |
290 | 290 | */ |
291 | - $post_types = apply_filters( 'wordpoints_register_hook_events_for_post_types', $post_types ); |
|
291 | + $post_types = apply_filters('wordpoints_register_hook_events_for_post_types', $post_types); |
|
292 | 292 | |
293 | - foreach ( $post_types as $slug ) { |
|
294 | - wordpoints_register_post_type_hook_events( $slug ); |
|
293 | + foreach ($post_types as $slug) { |
|
294 | + wordpoints_register_post_type_hook_events($slug); |
|
295 | 295 | } |
296 | 296 | |
297 | - if ( is_multisite() ) { |
|
297 | + if (is_multisite()) { |
|
298 | 298 | |
299 | 299 | $event_slugs = array( |
300 | 300 | 'user_visit', |
301 | 301 | 'user_register', |
302 | 302 | ); |
303 | 303 | |
304 | - foreach ( $event_slugs as $event_slug ) { |
|
304 | + foreach ($event_slugs as $event_slug) { |
|
305 | 305 | // TODO network hooks |
306 | 306 | $events->args->register( |
307 | 307 | $event_slug |
@@ -321,10 +321,10 @@ discard block |
||
321 | 321 | * |
322 | 322 | * @param WordPoints_App_Registry $entities The entities app. |
323 | 323 | */ |
324 | -function wordpoints_entities_app_init( $entities ) { |
|
324 | +function wordpoints_entities_app_init($entities) { |
|
325 | 325 | |
326 | - $entities->sub_apps->register( 'children', 'WordPoints_Class_Registry_Children' ); |
|
327 | - $entities->sub_apps->register( 'contexts', 'WordPoints_Class_Registry' ); |
|
326 | + $entities->sub_apps->register('children', 'WordPoints_Class_Registry_Children'); |
|
327 | + $entities->sub_apps->register('contexts', 'WordPoints_Class_Registry'); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -336,10 +336,10 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @param WordPoints_Class_Registry $contexts The entity context registry. |
338 | 338 | */ |
339 | -function wordpoints_entity_contexts_init( $contexts ) { |
|
339 | +function wordpoints_entity_contexts_init($contexts) { |
|
340 | 340 | |
341 | - $contexts->register( 'network', 'WordPoints_Entity_Context_Network' ); |
|
342 | - $contexts->register( 'site', 'WordPoints_Entity_Context_Site' ); |
|
341 | + $contexts->register('network', 'WordPoints_Entity_Context_Network'); |
|
342 | + $contexts->register('site', 'WordPoints_Entity_Context_Site'); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -351,18 +351,18 @@ discard block |
||
351 | 351 | * |
352 | 352 | * @param WordPoints_App_Registry $entities The entities app. |
353 | 353 | */ |
354 | -function wordpoints_entities_init( $entities ) { |
|
354 | +function wordpoints_entities_init($entities) { |
|
355 | 355 | |
356 | 356 | $children = $entities->children; |
357 | 357 | |
358 | - $entities->register( 'user', 'WordPoints_Entity_User' ); |
|
359 | - $children->register( 'user', 'roles', 'WordPoints_Entity_User_Roles' ); |
|
358 | + $entities->register('user', 'WordPoints_Entity_User'); |
|
359 | + $children->register('user', 'roles', 'WordPoints_Entity_User_Roles'); |
|
360 | 360 | |
361 | - $entities->register( 'user_role', 'WordPoints_Entity_User_Role' ); |
|
362 | - $children->register( 'user_role', 'name', 'WordPoints_Entity_User_Role_Name' ); |
|
361 | + $entities->register('user_role', 'WordPoints_Entity_User_Role'); |
|
362 | + $children->register('user_role', 'name', 'WordPoints_Entity_User_Role_Name'); |
|
363 | 363 | |
364 | 364 | // Register entities for all of the public post types. |
365 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
365 | + $post_types = get_post_types(array('public' => true)); |
|
366 | 366 | |
367 | 367 | /** |
368 | 368 | * Filter which post types to register entities for. |
@@ -371,14 +371,14 @@ discard block |
||
371 | 371 | * |
372 | 372 | * @param string[] The post type slugs ("names"). |
373 | 373 | */ |
374 | - $post_types = apply_filters( 'wordpoints_register_entities_for_post_types', $post_types ); |
|
374 | + $post_types = apply_filters('wordpoints_register_entities_for_post_types', $post_types); |
|
375 | 375 | |
376 | - foreach ( $post_types as $slug ) { |
|
377 | - wordpoints_register_post_type_entities( $slug ); |
|
376 | + foreach ($post_types as $slug) { |
|
377 | + wordpoints_register_post_type_entities($slug); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | // Register entities for all of the public taxonomies. |
381 | - $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
381 | + $taxonomies = get_taxonomies(array('public' => true)); |
|
382 | 382 | |
383 | 383 | /** |
384 | 384 | * Filter which taxonomies to register entities for. |
@@ -387,10 +387,10 @@ discard block |
||
387 | 387 | * |
388 | 388 | * @param string[] The taxonomy slugs. |
389 | 389 | */ |
390 | - $taxonomies = apply_filters( 'wordpoints_register_entities_for_taxonomies', $taxonomies ); |
|
390 | + $taxonomies = apply_filters('wordpoints_register_entities_for_taxonomies', $taxonomies); |
|
391 | 391 | |
392 | - foreach ( $taxonomies as $slug ) { |
|
393 | - wordpoints_register_taxonomy_entities( $slug ); |
|
392 | + foreach ($taxonomies as $slug) { |
|
393 | + wordpoints_register_taxonomy_entities($slug); |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
@@ -401,28 +401,28 @@ discard block |
||
401 | 401 | * |
402 | 402 | * @param string $slug The slug of the post type. |
403 | 403 | */ |
404 | -function wordpoints_register_post_type_entities( $slug ) { |
|
404 | +function wordpoints_register_post_type_entities($slug) { |
|
405 | 405 | |
406 | 406 | $entities = wordpoints_entities(); |
407 | 407 | $children = $entities->children; |
408 | 408 | |
409 | - $entities->register( "post\\{$slug}", 'WordPoints_Entity_Post' ); |
|
410 | - $children->register( "post\\{$slug}", 'author', 'WordPoints_Entity_Post_Author' ); |
|
409 | + $entities->register("post\\{$slug}", 'WordPoints_Entity_Post'); |
|
410 | + $children->register("post\\{$slug}", 'author', 'WordPoints_Entity_Post_Author'); |
|
411 | 411 | |
412 | - $supports = get_all_post_type_supports( $slug ); |
|
412 | + $supports = get_all_post_type_supports($slug); |
|
413 | 413 | |
414 | - if ( isset( $supports['editor'] ) ) { |
|
415 | - $children->register( "post\\{$slug}", 'content', 'WordPoints_Entity_Post_Content' ); |
|
414 | + if (isset($supports['editor'])) { |
|
415 | + $children->register("post\\{$slug}", 'content', 'WordPoints_Entity_Post_Content'); |
|
416 | 416 | } |
417 | 417 | |
418 | - if ( isset( $supports['comments'] ) ) { |
|
419 | - $entities->register( "comment\\{$slug}", 'WordPoints_Entity_Comment' ); |
|
420 | - $children->register( "comment\\{$slug}", "post\\{$slug}", 'WordPoints_Entity_Comment_Post' ); |
|
421 | - $children->register( "comment\\{$slug}", 'author', 'WordPoints_Entity_Comment_Author' ); |
|
418 | + if (isset($supports['comments'])) { |
|
419 | + $entities->register("comment\\{$slug}", 'WordPoints_Entity_Comment'); |
|
420 | + $children->register("comment\\{$slug}", "post\\{$slug}", 'WordPoints_Entity_Comment_Post'); |
|
421 | + $children->register("comment\\{$slug}", 'author', 'WordPoints_Entity_Comment_Author'); |
|
422 | 422 | } |
423 | 423 | |
424 | - foreach ( get_object_taxonomies( $slug ) as $taxonomy_slug ) { |
|
425 | - $children->register( "post\\{$slug}", "terms\\{$taxonomy_slug}", 'WordPoints_Entity_Post_Terms' ); |
|
424 | + foreach (get_object_taxonomies($slug) as $taxonomy_slug) { |
|
425 | + $children->register("post\\{$slug}", "terms\\{$taxonomy_slug}", 'WordPoints_Entity_Post_Terms'); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * |
433 | 433 | * @param string $slug The slug ("name") of the post type. |
434 | 434 | */ |
435 | - do_action( 'wordpoints_register_post_type_entities', $slug ); |
|
435 | + do_action('wordpoints_register_post_type_entities', $slug); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -442,13 +442,13 @@ discard block |
||
442 | 442 | * |
443 | 443 | * @param string $slug The slug of the post type. |
444 | 444 | */ |
445 | -function wordpoints_register_post_type_hook_events( $slug ) { |
|
445 | +function wordpoints_register_post_type_hook_events($slug) { |
|
446 | 446 | |
447 | 447 | $event_slugs = array(); |
448 | 448 | |
449 | 449 | $events = wordpoints_hooks()->events; |
450 | 450 | |
451 | - if ( 'attachment' === $slug ) { |
|
451 | + if ('attachment' === $slug) { |
|
452 | 452 | |
453 | 453 | $event_slugs[] = 'media_upload'; |
454 | 454 | |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | , array( |
477 | 477 | 'actions' => array( |
478 | 478 | 'fire' => 'post_publish', |
479 | - 'reverse' => array( 'post_depublish', 'post_delete' ), |
|
479 | + 'reverse' => array('post_depublish', 'post_delete'), |
|
480 | 480 | ), |
481 | 481 | 'args' => array( |
482 | 482 | "post\\{$slug}" => 'WordPoints_Hook_Arg_Dynamic', |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | ); |
486 | 486 | } |
487 | 487 | |
488 | - if ( post_type_supports( $slug, 'comments' ) ) { |
|
488 | + if (post_type_supports($slug, 'comments')) { |
|
489 | 489 | |
490 | 490 | $event_slugs[] = "comment_leave\\{$slug}"; |
491 | 491 | |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | , 'WordPoints_Hook_Event_Comment_Leave' |
495 | 495 | , array( |
496 | 496 | 'actions' => array( |
497 | - 'fire' => array( 'comment_approve', 'comment_new' ), |
|
497 | + 'fire' => array('comment_approve', 'comment_new'), |
|
498 | 498 | 'reverse' => 'comment_deapprove', |
499 | 499 | ), |
500 | 500 | 'args' => array( |
@@ -504,8 +504,8 @@ discard block |
||
504 | 504 | ); |
505 | 505 | } |
506 | 506 | |
507 | - if ( is_multisite() ) { |
|
508 | - foreach ( $event_slugs as $event_slug ) { |
|
507 | + if (is_multisite()) { |
|
508 | + foreach ($event_slugs as $event_slug) { |
|
509 | 509 | $events->args->register( |
510 | 510 | $event_slug |
511 | 511 | , 'current:site' |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | * |
522 | 522 | * @param string $slug The slug ("name") of the post type. |
523 | 523 | */ |
524 | - do_action( 'wordpoints_register_post_type_hook_events', $slug ); |
|
524 | + do_action('wordpoints_register_post_type_hook_events', $slug); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -531,13 +531,13 @@ discard block |
||
531 | 531 | * |
532 | 532 | * @param string $slug The slug of the taxonomy. |
533 | 533 | */ |
534 | -function wordpoints_register_taxonomy_entities( $slug ) { |
|
534 | +function wordpoints_register_taxonomy_entities($slug) { |
|
535 | 535 | |
536 | 536 | $entities = wordpoints_entities(); |
537 | 537 | $children = $entities->children; |
538 | 538 | |
539 | - $entities->register( "term\\{$slug}", 'WordPoints_Entity_Term' ); |
|
540 | - $children->register( "term\\{$slug}", 'id', 'WordPoints_Entity_Term_Id' ); |
|
539 | + $entities->register("term\\{$slug}", 'WordPoints_Entity_Term'); |
|
540 | + $children->register("term\\{$slug}", 'id', 'WordPoints_Entity_Term_Id'); |
|
541 | 541 | |
542 | 542 | /** |
543 | 543 | * Fired when registering the entities for a taxonomy. |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | * |
547 | 547 | * @param string $slug The taxonomy's slug. |
548 | 548 | */ |
549 | - do_action( 'wordpoints_register_taxonomy_entities', $slug ); |
|
549 | + do_action('wordpoints_register_taxonomy_entities', $slug); |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
@@ -558,10 +558,10 @@ discard block |
||
558 | 558 | * |
559 | 559 | * @param WordPoints_Class_RegistryI $data_types The data types registry. |
560 | 560 | */ |
561 | -function wordpoints_data_types_init( $data_types ) { |
|
561 | +function wordpoints_data_types_init($data_types) { |
|
562 | 562 | |
563 | - $data_types->register( 'integer', 'WordPoints_Data_Type_Integer' ); |
|
564 | - $data_types->register( 'text', 'WordPoints_Data_Type_Text' ); |
|
563 | + $data_types->register('integer', 'WordPoints_Data_Type_Integer'); |
|
564 | + $data_types->register('text', 'WordPoints_Data_Type_Text'); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | * |
577 | 577 | * @return bool Whether the user can view the points log. |
578 | 578 | */ |
579 | -function wordpoints_hooks_user_can_view_points_log( $can_view, $log ) { |
|
579 | +function wordpoints_hooks_user_can_view_points_log($can_view, $log) { |
|
580 | 580 | |
581 | - if ( ! $can_view ) { |
|
581 | + if ( ! $can_view) { |
|
582 | 582 | return $can_view; |
583 | 583 | } |
584 | 584 | |
@@ -587,11 +587,11 @@ discard block |
||
587 | 587 | $event_slug = $log->log_type; |
588 | 588 | |
589 | 589 | /** @var WordPoints_Hook_Arg $arg */ |
590 | - foreach ( wordpoints_hooks()->events->args->get_children( $event_slug ) as $slug => $arg ) { |
|
590 | + foreach (wordpoints_hooks()->events->args->get_children($event_slug) as $slug => $arg) { |
|
591 | 591 | |
592 | - $value = wordpoints_get_points_log_meta( $log->id, $slug, true ); |
|
592 | + $value = wordpoints_get_points_log_meta($log->id, $slug, true); |
|
593 | 593 | |
594 | - if ( ! $value ) { |
|
594 | + if ( ! $value) { |
|
595 | 595 | continue; |
596 | 596 | } |
597 | 597 | |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | , $value |
602 | 602 | ); |
603 | 603 | |
604 | - if ( ! $can_view ) { |
|
604 | + if ( ! $can_view) { |
|
605 | 605 | break; |
606 | 606 | } |
607 | 607 | } |
@@ -620,20 +620,20 @@ discard block |
||
620 | 620 | * |
621 | 621 | * @return bool Whether the user can view this entity. |
622 | 622 | */ |
623 | -function wordpoints_entity_user_can_view( $user_id, $entity_slug, $entity_id ) { |
|
623 | +function wordpoints_entity_user_can_view($user_id, $entity_slug, $entity_id) { |
|
624 | 624 | |
625 | - $entity = wordpoints_entities()->get( $entity_slug ); |
|
625 | + $entity = wordpoints_entities()->get($entity_slug); |
|
626 | 626 | |
627 | 627 | // If this entity type is not found, we have no way of determining whether it is |
628 | 628 | // safe for the user to view it. |
629 | - if ( ! ( $entity instanceof WordPoints_Entity ) ) { |
|
629 | + if ( ! ($entity instanceof WordPoints_Entity)) { |
|
630 | 630 | return false; |
631 | 631 | } |
632 | 632 | |
633 | 633 | $can_view = true; |
634 | 634 | |
635 | - if ( $entity instanceof WordPoints_Entity_Restricted_VisibilityI ) { |
|
636 | - $can_view = $entity->user_can_view( $user_id, $entity_id ); |
|
635 | + if ($entity instanceof WordPoints_Entity_Restricted_VisibilityI) { |
|
636 | + $can_view = $entity->user_can_view($user_id, $entity_id); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -664,8 +664,8 @@ discard block |
||
664 | 664 | */ |
665 | 665 | function wordpoints_apps() { |
666 | 666 | |
667 | - if ( ! isset( WordPoints_App::$main ) ) { |
|
668 | - WordPoints_App::$main = new WordPoints_App( 'apps' ); |
|
667 | + if ( ! isset(WordPoints_App::$main)) { |
|
668 | + WordPoints_App::$main = new WordPoints_App('apps'); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | return WordPoints_App::$main; |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | */ |
681 | 681 | function wordpoints_hooks() { |
682 | 682 | |
683 | - if ( ! isset( WordPoints_App::$main ) ) { |
|
683 | + if ( ! isset(WordPoints_App::$main)) { |
|
684 | 684 | wordpoints_apps(); |
685 | 685 | } |
686 | 686 | |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | */ |
697 | 697 | function wordpoints_entities() { |
698 | 698 | |
699 | - if ( ! isset( WordPoints_App::$main ) ) { |
|
699 | + if ( ! isset(WordPoints_App::$main)) { |
|
700 | 700 | wordpoints_apps(); |
701 | 701 | } |
702 | 702 | |
@@ -712,13 +712,13 @@ discard block |
||
712 | 712 | * |
713 | 713 | * @param WordPoints_App $app The main apps app. |
714 | 714 | */ |
715 | -function wordpoints_apps_init( $app ) { |
|
715 | +function wordpoints_apps_init($app) { |
|
716 | 716 | |
717 | 717 | $apps = $app->sub_apps; |
718 | 718 | |
719 | - $apps->register( 'hooks', 'WordPoints_Hooks' ); |
|
720 | - $apps->register( 'entities', 'WordPoints_App_Registry' ); |
|
721 | - $apps->register( 'data_types', 'WordPoints_Class_Registry' ); |
|
719 | + $apps->register('hooks', 'WordPoints_Hooks'); |
|
720 | + $apps->register('entities', 'WordPoints_App_Registry'); |
|
721 | + $apps->register('data_types', 'WordPoints_Class_Registry'); |
|
722 | 722 | } |
723 | 723 | |
724 | 724 | /** |
@@ -731,19 +731,19 @@ discard block |
||
731 | 731 | * |
732 | 732 | * @return object|false The constructed object, or false if to many args were passed. |
733 | 733 | */ |
734 | -function wordpoints_construct_class_with_args( $class_name, array $args ) { |
|
734 | +function wordpoints_construct_class_with_args($class_name, array $args) { |
|
735 | 735 | |
736 | - switch ( count( $args ) ) { |
|
736 | + switch (count($args)) { |
|
737 | 737 | case 0: |
738 | 738 | return new $class_name(); |
739 | 739 | case 1: |
740 | - return new $class_name( $args[0] ); |
|
740 | + return new $class_name($args[0]); |
|
741 | 741 | case 2: |
742 | - return new $class_name( $args[0], $args[1] ); |
|
742 | + return new $class_name($args[0], $args[1]); |
|
743 | 743 | case 3: |
744 | - return new $class_name( $args[0], $args[1], $args[2] ); |
|
744 | + return new $class_name($args[0], $args[1], $args[2]); |
|
745 | 745 | case 4: |
746 | - return new $class_name( $args[0], $args[1], $args[2], $args[3] ); |
|
746 | + return new $class_name($args[0], $args[1], $args[2], $args[3]); |
|
747 | 747 | default: |
748 | 748 | return false; |
749 | 749 | } |
@@ -765,13 +765,13 @@ discard block |
||
765 | 765 | * @return array The slug parsed into the 'generic' and 'dynamic' portions. If the |
766 | 766 | * slug is not dynamic, the value of each of those keys will be false. |
767 | 767 | */ |
768 | -function wordpoints_parse_dynamic_slug( $slug ) { |
|
768 | +function wordpoints_parse_dynamic_slug($slug) { |
|
769 | 769 | |
770 | - $parsed = array( 'dynamic' => false, 'generic' => false ); |
|
770 | + $parsed = array('dynamic' => false, 'generic' => false); |
|
771 | 771 | |
772 | - $parts = explode( '\\', $slug, 2 ); |
|
772 | + $parts = explode('\\', $slug, 2); |
|
773 | 773 | |
774 | - if ( isset( $parts[1] ) ) { |
|
774 | + if (isset($parts[1])) { |
|
775 | 775 | $parsed['dynamic'] = $parts[1]; |
776 | 776 | $parsed['generic'] = $parts[0]; |
777 | 777 | } |
@@ -810,28 +810,28 @@ discard block |
||
810 | 810 | * contexts, indexed by context slug, or false if any of the |
811 | 811 | * contexts isn't current. |
812 | 812 | */ |
813 | -function wordpoints_entities_get_current_context_id( $slug ) { |
|
813 | +function wordpoints_entities_get_current_context_id($slug) { |
|
814 | 814 | |
815 | 815 | $current_context = array(); |
816 | 816 | |
817 | 817 | /** @var WordPoints_Class_Registry $contexts */ |
818 | 818 | $contexts = wordpoints_entities()->contexts; |
819 | 819 | |
820 | - while ( $slug ) { |
|
820 | + while ($slug) { |
|
821 | 821 | |
822 | - $context = $contexts->get( $slug ); |
|
822 | + $context = $contexts->get($slug); |
|
823 | 823 | |
824 | - if ( ! $context instanceof WordPoints_Entity_Context ) { |
|
824 | + if ( ! $context instanceof WordPoints_Entity_Context) { |
|
825 | 825 | return false; |
826 | 826 | } |
827 | 827 | |
828 | 828 | $id = $context->get_current_id(); |
829 | 829 | |
830 | - if ( false === $id ) { |
|
830 | + if (false === $id) { |
|
831 | 831 | return false; |
832 | 832 | } |
833 | 833 | |
834 | - $current_context[ $slug ] = $id; |
|
834 | + $current_context[$slug] = $id; |
|
835 | 835 | |
836 | 836 | $slug = $context->get_parent_slug(); |
837 | 837 | } |
@@ -852,22 +852,22 @@ discard block |
||
852 | 852 | */ |
853 | 853 | function wordpoints_is_network_context() { |
854 | 854 | |
855 | - if ( ! is_multisite() ) { |
|
855 | + if ( ! is_multisite()) { |
|
856 | 856 | return false; |
857 | 857 | } |
858 | 858 | |
859 | - if ( is_network_admin() ) { |
|
859 | + if (is_network_admin()) { |
|
860 | 860 | return true; |
861 | 861 | } |
862 | 862 | |
863 | 863 | // See https://core.trac.wordpress.org/ticket/22589 |
864 | 864 | if ( |
865 | - defined( 'DOING_AJAX' ) |
|
865 | + defined('DOING_AJAX') |
|
866 | 866 | && DOING_AJAX |
867 | - && isset( $_SERVER['HTTP_REFERER'] ) |
|
867 | + && isset($_SERVER['HTTP_REFERER']) |
|
868 | 868 | && preg_match( |
869 | - '#^' . preg_quote( network_admin_url(), '#' ) . '#i' |
|
870 | - , esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) |
|
869 | + '#^'.preg_quote(network_admin_url(), '#').'#i' |
|
870 | + , esc_url_raw(wp_unslash($_SERVER['HTTP_REFERER'])) |
|
871 | 871 | ) |
872 | 872 | ) { |
873 | 873 | return true; |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | * |
881 | 881 | * @param bool $in_network_context Whether we are in network context. |
882 | 882 | */ |
883 | - return apply_filters( 'wordpoints_is_network_context', false ); |
|
883 | + return apply_filters('wordpoints_is_network_context', false); |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | /** |
@@ -894,21 +894,21 @@ discard block |
||
894 | 894 | * |
895 | 895 | * @return string The primary arg's GUID, JSON encoded. |
896 | 896 | */ |
897 | -function wordpoints_hooks_get_event_primary_arg_guid_json( WordPoints_Hook_Event_Args $event_args ) { |
|
897 | +function wordpoints_hooks_get_event_primary_arg_guid_json(WordPoints_Hook_Event_Args $event_args) { |
|
898 | 898 | |
899 | 899 | $entity = $event_args->get_primary_arg(); |
900 | 900 | |
901 | - if ( ! $entity ) { |
|
901 | + if ( ! $entity) { |
|
902 | 902 | return ''; |
903 | 903 | } |
904 | 904 | |
905 | 905 | $the_guid = $entity->get_the_guid(); |
906 | 906 | |
907 | - if ( ! $the_guid ) { |
|
907 | + if ( ! $the_guid) { |
|
908 | 908 | return ''; |
909 | 909 | } |
910 | 910 | |
911 | - return wp_json_encode( $the_guid ); |
|
911 | + return wp_json_encode($the_guid); |
|
912 | 912 | } |
913 | 913 | |
914 | 914 | /** |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | */ |
922 | 922 | function wordpoints_hooks_api_add_global_cache_groups() { |
923 | 923 | |
924 | - if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
|
924 | + if (function_exists('wp_cache_add_global_groups')) { |
|
925 | 925 | |
926 | 926 | wp_cache_add_global_groups( |
927 | 927 | array( |
@@ -947,8 +947,8 @@ discard block |
||
947 | 947 | * @return string The escaped identifier. Already quoted, do not place within |
948 | 948 | * backticks. |
949 | 949 | */ |
950 | -function wordpoints_escape_mysql_identifier( $identifier ) { |
|
951 | - return '`' . str_replace( '`', '``', $identifier ) . '`'; |
|
950 | +function wordpoints_escape_mysql_identifier($identifier) { |
|
951 | + return '`'.str_replace('`', '``', $identifier).'`'; |
|
952 | 952 | } |
953 | 953 | |
954 | 954 | // EOF |
@@ -24,15 +24,15 @@ |
||
24 | 24 | /** |
25 | 25 | * @since 1.0.0 |
26 | 26 | */ |
27 | - public function validate_action_type_settings( $settings ) { |
|
27 | + public function validate_action_type_settings($settings) { |
|
28 | 28 | return (bool) $settings; |
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @since 1.0.0 |
33 | 33 | */ |
34 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
35 | - return ! $this->get_settings_from_fire( $fire ); |
|
34 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
35 | + return ! $this->get_settings_from_fire($fire); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 |
@@ -25,11 +25,11 @@ discard block |
||
25 | 25 | public function get_ui_script_data() { |
26 | 26 | |
27 | 27 | $periods = array( |
28 | - MINUTE_IN_SECONDS => __( 'Minute', 'wordpoints' ), |
|
29 | - HOUR_IN_SECONDS => __( 'Hour', 'wordpoints' ), |
|
30 | - DAY_IN_SECONDS => __( 'Day', 'wordpoints' ), |
|
31 | - WEEK_IN_SECONDS => __( 'Week', 'wordpoints' ), |
|
32 | - 30 * DAY_IN_SECONDS => __( 'Month', 'wordpoints' ), |
|
28 | + MINUTE_IN_SECONDS => __('Minute', 'wordpoints'), |
|
29 | + HOUR_IN_SECONDS => __('Hour', 'wordpoints'), |
|
30 | + DAY_IN_SECONDS => __('Day', 'wordpoints'), |
|
31 | + WEEK_IN_SECONDS => __('Week', 'wordpoints'), |
|
32 | + 30 * DAY_IN_SECONDS => __('Month', 'wordpoints'), |
|
33 | 33 | ); |
34 | 34 | |
35 | 35 | /** |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @param string[] $periods The period titles, indexed by length in seconds. |
41 | 41 | */ |
42 | - $periods = apply_filters( 'wordpoints_hooks_ui_data_periods', $periods ); |
|
42 | + $periods = apply_filters('wordpoints_hooks_ui_data_periods', $periods); |
|
43 | 43 | |
44 | 44 | return array( |
45 | 45 | 'periods' => $periods, |
46 | 46 | 'l10n' => array( |
47 | - 'label' => __( 'Trigger reaction no more than once per:', 'wordpoints' ), |
|
47 | + 'label' => __('Trigger reaction no more than once per:', 'wordpoints'), |
|
48 | 48 | ), |
49 | 49 | ); |
50 | 50 | } |
@@ -58,25 +58,25 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return array The validated periods. |
60 | 60 | */ |
61 | - protected function validate_action_type_settings( $periods ) { |
|
61 | + protected function validate_action_type_settings($periods) { |
|
62 | 62 | |
63 | - if ( ! is_array( $periods ) ) { |
|
63 | + if ( ! is_array($periods)) { |
|
64 | 64 | |
65 | 65 | $this->validator->add_error( |
66 | - __( 'Periods do not match expected format.', 'wordpoints' ) |
|
66 | + __('Periods do not match expected format.', 'wordpoints') |
|
67 | 67 | ); |
68 | 68 | |
69 | 69 | return array(); |
70 | 70 | } |
71 | 71 | |
72 | - foreach ( $periods as $index => $period ) { |
|
72 | + foreach ($periods as $index => $period) { |
|
73 | 73 | |
74 | - $this->validator->push_field( $index ); |
|
74 | + $this->validator->push_field($index); |
|
75 | 75 | |
76 | - $period = $this->validate_period( $period ); |
|
76 | + $period = $this->validate_period($period); |
|
77 | 77 | |
78 | - if ( $period ) { |
|
79 | - $periods[ $index ] = $period; |
|
78 | + if ($period) { |
|
79 | + $periods[$index] = $period; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $this->validator->pop_field(); |
@@ -94,30 +94,30 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return array|false The validated period, or false if invalid. |
96 | 96 | */ |
97 | - protected function validate_period( $period ) { |
|
97 | + protected function validate_period($period) { |
|
98 | 98 | |
99 | - if ( ! is_array( $period ) ) { |
|
99 | + if ( ! is_array($period)) { |
|
100 | 100 | $this->validator->add_error( |
101 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
101 | + __('Period does not match expected format.', 'wordpoints') |
|
102 | 102 | ); |
103 | 103 | |
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | |
107 | - if ( isset( $period['args'] ) ) { |
|
108 | - $this->validate_period_args( $period['args'] ); |
|
107 | + if (isset($period['args'])) { |
|
108 | + $this->validate_period_args($period['args']); |
|
109 | 109 | } |
110 | 110 | |
111 | - if ( ! isset( $period['length'] ) ) { |
|
111 | + if ( ! isset($period['length'])) { |
|
112 | 112 | |
113 | 113 | $this->validator->add_error( |
114 | - __( 'Period length setting is missing.', 'wordpoints' ) |
|
114 | + __('Period length setting is missing.', 'wordpoints') |
|
115 | 115 | ); |
116 | 116 | |
117 | - } elseif ( false === wordpoints_posint( $period['length'] ) ) { |
|
117 | + } elseif (false === wordpoints_posint($period['length'])) { |
|
118 | 118 | |
119 | 119 | $this->validator->add_error( |
120 | - __( 'Period length must be a positive integer.', 'wordpoints' ) |
|
120 | + __('Period length must be a positive integer.', 'wordpoints') |
|
121 | 121 | , 'length' |
122 | 122 | ); |
123 | 123 | |
@@ -134,34 +134,34 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param mixed $args The args the period is related to. |
136 | 136 | */ |
137 | - protected function validate_period_args( $args ) { |
|
137 | + protected function validate_period_args($args) { |
|
138 | 138 | |
139 | - if ( ! is_array( $args ) ) { |
|
139 | + if ( ! is_array($args)) { |
|
140 | 140 | |
141 | 141 | $this->validator->add_error( |
142 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
142 | + __('Period does not match expected format.', 'wordpoints') |
|
143 | 143 | , 'args' |
144 | 144 | ); |
145 | 145 | |
146 | 146 | return; |
147 | 147 | } |
148 | 148 | |
149 | - $this->validator->push_field( 'args' ); |
|
149 | + $this->validator->push_field('args'); |
|
150 | 150 | |
151 | - foreach ( $args as $index => $hierarchy ) { |
|
151 | + foreach ($args as $index => $hierarchy) { |
|
152 | 152 | |
153 | - $this->validator->push_field( $index ); |
|
153 | + $this->validator->push_field($index); |
|
154 | 154 | |
155 | - if ( ! is_array( $hierarchy ) ) { |
|
155 | + if ( ! is_array($hierarchy)) { |
|
156 | 156 | |
157 | 157 | $this->validator->add_error( |
158 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
158 | + __('Period does not match expected format.', 'wordpoints') |
|
159 | 159 | ); |
160 | 160 | |
161 | - } elseif ( ! $this->event_args->get_from_hierarchy( $hierarchy ) ) { |
|
161 | + } elseif ( ! $this->event_args->get_from_hierarchy($hierarchy)) { |
|
162 | 162 | |
163 | 163 | $this->validator->add_error( |
164 | - __( 'Invalid period.', 'wordpoints' ) // TODO better error message |
|
164 | + __('Invalid period.', 'wordpoints') // TODO better error message |
|
165 | 165 | ); |
166 | 166 | } |
167 | 167 | |
@@ -174,18 +174,18 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * @since 1.0.0 |
176 | 176 | */ |
177 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
177 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
178 | 178 | |
179 | - $periods = $this->get_settings_from_fire( $fire ); |
|
179 | + $periods = $this->get_settings_from_fire($fire); |
|
180 | 180 | |
181 | - if ( empty( $periods ) ) { |
|
181 | + if (empty($periods)) { |
|
182 | 182 | return true; |
183 | 183 | } |
184 | 184 | |
185 | 185 | $this->event_args = $fire->event_args; |
186 | 186 | |
187 | - foreach ( $periods as $period ) { |
|
188 | - if ( ! $this->has_period_ended( $period, $fire->reaction ) ) { |
|
187 | + foreach ($periods as $period) { |
|
188 | + if ( ! $this->has_period_ended($period, $fire->reaction)) { |
|
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | } |
@@ -209,24 +209,24 @@ discard block |
||
209 | 209 | ) { |
210 | 210 | |
211 | 211 | $period = $this->get_period_by_reaction( |
212 | - $this->get_period_signature( $settings, $reaction ) |
|
212 | + $this->get_period_signature($settings, $reaction) |
|
213 | 213 | , $reaction |
214 | 214 | ); |
215 | 215 | |
216 | 216 | // If the period isn't found, we know that we can still fire. |
217 | - if ( ! $period ) { |
|
217 | + if ( ! $period) { |
|
218 | 218 | return true; |
219 | 219 | } |
220 | 220 | |
221 | - $now = current_time( 'timestamp' ); |
|
222 | - $hit_time = strtotime( $period->date, $now ); |
|
221 | + $now = current_time('timestamp'); |
|
222 | + $hit_time = strtotime($period->date, $now); |
|
223 | 223 | |
224 | - if ( ! empty( $settings['relative'] ) ) { |
|
225 | - return ( $hit_time < $now - $settings['length'] ); |
|
224 | + if ( ! empty($settings['relative'])) { |
|
225 | + return ($hit_time < $now - $settings['length']); |
|
226 | 226 | } else { |
227 | 227 | return ( |
228 | - (int) ( $hit_time / $settings['length'] ) |
|
229 | - < (int) ( $now / $settings['length'] ) |
|
228 | + (int) ($hit_time / $settings['length']) |
|
229 | + < (int) ($now / $settings['length']) |
|
230 | 230 | ); |
231 | 231 | } |
232 | 232 | } |
@@ -240,24 +240,24 @@ discard block |
||
240 | 240 | * |
241 | 241 | * @return array The arg values. |
242 | 242 | */ |
243 | - protected function get_arg_values( array $period_args ) { |
|
243 | + protected function get_arg_values(array $period_args) { |
|
244 | 244 | |
245 | 245 | $values = array(); |
246 | 246 | |
247 | - foreach ( $period_args as $arg_hierarchy ) { |
|
247 | + foreach ($period_args as $arg_hierarchy) { |
|
248 | 248 | |
249 | 249 | $arg = $this->event_args->get_from_hierarchy( |
250 | 250 | $arg_hierarchy |
251 | 251 | ); |
252 | 252 | |
253 | - if ( ! $arg instanceof WordPoints_EntityishI ) { |
|
253 | + if ( ! $arg instanceof WordPoints_EntityishI) { |
|
254 | 254 | continue; |
255 | 255 | } |
256 | 256 | |
257 | - $values[ implode( '.', $arg_hierarchy ) ] = $arg->get_the_value(); |
|
257 | + $values[implode('.', $arg_hierarchy)] = $arg->get_the_value(); |
|
258 | 258 | } |
259 | 259 | |
260 | - ksort( $values ); |
|
260 | + ksort($values); |
|
261 | 261 | |
262 | 262 | return $values; |
263 | 263 | } |
@@ -271,11 +271,11 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @return object|false The period data, or false if not found. |
273 | 273 | */ |
274 | - protected function get_period( $period_id ) { |
|
274 | + protected function get_period($period_id) { |
|
275 | 275 | |
276 | - $period = wp_cache_get( $period_id, 'wordpoints_hook_periods' ); |
|
276 | + $period = wp_cache_get($period_id, 'wordpoints_hook_periods'); |
|
277 | 277 | |
278 | - if ( ! $period ) { |
|
278 | + if ( ! $period) { |
|
279 | 279 | |
280 | 280 | global $wpdb; |
281 | 281 | |
@@ -292,11 +292,11 @@ discard block |
||
292 | 292 | ) |
293 | 293 | ); |
294 | 294 | |
295 | - if ( ! $period ) { |
|
295 | + if ( ! $period) { |
|
296 | 296 | return false; |
297 | 297 | } |
298 | 298 | |
299 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
299 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | return $period; |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | |
321 | 321 | $reaction_guid = $reaction->get_guid(); |
322 | 322 | |
323 | - $cache_key = wp_json_encode( $reaction_guid ) . "-{$signature}"; |
|
323 | + $cache_key = wp_json_encode($reaction_guid)."-{$signature}"; |
|
324 | 324 | |
325 | 325 | // Before we run the query, we try to lookup the ID in the cache. |
326 | - $period_id = wp_cache_get( $cache_key, 'wordpoints_hook_period_ids_by_reaction' ); |
|
326 | + $period_id = wp_cache_get($cache_key, 'wordpoints_hook_period_ids_by_reaction'); |
|
327 | 327 | |
328 | 328 | // If we found it, we can retrieve the period by ID instead. |
329 | - if ( $period_id ) { |
|
330 | - return $this->get_period( $period_id ); |
|
329 | + if ($period_id) { |
|
330 | + return $this->get_period($period_id); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | global $wpdb; |
@@ -351,17 +351,17 @@ discard block |
||
351 | 351 | , $signature |
352 | 352 | , $reaction_guid['reactor'] |
353 | 353 | , $reaction_guid['store'] |
354 | - , wp_json_encode( $reaction_guid['context_id'] ) |
|
354 | + , wp_json_encode($reaction_guid['context_id']) |
|
355 | 355 | , $reaction_guid['id'] |
356 | 356 | ) |
357 | 357 | ); |
358 | 358 | |
359 | - if ( ! $period ) { |
|
359 | + if ( ! $period) { |
|
360 | 360 | return false; |
361 | 361 | } |
362 | 362 | |
363 | - wp_cache_set( $cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction' ); |
|
364 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
363 | + wp_cache_set($cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction'); |
|
364 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
365 | 365 | |
366 | 366 | return $period; |
367 | 367 | } |
@@ -369,20 +369,20 @@ discard block |
||
369 | 369 | /** |
370 | 370 | * @since 1.0.0 |
371 | 371 | */ |
372 | - public function after_hit( WordPoints_Hook_Fire $fire ) { |
|
372 | + public function after_hit(WordPoints_Hook_Fire $fire) { |
|
373 | 373 | |
374 | - $periods = $this->get_settings_from_fire( $fire ); |
|
374 | + $periods = $this->get_settings_from_fire($fire); |
|
375 | 375 | |
376 | - if ( empty( $periods ) ) { |
|
376 | + if (empty($periods)) { |
|
377 | 377 | return; |
378 | 378 | } |
379 | 379 | |
380 | 380 | $this->event_args = $fire->event_args; |
381 | 381 | |
382 | - foreach ( $periods as $settings ) { |
|
382 | + foreach ($periods as $settings) { |
|
383 | 383 | |
384 | 384 | $this->add_period( |
385 | - $this->get_period_signature( $settings, $fire->reaction ) |
|
385 | + $this->get_period_signature($settings, $fire->reaction) |
|
386 | 386 | , $fire |
387 | 387 | ); |
388 | 388 | } |
@@ -407,14 +407,14 @@ discard block |
||
407 | 407 | WordPoints_Hook_ReactionI $reaction |
408 | 408 | ) { |
409 | 409 | |
410 | - if ( isset( $settings['args'] ) ) { |
|
410 | + if (isset($settings['args'])) { |
|
411 | 411 | $period_args = $settings['args']; |
412 | 412 | } else { |
413 | - $period_args = array( $reaction->get_meta( 'target' ) ); |
|
413 | + $period_args = array($reaction->get_meta('target')); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | return wordpoints_hash( |
417 | - wp_json_encode( $this->get_arg_values( $period_args ) ) |
|
417 | + wp_json_encode($this->get_arg_values($period_args)) |
|
418 | 418 | ); |
419 | 419 | } |
420 | 420 | |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * |
429 | 429 | * @return false|object The period data, or false if not found. |
430 | 430 | */ |
431 | - protected function add_period( $signature, WordPoints_Hook_Fire $fire ) { |
|
431 | + protected function add_period($signature, WordPoints_Hook_Fire $fire) { |
|
432 | 432 | |
433 | 433 | global $wpdb; |
434 | 434 | |
@@ -438,17 +438,17 @@ discard block |
||
438 | 438 | 'hit_id' => $fire->hit_id, |
439 | 439 | 'signature' => $signature, |
440 | 440 | ) |
441 | - , array( '%d', '%s' ) |
|
441 | + , array('%d', '%s') |
|
442 | 442 | ); |
443 | 443 | |
444 | - if ( ! $inserted ) { |
|
444 | + if ( ! $inserted) { |
|
445 | 445 | return false; |
446 | 446 | } |
447 | 447 | |
448 | 448 | $period_id = $wpdb->insert_id; |
449 | 449 | |
450 | 450 | wp_cache_set( |
451 | - wp_json_encode( $fire->reaction->get_guid() ) . "-{$signature}" |
|
451 | + wp_json_encode($fire->reaction->get_guid())."-{$signature}" |
|
452 | 452 | , $period_id |
453 | 453 | , 'wordpoints_hook_period_ids_by_reaction' |
454 | 454 | ); |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | |
43 | 43 | $conditions_data = array(); |
44 | 44 | |
45 | - foreach ( $this->conditions->get_all() as $data_type => $conditions ) { |
|
46 | - foreach ( $conditions as $slug => $condition ) { |
|
45 | + foreach ($this->conditions->get_all() as $data_type => $conditions) { |
|
46 | + foreach ($conditions as $slug => $condition) { |
|
47 | 47 | |
48 | - if ( ! ( $condition instanceof WordPoints_Hook_Condition ) ) { |
|
48 | + if ( ! ($condition instanceof WordPoints_Hook_Condition)) { |
|
49 | 49 | continue; |
50 | 50 | } |
51 | 51 | |
52 | - $conditions_data[ $data_type ][ $slug ] = array( |
|
52 | + $conditions_data[$data_type][$slug] = array( |
|
53 | 53 | 'slug' => $slug, |
54 | 54 | 'data_type' => $data_type, |
55 | 55 | 'title' => $condition->get_title(), |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | - return array( 'conditions' => $conditions_data ); |
|
61 | + return array('conditions' => $conditions_data); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @since 1.0.0 |
66 | 66 | */ |
67 | - protected function validate_action_type_settings( $settings ) { |
|
68 | - return $this->validate_conditions( $settings ); |
|
67 | + protected function validate_action_type_settings($settings) { |
|
68 | + return $this->validate_conditions($settings); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -78,36 +78,36 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return array The validated settings. |
80 | 80 | */ |
81 | - public function validate_conditions( $conditions, WordPoints_Hook_Event_Args $event_args = null ) { |
|
81 | + public function validate_conditions($conditions, WordPoints_Hook_Event_Args $event_args = null) { |
|
82 | 82 | |
83 | - if ( $event_args ) { |
|
83 | + if ($event_args) { |
|
84 | 84 | $this->event_args = $event_args; |
85 | 85 | $this->validator = $event_args->get_validator(); |
86 | 86 | } |
87 | 87 | |
88 | - if ( ! is_array( $conditions ) ) { |
|
88 | + if ( ! is_array($conditions)) { |
|
89 | 89 | |
90 | 90 | $this->validator->add_error( |
91 | - __( 'Conditions do not match expected format.', 'wordpoints' ) |
|
91 | + __('Conditions do not match expected format.', 'wordpoints') |
|
92 | 92 | ); |
93 | 93 | |
94 | 94 | return array(); |
95 | 95 | } |
96 | 96 | |
97 | - foreach ( $conditions as $arg_slug => $sub_args ) { |
|
97 | + foreach ($conditions as $arg_slug => $sub_args) { |
|
98 | 98 | |
99 | - if ( '_conditions' === $arg_slug ) { |
|
99 | + if ('_conditions' === $arg_slug) { |
|
100 | 100 | |
101 | - $this->validator->push_field( $arg_slug ); |
|
101 | + $this->validator->push_field($arg_slug); |
|
102 | 102 | |
103 | - foreach ( $sub_args as $index => $settings ) { |
|
103 | + foreach ($sub_args as $index => $settings) { |
|
104 | 104 | |
105 | - $this->validator->push_field( $index ); |
|
105 | + $this->validator->push_field($index); |
|
106 | 106 | |
107 | - $condition = $this->validate_condition( $settings ); |
|
107 | + $condition = $this->validate_condition($settings); |
|
108 | 108 | |
109 | - if ( $condition ) { |
|
110 | - $sub_args[ $index ] = $condition; |
|
109 | + if ($condition) { |
|
110 | + $sub_args[$index] = $condition; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | $this->validator->pop_field(); |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | |
118 | 118 | } else { |
119 | 119 | |
120 | - if ( ! $this->event_args->descend( $arg_slug ) ) { |
|
120 | + if ( ! $this->event_args->descend($arg_slug)) { |
|
121 | 121 | continue; |
122 | 122 | } |
123 | 123 | |
124 | - $sub_args = $this->validate_action_type_settings( $sub_args ); |
|
124 | + $sub_args = $this->validate_action_type_settings($sub_args); |
|
125 | 125 | |
126 | - $conditions[ $arg_slug ] = $sub_args; |
|
126 | + $conditions[$arg_slug] = $sub_args; |
|
127 | 127 | |
128 | 128 | $this->event_args->ascend(); |
129 | 129 | } |
130 | 130 | |
131 | - $conditions[ $arg_slug ] = $sub_args; |
|
131 | + $conditions[$arg_slug] = $sub_args; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | return $conditions; |
@@ -144,32 +144,32 @@ discard block |
||
144 | 144 | * @return array|false The validated conditions settings, or false if unable to |
145 | 145 | * validate. |
146 | 146 | */ |
147 | - protected function validate_condition( $settings ) { |
|
147 | + protected function validate_condition($settings) { |
|
148 | 148 | |
149 | - if ( ! isset( $settings['type'] ) ) { |
|
150 | - $this->validator->add_error( __( 'Condition type is missing.', 'wordpoints' ) ); |
|
149 | + if ( ! isset($settings['type'])) { |
|
150 | + $this->validator->add_error(__('Condition type is missing.', 'wordpoints')); |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | |
154 | 154 | $arg = $this->event_args->get_current(); |
155 | 155 | |
156 | - $data_type = $this->get_data_type( $arg ); |
|
156 | + $data_type = $this->get_data_type($arg); |
|
157 | 157 | |
158 | - if ( ! $data_type ) { |
|
158 | + if ( ! $data_type) { |
|
159 | 159 | $this->validator->add_error( |
160 | - __( 'This type of condition does not work for the selected attribute.', 'wordpoints' ) |
|
160 | + __('This type of condition does not work for the selected attribute.', 'wordpoints') |
|
161 | 161 | ); |
162 | 162 | |
163 | 163 | return false; |
164 | 164 | } |
165 | 165 | |
166 | - $condition = wordpoints_hooks()->conditions->get( $data_type, $settings['type'] ); |
|
166 | + $condition = wordpoints_hooks()->conditions->get($data_type, $settings['type']); |
|
167 | 167 | |
168 | - if ( ! $condition ) { |
|
168 | + if ( ! $condition) { |
|
169 | 169 | |
170 | 170 | $this->validator->add_error( |
171 | 171 | sprintf( |
172 | - __( 'Unknown condition type “%s”.', 'wordpoints' ) |
|
172 | + __('Unknown condition type “%s”.', 'wordpoints') |
|
173 | 173 | , $settings['type'] |
174 | 174 | ) |
175 | 175 | , 'type' |
@@ -178,17 +178,17 @@ discard block |
||
178 | 178 | return false; |
179 | 179 | } |
180 | 180 | |
181 | - if ( ! isset( $settings['settings'] ) ) { |
|
182 | - $this->validator->add_error( __( 'Condition settings are missing.', 'wordpoints' ) ); |
|
181 | + if ( ! isset($settings['settings'])) { |
|
182 | + $this->validator->add_error(__('Condition settings are missing.', 'wordpoints')); |
|
183 | 183 | return false; |
184 | 184 | } |
185 | 185 | |
186 | - $this->validator->push_field( 'settings' ); |
|
186 | + $this->validator->push_field('settings'); |
|
187 | 187 | |
188 | 188 | // The condition may call this object's validate_settings() method to |
189 | 189 | // validate some sub-conditions. When that happens, these properties will be |
190 | 190 | // reset, so we need to back up their values and then restore them below. |
191 | - $backup = array( $this->validator, $this->event_args ); |
|
191 | + $backup = array($this->validator, $this->event_args); |
|
192 | 192 | |
193 | 193 | $settings['settings'] = $condition->validate_settings( |
194 | 194 | $arg |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | , $this->validator |
197 | 197 | ); |
198 | 198 | |
199 | - list( $this->validator, $this->event_args ) = $backup; |
|
199 | + list($this->validator, $this->event_args) = $backup; |
|
200 | 200 | |
201 | 201 | $this->validator->pop_field(); |
202 | 202 | |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | /** |
207 | 207 | * @since 1.0.0 |
208 | 208 | */ |
209 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
209 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
210 | 210 | |
211 | - $conditions = $this->get_settings_from_fire( $fire ); |
|
211 | + $conditions = $this->get_settings_from_fire($fire); |
|
212 | 212 | |
213 | - if ( $conditions && ! $this->conditions_are_met( $conditions, $fire->event_args ) ) { |
|
213 | + if ($conditions && ! $this->conditions_are_met($conditions, $fire->event_args)) { |
|
214 | 214 | return false; |
215 | 215 | } |
216 | 216 | |
@@ -232,35 +232,35 @@ discard block |
||
232 | 232 | WordPoints_Hook_Event_Args $event_args |
233 | 233 | ) { |
234 | 234 | |
235 | - foreach ( $conditions as $arg_slug => $sub_args ) { |
|
235 | + foreach ($conditions as $arg_slug => $sub_args) { |
|
236 | 236 | |
237 | - $event_args->descend( $arg_slug ); |
|
237 | + $event_args->descend($arg_slug); |
|
238 | 238 | |
239 | - if ( isset( $sub_args['_conditions'] ) ) { |
|
239 | + if (isset($sub_args['_conditions'])) { |
|
240 | 240 | |
241 | - foreach ( $sub_args['_conditions'] as $settings ) { |
|
241 | + foreach ($sub_args['_conditions'] as $settings) { |
|
242 | 242 | |
243 | 243 | $condition = $this->conditions->get( |
244 | - $this->get_data_type( $event_args->get_current() ) |
|
244 | + $this->get_data_type($event_args->get_current()) |
|
245 | 245 | , $settings['type'] |
246 | 246 | ); |
247 | 247 | |
248 | - $is_met = $condition->is_met( $settings['settings'], $event_args ); |
|
248 | + $is_met = $condition->is_met($settings['settings'], $event_args); |
|
249 | 249 | |
250 | - if ( ! $is_met ) { |
|
250 | + if ( ! $is_met) { |
|
251 | 251 | $event_args->ascend(); |
252 | 252 | return false; |
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
256 | - unset( $sub_args['_conditions'] ); |
|
256 | + unset($sub_args['_conditions']); |
|
257 | 257 | } |
258 | 258 | |
259 | - $are_met = $this->conditions_are_met( $sub_args, $event_args ); |
|
259 | + $are_met = $this->conditions_are_met($sub_args, $event_args); |
|
260 | 260 | |
261 | 261 | $event_args->ascend(); |
262 | 262 | |
263 | - if ( ! $are_met ) { |
|
263 | + if ( ! $are_met) { |
|
264 | 264 | return false; |
265 | 265 | } |
266 | 266 | } |
@@ -277,13 +277,13 @@ discard block |
||
277 | 277 | * |
278 | 278 | * @return string|false The data type, or false. |
279 | 279 | */ |
280 | - protected function get_data_type( $arg ) { |
|
280 | + protected function get_data_type($arg) { |
|
281 | 281 | |
282 | - if ( $arg instanceof WordPoints_Entity_Attr ) { |
|
282 | + if ($arg instanceof WordPoints_Entity_Attr) { |
|
283 | 283 | $data_type = $arg->get_data_type(); |
284 | - } elseif ( $arg instanceof WordPoints_Entity_Array ) { |
|
284 | + } elseif ($arg instanceof WordPoints_Entity_Array) { |
|
285 | 285 | $data_type = 'entity_array'; |
286 | - } elseif ( $arg instanceof WordPoints_Entity ) { |
|
286 | + } elseif ($arg instanceof WordPoints_Entity) { |
|
287 | 287 | $data_type = 'entity'; |
288 | 288 | } else { |
289 | 289 | $data_type = false; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @since 1.0.0 |
57 | 57 | */ |
58 | 58 | public function get_title() { |
59 | - return __( 'Contains', 'wordpoints' ); |
|
59 | + return __('Contains', 'wordpoints'); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -66,13 +66,13 @@ discard block |
||
66 | 66 | return array( |
67 | 67 | 'min' => array( |
68 | 68 | 'slug' => 'min', |
69 | - 'label' => __( 'Minimum number of items', 'wordpoints' ), |
|
69 | + 'label' => __('Minimum number of items', 'wordpoints'), |
|
70 | 70 | 'type' => 'number', |
71 | 71 | 'default' => 1, |
72 | 72 | ), |
73 | 73 | 'max' => array( |
74 | 74 | 'slug' => 'max', |
75 | - 'label' => __( 'Maximum number of items', 'wordpoints' ), |
|
75 | + 'label' => __('Maximum number of items', 'wordpoints'), |
|
76 | 76 | 'type' => 'number', |
77 | 77 | ), |
78 | 78 | ); |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | |
93 | 93 | $this->validate_count(); |
94 | 94 | |
95 | - if ( isset( $settings['conditions'] ) ) { |
|
96 | - $this->validate_conditions( $arg ); |
|
95 | + if (isset($settings['conditions'])) { |
|
96 | + $this->validate_conditions($arg); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | return $this->settings; |
@@ -107,31 +107,31 @@ discard block |
||
107 | 107 | protected function validate_count() { |
108 | 108 | |
109 | 109 | if ( |
110 | - ! empty( $this->settings['max'] ) |
|
111 | - && ! wordpoints_posint( $this->settings['max'] ) |
|
110 | + ! empty($this->settings['max']) |
|
111 | + && ! wordpoints_posint($this->settings['max']) |
|
112 | 112 | ) { |
113 | 113 | $this->validator->add_error( |
114 | - __( 'The maximum must be a positive integer.', 'wordpoints' ) |
|
114 | + __('The maximum must be a positive integer.', 'wordpoints') |
|
115 | 115 | , 'max' |
116 | 116 | ); |
117 | 117 | } |
118 | 118 | |
119 | - if ( ! empty( $this->settings['min'] ) ) { |
|
119 | + if ( ! empty($this->settings['min'])) { |
|
120 | 120 | |
121 | - if ( ! wordpoints_posint( $this->settings['min'] ) ) { |
|
121 | + if ( ! wordpoints_posint($this->settings['min'])) { |
|
122 | 122 | |
123 | 123 | $this->validator->add_error( |
124 | - __( 'The minimum must be a positive integer.', 'wordpoints' ) |
|
124 | + __('The minimum must be a positive integer.', 'wordpoints') |
|
125 | 125 | , 'min' |
126 | 126 | ); |
127 | 127 | |
128 | 128 | } elseif ( |
129 | - ! empty( $this->settings['max'] ) |
|
129 | + ! empty($this->settings['max']) |
|
130 | 130 | && $this->settings['max'] < $this->settings['min'] |
131 | 131 | ) { |
132 | 132 | |
133 | 133 | $this->validator->add_error( |
134 | - __( 'The minimum must be less than the maximum.', 'wordpoints' ) |
|
134 | + __('The minimum must be less than the maximum.', 'wordpoints') |
|
135 | 135 | , 'min' |
136 | 136 | ); |
137 | 137 | } |
@@ -145,24 +145,24 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @param WordPoints_EntityishI $current_arg The current arg. |
147 | 147 | */ |
148 | - protected function validate_conditions( $current_arg ) { |
|
148 | + protected function validate_conditions($current_arg) { |
|
149 | 149 | |
150 | - $args = new WordPoints_Hook_Event_Args( array() ); |
|
150 | + $args = new WordPoints_Hook_Event_Args(array()); |
|
151 | 151 | |
152 | - if ( $current_arg instanceof WordPoints_Entity_Array ) { |
|
152 | + if ($current_arg instanceof WordPoints_Entity_Array) { |
|
153 | 153 | |
154 | 154 | $entity = wordpoints_entities()->get( |
155 | 155 | $current_arg->get_entity_slug() |
156 | 156 | ); |
157 | 157 | |
158 | - if ( $entity instanceof WordPoints_Entity ) { |
|
159 | - $args->add_entity( $entity ); |
|
158 | + if ($entity instanceof WordPoints_Entity) { |
|
159 | + $args->add_entity($entity); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | - $args->set_validator( $this->validator ); |
|
163 | + $args->set_validator($this->validator); |
|
164 | 164 | |
165 | - $this->validator->push_field( 'conditions' ); |
|
165 | + $this->validator->push_field('conditions'); |
|
166 | 166 | |
167 | 167 | $this->settings['conditions'] = $this->conditions_extension->validate_conditions( |
168 | 168 | $this->settings['conditions'] |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | /** |
176 | 176 | * @since 1.0.0 |
177 | 177 | */ |
178 | - public function is_met( array $settings, WordPoints_Hook_Event_Args $args ) { |
|
178 | + public function is_met(array $settings, WordPoints_Hook_Event_Args $args) { |
|
179 | 179 | |
180 | 180 | $this->settings = $settings; |
181 | 181 | |
@@ -183,16 +183,16 @@ discard block |
||
183 | 183 | |
184 | 184 | $entities = array(); |
185 | 185 | |
186 | - if ( $arg instanceof WordPoints_Entity_Array ) { |
|
186 | + if ($arg instanceof WordPoints_Entity_Array) { |
|
187 | 187 | |
188 | 188 | $entities = $arg->get_the_entities(); |
189 | 189 | |
190 | - if ( isset( $this->settings['conditions'] ) ) { |
|
191 | - $entities = $this->filter_entities( $entities ); |
|
190 | + if (isset($this->settings['conditions'])) { |
|
191 | + $entities = $this->filter_entities($entities); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | - return $this->check_count( count( $entities ) ); |
|
195 | + return $this->check_count(count($entities)); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -204,20 +204,20 @@ discard block |
||
204 | 204 | * |
205 | 205 | * @return WordPoints_Entity[] The entities that matched the sub-conditions. |
206 | 206 | */ |
207 | - protected function filter_entities( $entities ) { |
|
207 | + protected function filter_entities($entities) { |
|
208 | 208 | |
209 | - foreach ( $entities as $index => $entity ) { |
|
209 | + foreach ($entities as $index => $entity) { |
|
210 | 210 | |
211 | - $event_args = new WordPoints_Hook_Event_Args( array() ); |
|
212 | - $event_args->add_entity( $entity ); |
|
211 | + $event_args = new WordPoints_Hook_Event_Args(array()); |
|
212 | + $event_args->add_entity($entity); |
|
213 | 213 | |
214 | 214 | $matches = $this->conditions_extension->conditions_are_met( |
215 | 215 | $this->settings['conditions'] |
216 | 216 | , $event_args |
217 | 217 | ); |
218 | 218 | |
219 | - if ( ! $matches ) { |
|
220 | - unset( $entities[ $index ] ); |
|
219 | + if ( ! $matches) { |
|
220 | + unset($entities[$index]); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
@@ -233,13 +233,13 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @return bool Whether the count met the requirements. |
235 | 235 | */ |
236 | - protected function check_count( $count ) { |
|
236 | + protected function check_count($count) { |
|
237 | 237 | |
238 | - if ( isset( $this->settings['max'] ) && $count > $this->settings['max'] ) { |
|
238 | + if (isset($this->settings['max']) && $count > $this->settings['max']) { |
|
239 | 239 | return false; |
240 | 240 | } |
241 | 241 | |
242 | - if ( isset( $this->settings['min'] ) && $count < $this->settings['min'] ) { |
|
242 | + if (isset($this->settings['min']) && $count < $this->settings['min']) { |
|
243 | 243 | return false; |
244 | 244 | } |
245 | 245 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * @since 1.0.0 |
29 | 29 | */ |
30 | - protected $action_types = array( 'fire', 'reverse' ); |
|
30 | + protected $action_types = array('fire', 'reverse'); |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @since 1.0.0 |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function get_settings_fields() { |
60 | 60 | |
61 | - $this->settings_fields['points']['label'] = _x( 'Points', 'form label', 'wordpoints' ); |
|
62 | - $this->settings_fields['log_text']['label'] = _x( 'Log Text', 'form label', 'wordpoints' ); |
|
63 | - $this->settings_fields['description']['label'] = _x( 'Description', 'form label', 'wordpoints' ); |
|
61 | + $this->settings_fields['points']['label'] = _x('Points', 'form label', 'wordpoints'); |
|
62 | + $this->settings_fields['log_text']['label'] = _x('Log Text', 'form label', 'wordpoints'); |
|
63 | + $this->settings_fields['description']['label'] = _x('Description', 'form label', 'wordpoints'); |
|
64 | 64 | |
65 | 65 | return parent::get_settings_fields(); |
66 | 66 | } |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | |
73 | 73 | $data = parent::get_ui_script_data(); |
74 | 74 | |
75 | - $data['target_label'] = __( 'Award To', 'wordpoints' ); |
|
76 | - $data['periods_label'] = __( 'Award each user no more than once per:', 'wordpoints' ); |
|
75 | + $data['target_label'] = __('Award To', 'wordpoints'); |
|
76 | + $data['periods_label'] = __('Award each user no more than once per:', 'wordpoints'); |
|
77 | 77 | |
78 | 78 | return $data; |
79 | 79 | } |
@@ -87,23 +87,23 @@ discard block |
||
87 | 87 | WordPoints_Hook_Event_Args $event_args |
88 | 88 | ) { |
89 | 89 | |
90 | - if ( ! isset( $settings['points'] ) || false === wordpoints_int( $settings['points'] ) ) { |
|
91 | - $validator->add_error( __( 'Points must be an integer.', 'wordpoints' ), 'points' ); |
|
90 | + if ( ! isset($settings['points']) || false === wordpoints_int($settings['points'])) { |
|
91 | + $validator->add_error(__('Points must be an integer.', 'wordpoints'), 'points'); |
|
92 | 92 | } |
93 | 93 | |
94 | - if ( ! isset( $settings['points_type'] ) || ! wordpoints_is_points_type( $settings['points_type'] ) ) { |
|
95 | - $validator->add_error( __( 'Invalid points type.', 'wordpoints' ), 'points_type' ); |
|
94 | + if ( ! isset($settings['points_type']) || ! wordpoints_is_points_type($settings['points_type'])) { |
|
95 | + $validator->add_error(__('Invalid points type.', 'wordpoints'), 'points_type'); |
|
96 | 96 | } |
97 | 97 | |
98 | - if ( ! isset( $settings['description'] ) ) { |
|
99 | - $validator->add_error( __( 'Description is required.', 'wordpoints' ), 'description' ); |
|
98 | + if ( ! isset($settings['description'])) { |
|
99 | + $validator->add_error(__('Description is required.', 'wordpoints'), 'description'); |
|
100 | 100 | } |
101 | 101 | |
102 | - if ( ! isset( $settings['log_text'] ) ) { |
|
103 | - $validator->add_error( __( 'Log Text is required.', 'wordpoints' ), 'log_text' ); |
|
102 | + if ( ! isset($settings['log_text'])) { |
|
103 | + $validator->add_error(__('Log Text is required.', 'wordpoints'), 'log_text'); |
|
104 | 104 | } |
105 | 105 | |
106 | - return parent::validate_settings( $settings, $validator, $event_args ); |
|
106 | + return parent::validate_settings($settings, $validator, $event_args); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -114,54 +114,54 @@ discard block |
||
114 | 114 | array $settings |
115 | 115 | ) { |
116 | 116 | |
117 | - parent::update_settings( $reaction, $settings ); |
|
117 | + parent::update_settings($reaction, $settings); |
|
118 | 118 | |
119 | - $reaction->update_meta( 'points', $settings['points'] ); |
|
120 | - $reaction->update_meta( 'points_type', $settings['points_type'] ); |
|
121 | - $reaction->update_meta( 'description', $settings['description'] ); |
|
122 | - $reaction->update_meta( 'log_text', $settings['log_text'] ); |
|
119 | + $reaction->update_meta('points', $settings['points']); |
|
120 | + $reaction->update_meta('points_type', $settings['points_type']); |
|
121 | + $reaction->update_meta('description', $settings['description']); |
|
122 | + $reaction->update_meta('log_text', $settings['log_text']); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | 126 | * @since 1.0.0 |
127 | 127 | */ |
128 | - public function hit( WordPoints_Hook_Fire $fire ) { |
|
128 | + public function hit(WordPoints_Hook_Fire $fire) { |
|
129 | 129 | |
130 | - if ( 'reverse' === $fire->action_type ) { |
|
131 | - $this->reverse_hit( $fire ); |
|
130 | + if ('reverse' === $fire->action_type) { |
|
131 | + $this->reverse_hit($fire); |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
135 | 135 | $reaction = $fire->reaction; |
136 | 136 | |
137 | 137 | $target = $fire->event_args->get_from_hierarchy( |
138 | - $reaction->get_meta( 'target' ) |
|
138 | + $reaction->get_meta('target') |
|
139 | 139 | ); |
140 | 140 | |
141 | - if ( ! $target instanceof WordPoints_Entity ) { |
|
141 | + if ( ! $target instanceof WordPoints_Entity) { |
|
142 | 142 | return; |
143 | 143 | } |
144 | 144 | |
145 | 145 | $meta = array(); |
146 | 146 | |
147 | - foreach ( $fire->event_args->get_entities() as $entity ) { |
|
148 | - $meta[ $entity->get_slug() ] = $entity->get_the_id(); |
|
147 | + foreach ($fire->event_args->get_entities() as $entity) { |
|
148 | + $meta[$entity->get_slug()] = $entity->get_the_id(); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | wordpoints_alter_points( |
152 | 152 | $target->get_the_id() |
153 | - , $reaction->get_meta( 'points' ) |
|
154 | - , $reaction->get_meta( 'points_type' ) |
|
153 | + , $reaction->get_meta('points') |
|
154 | + , $reaction->get_meta('points_type') |
|
155 | 155 | , $reaction->get_event_slug() |
156 | 156 | , $meta |
157 | - , $reaction->get_meta( 'log_text' ) |
|
157 | + , $reaction->get_meta('log_text') |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * @since 1.0.0 |
163 | 163 | */ |
164 | - public function reverse_hit( WordPoints_Hook_Fire $fire ) { |
|
164 | + public function reverse_hit(WordPoints_Hook_Fire $fire) { |
|
165 | 165 | |
166 | 166 | $meta_queries = array( |
167 | 167 | array( |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | ), |
173 | 173 | ); |
174 | 174 | |
175 | - foreach ( $fire->event_args->get_entities() as $slug => $entity ) { |
|
175 | + foreach ($fire->event_args->get_entities() as $slug => $entity) { |
|
176 | 176 | |
177 | 177 | $meta_queries[] = array( |
178 | 178 | 'key' => $slug, |
@@ -189,35 +189,35 @@ discard block |
||
189 | 189 | |
190 | 190 | $logs = $query->get(); |
191 | 191 | |
192 | - if ( ! $logs ) { |
|
192 | + if ( ! $logs) { |
|
193 | 193 | return; |
194 | 194 | } |
195 | 195 | |
196 | 196 | global $wpdb; |
197 | 197 | |
198 | - add_filter( 'wordpoints_points_log', '__return_false' ); |
|
198 | + add_filter('wordpoints_points_log', '__return_false'); |
|
199 | 199 | |
200 | - foreach ( $logs as $log ) { |
|
200 | + foreach ($logs as $log) { |
|
201 | 201 | |
202 | 202 | wordpoints_alter_points( |
203 | 203 | $log->user_id |
204 | 204 | , -$log->points |
205 | 205 | , $log->points_type |
206 | 206 | , "reverse-{$log->log_type}" |
207 | - , array( 'original_log_id' => $log->id ) |
|
207 | + , array('original_log_id' => $log->id) |
|
208 | 208 | ); |
209 | 209 | |
210 | - wordpoints_points_log_delete_all_metadata( $log->id ); |
|
210 | + wordpoints_points_log_delete_all_metadata($log->id); |
|
211 | 211 | |
212 | 212 | // Now delete the log. |
213 | 213 | $wpdb->delete( |
214 | 214 | $wpdb->wordpoints_points_logs |
215 | - , array( 'id' => $log->id ) |
|
215 | + , array('id' => $log->id) |
|
216 | 216 | , '%d' |
217 | 217 | ); // WPCS: cache OK, cleaned by wordpoints_alter_points(). |
218 | 218 | } |
219 | 219 | |
220 | - remove_filter( 'wordpoints_points_log', '__return_false' ); |
|
220 | + remove_filter('wordpoints_points_log', '__return_false'); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @var string|string[] |
50 | 50 | */ |
51 | - protected $action_types = array( 'fire' ); |
|
51 | + protected $action_types = array('fire'); |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * The settings fields used by this reactor. |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * @since 1.0.0 |
64 | 64 | */ |
65 | - public function __get( $var ) { |
|
65 | + public function __get($var) { |
|
66 | 66 | |
67 | - if ( 'reactions' !== $var ) { |
|
67 | + if ('reactions' !== $var) { |
|
68 | 68 | return null; |
69 | 69 | } |
70 | 70 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | wordpoints_hooks()->get_current_mode() |
73 | 73 | ); |
74 | 74 | |
75 | - if ( ! $reaction_store ) { |
|
75 | + if ( ! $reaction_store) { |
|
76 | 76 | return null; |
77 | 77 | } |
78 | 78 | |
@@ -88,20 +88,20 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return WordPoints_Hook_Reaction_StoreI|false The reaction storage object. |
90 | 90 | */ |
91 | - public function get_reaction_store( $slug ) { |
|
91 | + public function get_reaction_store($slug) { |
|
92 | 92 | |
93 | 93 | $reaction_store = wordpoints_hooks()->reaction_stores->get( |
94 | 94 | $this->slug |
95 | 95 | , $slug |
96 | - , array( $this ) |
|
96 | + , array($this) |
|
97 | 97 | ); |
98 | 98 | |
99 | - if ( ! $reaction_store instanceof WordPoints_Hook_Reaction_StoreI ) { |
|
99 | + if ( ! $reaction_store instanceof WordPoints_Hook_Reaction_StoreI) { |
|
100 | 100 | return false; |
101 | 101 | } |
102 | 102 | |
103 | 103 | // Allowing access to stores out-of-context would lead to strange behavior. |
104 | - if ( false === $reaction_store->get_context_id() ) { |
|
104 | + if (false === $reaction_store->get_context_id()) { |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @return WordPoints_Hook_ReactionI[] All of the reaction objects. |
205 | 205 | */ |
206 | - public function get_all_reactions_to_event( $event_slug ) { |
|
206 | + public function get_all_reactions_to_event($event_slug) { |
|
207 | 207 | |
208 | 208 | $reactions = array(); |
209 | 209 | |
@@ -211,17 +211,17 @@ discard block |
||
211 | 211 | $this->slug |
212 | 212 | ); |
213 | 213 | |
214 | - foreach ( $slugs as $slug ) { |
|
214 | + foreach ($slugs as $slug) { |
|
215 | 215 | |
216 | - $store = $this->get_reaction_store( $slug ); |
|
216 | + $store = $this->get_reaction_store($slug); |
|
217 | 217 | |
218 | - if ( ! $store ) { |
|
218 | + if ( ! $store) { |
|
219 | 219 | continue; |
220 | 220 | } |
221 | 221 | |
222 | 222 | $reactions = array_merge( |
223 | 223 | $reactions |
224 | - , $store->get_reactions_to_event( $event_slug ) |
|
224 | + , $store->get_reactions_to_event($event_slug) |
|
225 | 225 | ); |
226 | 226 | } |
227 | 227 | |
@@ -250,15 +250,15 @@ discard block |
||
250 | 250 | $this->slug |
251 | 251 | ); |
252 | 252 | |
253 | - foreach ( $slugs as $slug ) { |
|
253 | + foreach ($slugs as $slug) { |
|
254 | 254 | |
255 | - $store = $this->get_reaction_store( $slug ); |
|
255 | + $store = $this->get_reaction_store($slug); |
|
256 | 256 | |
257 | - if ( ! $store ) { |
|
257 | + if ( ! $store) { |
|
258 | 258 | continue; |
259 | 259 | } |
260 | 260 | |
261 | - $reactions = array_merge( $reactions, $store->get_reactions() ); |
|
261 | + $reactions = array_merge($reactions, $store->get_reactions()); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | return $reactions; |
@@ -274,21 +274,21 @@ discard block |
||
274 | 274 | ) { |
275 | 275 | |
276 | 276 | if ( |
277 | - empty( $settings['target'] ) |
|
278 | - || ! is_array( $settings['target'] ) |
|
277 | + empty($settings['target']) |
|
278 | + || ! is_array($settings['target']) |
|
279 | 279 | ) { |
280 | 280 | |
281 | - $validator->add_error( __( 'Invalid target.', 'wordpoints' ), 'target' ); |
|
281 | + $validator->add_error(__('Invalid target.', 'wordpoints'), 'target'); |
|
282 | 282 | |
283 | 283 | } else { |
284 | 284 | |
285 | - $target = $event_args->get_from_hierarchy( $settings['target'] ); |
|
285 | + $target = $event_args->get_from_hierarchy($settings['target']); |
|
286 | 286 | |
287 | 287 | if ( |
288 | 288 | ! $target instanceof WordPoints_Entity |
289 | - || ! in_array( $target->get_slug(), (array) $this->arg_types ) |
|
289 | + || ! in_array($target->get_slug(), (array) $this->arg_types) |
|
290 | 290 | ) { |
291 | - $validator->add_error( __( 'Invalid target.', 'wordpoints' ), 'target' ); |
|
291 | + $validator->add_error(__('Invalid target.', 'wordpoints'), 'target'); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
@@ -298,8 +298,8 @@ discard block |
||
298 | 298 | /** |
299 | 299 | * @since 1.0.0 |
300 | 300 | */ |
301 | - public function update_settings( WordPoints_Hook_ReactionI $reaction, array $settings ) { |
|
302 | - $reaction->update_meta( 'target', $settings['target'] ); |
|
301 | + public function update_settings(WordPoints_Hook_ReactionI $reaction, array $settings) { |
|
302 | + $reaction->update_meta('target', $settings['target']); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @param WordPoints_Hook_Fire $fire The hook fire object. |
311 | 311 | */ |
312 | - abstract public function hit( WordPoints_Hook_Fire $fire ); |
|
312 | + abstract public function hit(WordPoints_Hook_Fire $fire); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | // EOF |
@@ -18,15 +18,15 @@ discard block |
||
18 | 18 | * @since 1.0.0 |
19 | 19 | */ |
20 | 20 | protected $columns = array( |
21 | - 'id' => array( 'format' => '%d', 'unsigned' => true ), |
|
22 | - 'action_type' => array( 'format' => '%s' ), |
|
23 | - 'primary_arg_guid' => array( 'format' => '%s' ), |
|
24 | - 'event' => array( 'format' => '%s' ), |
|
25 | - 'reactor' => array( 'format' => '%s' ), |
|
26 | - 'reaction_store' => array( 'format' => '%s' ), |
|
27 | - 'reaction_context_id' => array( 'format' => '%s' ), |
|
28 | - 'reaction_id' => array( 'format' => '%d', 'unsigned' => true ), |
|
29 | - 'date' => array( 'format' => '%s', 'is_date' => true ), |
|
21 | + 'id' => array('format' => '%d', 'unsigned' => true), |
|
22 | + 'action_type' => array('format' => '%s'), |
|
23 | + 'primary_arg_guid' => array('format' => '%s'), |
|
24 | + 'event' => array('format' => '%s'), |
|
25 | + 'reactor' => array('format' => '%s'), |
|
26 | + 'reaction_store' => array('format' => '%s'), |
|
27 | + 'reaction_context_id' => array('format' => '%s'), |
|
28 | + 'reaction_id' => array('format' => '%d', 'unsigned' => true), |
|
29 | + 'date' => array('format' => '%s', 'is_date' => true), |
|
30 | 30 | ); |
31 | 31 | |
32 | 32 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @type array $meta_query See WP_Meta_Query. |
103 | 103 | * } |
104 | 104 | */ |
105 | - public function __construct( $args = array() ) { |
|
105 | + public function __construct($args = array()) { |
|
106 | 106 | |
107 | 107 | global $wpdb; |
108 | 108 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | $this->defaults['order_by'] = 'date'; |
112 | 112 | |
113 | - parent::__construct( $args ); |
|
113 | + parent::__construct($args); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 |