@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @param WordPoints_Hook_Fire $fire The fire that might be logged as a hit. |
30 | 30 | */ |
31 | - public function __construct( WordPoints_Hook_Fire $fire ) { |
|
31 | + public function __construct(WordPoints_Hook_Fire $fire) { |
|
32 | 32 | |
33 | 33 | $this->fire = $fire; |
34 | 34 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | global $wpdb; |
46 | 46 | |
47 | - $signature = wordpoints_hooks_get_event_primary_arg_guid_json( $this->fire->event_args ); |
|
47 | + $signature = wordpoints_hooks_get_event_primary_arg_guid_json($this->fire->event_args); |
|
48 | 48 | |
49 | 49 | $inserted = $wpdb->insert( |
50 | 50 | $wpdb->wordpoints_hook_hits |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | 'event' => $this->fire->reaction->get_event_slug(), |
55 | 55 | 'reactor' => $this->fire->reaction->get_reactor_slug(), |
56 | 56 | 'reaction_store' => $this->fire->reaction->get_store_slug(), |
57 | - 'reaction_context_id' => wp_json_encode( $this->fire->reaction->get_context_id() ), |
|
57 | + 'reaction_context_id' => wp_json_encode($this->fire->reaction->get_context_id()), |
|
58 | 58 | 'reaction_id' => $this->fire->reaction->ID, |
59 | - 'date' => current_time( 'mysql' ), |
|
59 | + 'date' => current_time('mysql'), |
|
60 | 60 | ) |
61 | 61 | ); |
62 | 62 | |
63 | - if ( ! $inserted ) { |
|
63 | + if ( ! $inserted) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 |
@@ -9,8 +9,8 @@ |
||
9 | 9 | |
10 | 10 | global $wpdb; |
11 | 11 | |
12 | -$wpdb->wordpoints_hook_hits = $wpdb->base_prefix . 'wordpoints_hook_hits'; |
|
13 | -$wpdb->wordpoints_hook_hitmeta = $wpdb->base_prefix . 'wordpoints_hook_hitmeta'; |
|
14 | -$wpdb->wordpoints_hook_periods = $wpdb->base_prefix . 'wordpoints_hook_periods'; |
|
12 | +$wpdb->wordpoints_hook_hits = $wpdb->base_prefix.'wordpoints_hook_hits'; |
|
13 | +$wpdb->wordpoints_hook_hitmeta = $wpdb->base_prefix.'wordpoints_hook_hitmeta'; |
|
14 | +$wpdb->wordpoints_hook_periods = $wpdb->base_prefix.'wordpoints_hook_periods'; |
|
15 | 15 | |
16 | 16 | // EOF |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @type array $meta_query See WP_Meta_Query. |
215 | 215 | * } |
216 | 216 | */ |
217 | - public function __construct( $args = array() ) { |
|
218 | - $this->args = array_merge( $this->defaults, $args ); |
|
217 | + public function __construct($args = array()) { |
|
218 | + $this->args = array_merge($this->defaults, $args); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @return mixed|null The query arg's value, or null if it isn't set. |
229 | 229 | */ |
230 | - public function get_arg( $arg ) { |
|
230 | + public function get_arg($arg) { |
|
231 | 231 | |
232 | - if ( isset( $this->args[ $arg ] ) ) { |
|
233 | - return $this->args[ $arg ]; |
|
232 | + if (isset($this->args[$arg])) { |
|
233 | + return $this->args[$arg]; |
|
234 | 234 | } else { |
235 | 235 | return null; |
236 | 236 | } |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | * |
247 | 247 | * @param array $args A list of arguments to set and their values. |
248 | 248 | */ |
249 | - public function set_args( array $args ) { |
|
249 | + public function set_args(array $args) { |
|
250 | 250 | |
251 | - $this->args = array_merge( $this->args, $args ); |
|
251 | + $this->args = array_merge($this->args, $args); |
|
252 | 252 | |
253 | 253 | $this->is_query_ready = false; |
254 | 254 | } |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | |
270 | 270 | global $wpdb; |
271 | 271 | |
272 | - $count = (int) $wpdb->get_var( $this->get_sql( 'SELECT COUNT' ) ); // WPCS: unprepared SQL, cache OK |
|
272 | + $count = (int) $wpdb->get_var($this->get_sql('SELECT COUNT')); // WPCS: unprepared SQL, cache OK |
|
273 | 273 | |
274 | 274 | return $count; |
275 | 275 | } |
@@ -284,20 +284,20 @@ discard block |
||
284 | 284 | * |
285 | 285 | * @return mixed The results of the query, or false on failure. |
286 | 286 | */ |
287 | - public function get( $method = 'results' ) { |
|
287 | + public function get($method = 'results') { |
|
288 | 288 | |
289 | 289 | global $wpdb; |
290 | 290 | |
291 | - $methods = array( 'results', 'row', 'col', 'var' ); |
|
291 | + $methods = array('results', 'row', 'col', 'var'); |
|
292 | 292 | |
293 | - if ( ! in_array( $method, $methods ) ) { |
|
293 | + if ( ! in_array($method, $methods)) { |
|
294 | 294 | |
295 | - _doing_it_wrong( __METHOD__, esc_html( sprintf( 'WordPoints Debug Error: invalid get method %s, possible values are %s', $method, implode( ', ', $methods ) ) ), '1.0.0' ); |
|
295 | + _doing_it_wrong(__METHOD__, esc_html(sprintf('WordPoints Debug Error: invalid get method %s, possible values are %s', $method, implode(', ', $methods))), '1.0.0'); |
|
296 | 296 | |
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | |
300 | - $result = $wpdb->{"get_{$method}"}( $this->get_sql() ); |
|
300 | + $result = $wpdb->{"get_{$method}"}($this->get_sql()); |
|
301 | 301 | |
302 | 302 | return $result; |
303 | 303 | } |
@@ -317,11 +317,11 @@ discard block |
||
317 | 317 | * |
318 | 318 | * @return string The SQL for the query. |
319 | 319 | */ |
320 | - public function get_sql( $select_type = 'SELECT' ) { |
|
320 | + public function get_sql($select_type = 'SELECT') { |
|
321 | 321 | |
322 | 322 | $this->prepare_query(); |
323 | 323 | |
324 | - $select = ( 'SELECT COUNT' === $select_type ) |
|
324 | + $select = ('SELECT COUNT' === $select_type) |
|
325 | 325 | ? $this->select_count |
326 | 326 | : $this->select; |
327 | 327 | |
@@ -349,12 +349,12 @@ discard block |
||
349 | 349 | * |
350 | 350 | * @return string[] The valid columns. |
351 | 351 | */ |
352 | - public function date_query_valid_columns_filter( $valid_columns ) { |
|
352 | + public function date_query_valid_columns_filter($valid_columns) { |
|
353 | 353 | |
354 | 354 | $valid_columns = array_merge( |
355 | 355 | $valid_columns |
356 | 356 | , array_keys( |
357 | - wp_list_filter( $this->columns, array( 'is_date' => true ) ) |
|
357 | + wp_list_filter($this->columns, array('is_date' => true)) |
|
358 | 358 | ) |
359 | 359 | ); |
360 | 360 | |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | */ |
373 | 373 | protected function prepare_query() { |
374 | 374 | |
375 | - if ( ! $this->is_query_ready ) { |
|
375 | + if ( ! $this->is_query_ready) { |
|
376 | 376 | |
377 | 377 | $this->prepare_select(); |
378 | 378 | $this->prepare_where(); |
@@ -390,26 +390,26 @@ discard block |
||
390 | 390 | */ |
391 | 391 | protected function prepare_select() { |
392 | 392 | |
393 | - $all_fields = array_keys( $this->columns ); |
|
393 | + $all_fields = array_keys($this->columns); |
|
394 | 394 | $fields = array(); |
395 | 395 | |
396 | - if ( ! empty( $this->args['fields'] ) ) { |
|
396 | + if ( ! empty($this->args['fields'])) { |
|
397 | 397 | |
398 | 398 | $fields = (array) $this->args['fields']; |
399 | - $diff = array_diff( $fields, $all_fields ); |
|
400 | - $fields = array_intersect( $all_fields, $fields ); |
|
399 | + $diff = array_diff($fields, $all_fields); |
|
400 | + $fields = array_intersect($all_fields, $fields); |
|
401 | 401 | |
402 | - if ( ! empty( $diff ) ) { |
|
403 | - _doing_it_wrong( __METHOD__, esc_html( 'WordPoints Debug Error: invalid field(s) "' . implode( '", "', $diff ) . '" given' ), '1.0.0' ); |
|
402 | + if ( ! empty($diff)) { |
|
403 | + _doing_it_wrong(__METHOD__, esc_html('WordPoints Debug Error: invalid field(s) "'.implode('", "', $diff).'" given'), '1.0.0'); |
|
404 | 404 | } |
405 | 405 | } |
406 | 406 | |
407 | 407 | // Pull all fields by default. |
408 | - if ( empty( $fields ) ) { |
|
408 | + if (empty($fields)) { |
|
409 | 409 | $fields = $all_fields; |
410 | 410 | } |
411 | 411 | |
412 | - $fields = implode( ', ', array_map( 'wordpoints_escape_mysql_identifier', $fields ) ); |
|
412 | + $fields = implode(', ', array_map('wordpoints_escape_mysql_identifier', $fields)); |
|
413 | 413 | |
414 | 414 | $this->select = "SELECT {$fields}"; |
415 | 415 | } |
@@ -424,13 +424,13 @@ discard block |
||
424 | 424 | * |
425 | 425 | * @return mixed The validated value, or false if invalid. |
426 | 426 | */ |
427 | - protected function validate_value( $value, $validators ) { |
|
427 | + protected function validate_value($value, $validators) { |
|
428 | 428 | |
429 | - foreach ( $validators as $validator ) { |
|
429 | + foreach ($validators as $validator) { |
|
430 | 430 | |
431 | - $value = call_user_func_array( $validator, array( &$value ) ); |
|
431 | + $value = call_user_func_array($validator, array(&$value)); |
|
432 | 432 | |
433 | - if ( false === $value ) { |
|
433 | + if (false === $value) { |
|
434 | 434 | break; |
435 | 435 | } |
436 | 436 | } |
@@ -448,14 +448,14 @@ discard block |
||
448 | 448 | * |
449 | 449 | * @return array The validated values, with any invalid ones removed. |
450 | 450 | */ |
451 | - protected function validate_values( $values, $validators ) { |
|
451 | + protected function validate_values($values, $validators) { |
|
452 | 452 | |
453 | - foreach ( $values as $index => $value ) { |
|
453 | + foreach ($values as $index => $value) { |
|
454 | 454 | |
455 | - $value = $this->validate_value( $value, $validators ); |
|
455 | + $value = $this->validate_value($value, $validators); |
|
456 | 456 | |
457 | - if ( false === $value ) { |
|
458 | - unset( $values[ $index ] ); |
|
457 | + if (false === $value) { |
|
458 | + unset($values[$index]); |
|
459 | 459 | } |
460 | 460 | } |
461 | 461 | |
@@ -474,9 +474,9 @@ discard block |
||
474 | 474 | * |
475 | 475 | * @return int|false The validated value or false. |
476 | 476 | */ |
477 | - protected function validate_unsigned_column( $value ) { |
|
477 | + protected function validate_unsigned_column($value) { |
|
478 | 478 | |
479 | - if ( false !== wordpoints_int( $value ) && $value >= 0 ) { |
|
479 | + if (false !== wordpoints_int($value) && $value >= 0) { |
|
480 | 480 | return $value; |
481 | 481 | } |
482 | 482 | |
@@ -492,14 +492,14 @@ discard block |
||
492 | 492 | * |
493 | 493 | * @return callable[] The validation functions. |
494 | 494 | */ |
495 | - protected function get_validators_for_column( $data ) { |
|
495 | + protected function get_validators_for_column($data) { |
|
496 | 496 | |
497 | 497 | $validators = array(); |
498 | 498 | |
499 | 499 | // Default validators for integer columns. |
500 | - if ( '%d' === $data['format'] ) { |
|
501 | - if ( ! empty( $data['unsigned'] ) ) { |
|
502 | - $validators[] = array( $this, 'validate_unsigned_column' ); |
|
500 | + if ('%d' === $data['format']) { |
|
501 | + if ( ! empty($data['unsigned'])) { |
|
502 | + $validators[] = array($this, 'validate_unsigned_column'); |
|
503 | 503 | } else { |
504 | 504 | $validators[] = 'wordpoints_int'; |
505 | 505 | } |
@@ -516,15 +516,15 @@ discard block |
||
516 | 516 | * @param string $column The column name. |
517 | 517 | * @param array $data The column data. |
518 | 518 | */ |
519 | - protected function prepare_column_where( $column, $data ) { |
|
519 | + protected function prepare_column_where($column, $data) { |
|
520 | 520 | |
521 | 521 | // If a single value has been supplied for the column, it takes precedence. |
522 | - if ( isset( $this->args[ $column ] ) ) { |
|
523 | - $this->prepare_column( $column, $data ); |
|
524 | - } elseif ( isset( $this->args[ "{$column}__in" ] ) ) { |
|
525 | - $this->prepare_column__in( $column, $data ); |
|
526 | - } elseif ( isset( $this->args[ "{$column}__not_in" ] ) ) { |
|
527 | - $this->prepare_column__in( $column, $data, 'NOT IN' ); |
|
522 | + if (isset($this->args[$column])) { |
|
523 | + $this->prepare_column($column, $data); |
|
524 | + } elseif (isset($this->args["{$column}__in"])) { |
|
525 | + $this->prepare_column__in($column, $data); |
|
526 | + } elseif (isset($this->args["{$column}__not_in"])) { |
|
527 | + $this->prepare_column__in($column, $data, 'NOT IN'); |
|
528 | 528 | } |
529 | 529 | } |
530 | 530 | |
@@ -536,29 +536,29 @@ discard block |
||
536 | 536 | * @param string $column The name of the column |
537 | 537 | * @param array $data The column data. |
538 | 538 | */ |
539 | - protected function prepare_column( $column, $data ) { |
|
539 | + protected function prepare_column($column, $data) { |
|
540 | 540 | |
541 | 541 | global $wpdb; |
542 | 542 | |
543 | 543 | if ( |
544 | - isset( $data['values'] ) |
|
545 | - && ! in_array( $this->args[ $column ], $data['values'], true ) |
|
544 | + isset($data['values']) |
|
545 | + && ! in_array($this->args[$column], $data['values'], true) |
|
546 | 546 | ) { |
547 | 547 | return; |
548 | 548 | } |
549 | 549 | |
550 | 550 | $value = $this->validate_value( |
551 | - $this->args[ $column ] |
|
552 | - , $this->get_validators_for_column( $data ) |
|
551 | + $this->args[$column] |
|
552 | + , $this->get_validators_for_column($data) |
|
553 | 553 | ); |
554 | 554 | |
555 | - if ( false === $value ) { |
|
555 | + if (false === $value) { |
|
556 | 556 | return; |
557 | 557 | } |
558 | 558 | |
559 | - $compare = $this->get_comparator_for_column( $column, $data ); |
|
559 | + $compare = $this->get_comparator_for_column($column, $data); |
|
560 | 560 | |
561 | - $column = wordpoints_escape_mysql_identifier( $column ); |
|
561 | + $column = wordpoints_escape_mysql_identifier($column); |
|
562 | 562 | |
563 | 563 | $this->wheres[] = $wpdb->prepare( // WPCS: unprepared SQL OK. |
564 | 564 | "{$column} {$compare} {$data['format']}" |
@@ -576,23 +576,23 @@ discard block |
||
576 | 576 | * |
577 | 577 | * @return string The comparator for the column. |
578 | 578 | */ |
579 | - protected function get_comparator_for_column( $column, $data ) { |
|
579 | + protected function get_comparator_for_column($column, $data) { |
|
580 | 580 | |
581 | - $comparisons = array( '=', '<', '>', '<>', '!=', '<=', '>=' ); |
|
581 | + $comparisons = array('=', '<', '>', '<>', '!=', '<=', '>='); |
|
582 | 582 | |
583 | 583 | // MySQL doesn't support LIKE and NOT LIKE for int columns. |
584 | 584 | // See http://stackoverflow.com/q/8422455/1924128 |
585 | - if ( '%s' === $data['format'] ) { |
|
586 | - $comparisons = array_merge( $comparisons, array( 'LIKE', 'NOT LIKE' ) ); |
|
585 | + if ('%s' === $data['format']) { |
|
586 | + $comparisons = array_merge($comparisons, array('LIKE', 'NOT LIKE')); |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | $comparator = '='; |
590 | 590 | |
591 | 591 | if ( |
592 | - isset( $this->args[ "{$column}__compare" ] ) |
|
593 | - && in_array( $this->args[ "{$column}__compare" ], $comparisons, true ) |
|
592 | + isset($this->args["{$column}__compare"]) |
|
593 | + && in_array($this->args["{$column}__compare"], $comparisons, true) |
|
594 | 594 | ) { |
595 | - $comparator = $this->args[ "{$column}__compare" ]; |
|
595 | + $comparator = $this->args["{$column}__compare"]; |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | return $comparator; |
@@ -607,36 +607,36 @@ discard block |
||
607 | 607 | * @param array $data The column data. |
608 | 608 | * @param string $type The type of IN clause, IN or NOT IN. |
609 | 609 | */ |
610 | - protected function prepare_column__in( $column, $data, $type = 'IN' ) { |
|
610 | + protected function prepare_column__in($column, $data, $type = 'IN') { |
|
611 | 611 | |
612 | - $key = "{$column}__" . strtolower( str_replace( ' ', '_', $type ) ); |
|
612 | + $key = "{$column}__".strtolower(str_replace(' ', '_', $type)); |
|
613 | 613 | |
614 | - if ( empty( $this->args[ $key ] ) || ! is_array( $this->args[ $key ] ) ) { |
|
614 | + if (empty($this->args[$key]) || ! is_array($this->args[$key])) { |
|
615 | 615 | return; |
616 | 616 | } |
617 | 617 | |
618 | - $values = $this->args[ $key ]; |
|
618 | + $values = $this->args[$key]; |
|
619 | 619 | |
620 | - if ( isset( $data['values'] ) ) { |
|
621 | - $values = array_intersect( $values, $data['values'] ); |
|
620 | + if (isset($data['values'])) { |
|
621 | + $values = array_intersect($values, $data['values']); |
|
622 | 622 | } else { |
623 | 623 | $values = $this->validate_values( |
624 | 624 | $values |
625 | - , $this->get_validators_for_column( $data ) |
|
625 | + , $this->get_validators_for_column($data) |
|
626 | 626 | ); |
627 | 627 | } |
628 | 628 | |
629 | - if ( empty( $values ) ) { |
|
629 | + if (empty($values)) { |
|
630 | 630 | return; |
631 | 631 | } |
632 | 632 | |
633 | - $in = wordpoints_prepare__in( $values, $data['format'] ); |
|
633 | + $in = wordpoints_prepare__in($values, $data['format']); |
|
634 | 634 | |
635 | - if ( false === $in ) { |
|
635 | + if (false === $in) { |
|
636 | 636 | return; |
637 | 637 | } |
638 | 638 | |
639 | - $column = wordpoints_escape_mysql_identifier( $column ); |
|
639 | + $column = wordpoints_escape_mysql_identifier($column); |
|
640 | 640 | |
641 | 641 | $this->wheres[] = "{$column} {$type} ({$in})"; |
642 | 642 | } |
@@ -650,19 +650,19 @@ discard block |
||
650 | 650 | |
651 | 651 | $this->wheres = array(); |
652 | 652 | |
653 | - foreach ( $this->columns as $column => $data ) { |
|
653 | + foreach ($this->columns as $column => $data) { |
|
654 | 654 | |
655 | - if ( ! empty( $data['is_date'] ) ) { |
|
656 | - $this->prepare_date_where( $column ); |
|
655 | + if ( ! empty($data['is_date'])) { |
|
656 | + $this->prepare_date_where($column); |
|
657 | 657 | } else { |
658 | - $this->prepare_column_where( $column, $data ); |
|
658 | + $this->prepare_column_where($column, $data); |
|
659 | 659 | } |
660 | 660 | } |
661 | 661 | |
662 | 662 | $this->prepare_meta_where(); |
663 | 663 | |
664 | - if ( ! empty( $this->wheres ) ) { |
|
665 | - $this->where = 'WHERE ' . implode( ' AND ', $this->wheres ) . "\n"; |
|
664 | + if ( ! empty($this->wheres)) { |
|
665 | + $this->where = 'WHERE '.implode(' AND ', $this->wheres)."\n"; |
|
666 | 666 | } |
667 | 667 | } |
668 | 668 | |
@@ -675,32 +675,32 @@ discard block |
||
675 | 675 | |
676 | 676 | // MySQL doesn't allow for the offset without a limit, so if no limit is set |
677 | 677 | // we can ignore the start arg. See http://stackoverflow.com/a/271650/1924128 |
678 | - if ( ! isset( $this->args['limit'] ) ) { |
|
678 | + if ( ! isset($this->args['limit'])) { |
|
679 | 679 | return; |
680 | 680 | } |
681 | 681 | |
682 | - foreach ( array( 'limit', 'start' ) as $key ) { |
|
682 | + foreach (array('limit', 'start') as $key) { |
|
683 | 683 | |
684 | 684 | // Save a backup of the arg value since wordpoints_int() is by reference. |
685 | - $arg = $this->args[ $key ]; |
|
685 | + $arg = $this->args[$key]; |
|
686 | 686 | |
687 | - if ( false === wordpoints_int( $this->args[ $key ] ) ) { |
|
687 | + if (false === wordpoints_int($this->args[$key])) { |
|
688 | 688 | |
689 | 689 | _doing_it_wrong( |
690 | 690 | __METHOD__ |
691 | 691 | , sprintf( |
692 | 692 | "WordPoints Debug Error: '%s' must be a positive integer, %s given" |
693 | - , esc_html( $key ) |
|
694 | - , esc_html( strval( $arg ) ? $arg : gettype( $arg ) ) |
|
693 | + , esc_html($key) |
|
694 | + , esc_html(strval($arg) ? $arg : gettype($arg)) |
|
695 | 695 | ) |
696 | 696 | , '1.0.0' |
697 | 697 | ); |
698 | 698 | |
699 | - $this->args[ $key ] = 0; |
|
699 | + $this->args[$key] = 0; |
|
700 | 700 | } |
701 | 701 | } |
702 | 702 | |
703 | - if ( $this->args['limit'] > 0 && $this->args['start'] >= 0 ) { |
|
703 | + if ($this->args['limit'] > 0 && $this->args['start'] >= 0) { |
|
704 | 704 | $this->limit = "LIMIT {$this->args['start']}, {$this->args['limit']}"; |
705 | 705 | } |
706 | 706 | } |
@@ -712,20 +712,20 @@ discard block |
||
712 | 712 | */ |
713 | 713 | protected function prepare_order_by() { |
714 | 714 | |
715 | - if ( empty( $this->args['order_by'] ) ) { |
|
715 | + if (empty($this->args['order_by'])) { |
|
716 | 716 | return; |
717 | 717 | } |
718 | 718 | |
719 | 719 | $order = $this->args['order']; |
720 | 720 | $order_by = $this->args['order_by']; |
721 | 721 | |
722 | - if ( ! in_array( $order, array( 'DESC', 'ASC' ) ) ) { |
|
722 | + if ( ! in_array($order, array('DESC', 'ASC'))) { |
|
723 | 723 | |
724 | - _doing_it_wrong( __METHOD__, esc_html( "WordPoints Debug Error: invalid 'order' \"{$order}\", possible values are DESC and ASC" ), '1.0.0' ); |
|
724 | + _doing_it_wrong(__METHOD__, esc_html("WordPoints Debug Error: invalid 'order' \"{$order}\", possible values are DESC and ASC"), '1.0.0'); |
|
725 | 725 | $order = 'DESC'; |
726 | 726 | } |
727 | 727 | |
728 | - if ( 'meta_value' === $order_by ) { |
|
728 | + if ('meta_value' === $order_by) { |
|
729 | 729 | |
730 | 730 | global $wpdb; |
731 | 731 | |
@@ -733,9 +733,9 @@ discard block |
||
733 | 733 | $wpdb->{"{$this->meta_type}meta"} |
734 | 734 | ); |
735 | 735 | |
736 | - if ( isset( $this->args['meta_type'] ) ) { |
|
736 | + if (isset($this->args['meta_type'])) { |
|
737 | 737 | |
738 | - $meta_type = $this->meta_query->get_cast_for_type( $this->args['meta_type'] ); |
|
738 | + $meta_type = $this->meta_query->get_cast_for_type($this->args['meta_type']); |
|
739 | 739 | $order_by = "CAST({$meta_table_name}.meta_value AS {$meta_type})"; |
740 | 740 | |
741 | 741 | } else { |
@@ -743,13 +743,13 @@ discard block |
||
743 | 743 | $order_by = "{$meta_table_name}.meta_value"; |
744 | 744 | } |
745 | 745 | |
746 | - } elseif ( isset( $this->columns[ $order_by ] ) ) { |
|
746 | + } elseif (isset($this->columns[$order_by])) { |
|
747 | 747 | |
748 | - $order_by = wordpoints_escape_mysql_identifier( $order_by ); |
|
748 | + $order_by = wordpoints_escape_mysql_identifier($order_by); |
|
749 | 749 | |
750 | 750 | } else { |
751 | 751 | |
752 | - _doing_it_wrong( __METHOD__, esc_html( "WordPoints Debug Error: invalid 'order_by' \"{$order_by}\", possible values are " . implode( ', ', array_keys( $this->columns ) ) ), '1.0.0' ); |
|
752 | + _doing_it_wrong(__METHOD__, esc_html("WordPoints Debug Error: invalid 'order_by' \"{$order_by}\", possible values are ".implode(', ', array_keys($this->columns))), '1.0.0'); |
|
753 | 753 | return; |
754 | 754 | } |
755 | 755 | |
@@ -763,25 +763,25 @@ discard block |
||
763 | 763 | * |
764 | 764 | * @param string $column The name of the column. |
765 | 765 | */ |
766 | - protected function prepare_date_where( $column ) { |
|
766 | + protected function prepare_date_where($column) { |
|
767 | 767 | |
768 | 768 | if ( |
769 | - empty( $this->args[ "{$column}_query" ] ) |
|
770 | - || ! is_array( $this->args[ "{$column}_query" ] ) |
|
769 | + empty($this->args["{$column}_query"]) |
|
770 | + || ! is_array($this->args["{$column}_query"]) |
|
771 | 771 | ) { |
772 | 772 | return; |
773 | 773 | } |
774 | 774 | |
775 | - add_filter( 'date_query_valid_columns', array( $this, 'date_query_valid_columns_filter' ) ); |
|
775 | + add_filter('date_query_valid_columns', array($this, 'date_query_valid_columns_filter')); |
|
776 | 776 | |
777 | - $date_query = new WP_Date_Query( $this->args[ "{$column}_query" ], $column ); |
|
777 | + $date_query = new WP_Date_Query($this->args["{$column}_query"], $column); |
|
778 | 778 | $date_query = $date_query->get_sql(); |
779 | 779 | |
780 | - if ( ! empty( $date_query ) ) { |
|
781 | - $this->wheres[] = ltrim( $date_query, ' AND' ); |
|
780 | + if ( ! empty($date_query)) { |
|
781 | + $this->wheres[] = ltrim($date_query, ' AND'); |
|
782 | 782 | } |
783 | 783 | |
784 | - remove_filter( 'date_query_valid_columns', array( $this, 'date_query_valid_columns_filter' ) ); |
|
784 | + remove_filter('date_query_valid_columns', array($this, 'date_query_valid_columns_filter')); |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | /** |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | */ |
792 | 792 | protected function prepare_meta_where() { |
793 | 793 | |
794 | - if ( empty( $this->meta_type ) ) { |
|
794 | + if (empty($this->meta_type)) { |
|
795 | 795 | return; |
796 | 796 | } |
797 | 797 | |
@@ -806,12 +806,12 @@ discard block |
||
806 | 806 | ) |
807 | 807 | ); |
808 | 808 | |
809 | - if ( empty( $meta_args ) ) { |
|
809 | + if (empty($meta_args)) { |
|
810 | 810 | return; |
811 | 811 | } |
812 | 812 | |
813 | 813 | $this->meta_query = new WP_Meta_Query(); |
814 | - $this->meta_query->parse_query_vars( $meta_args ); |
|
814 | + $this->meta_query->parse_query_vars($meta_args); |
|
815 | 815 | |
816 | 816 | $meta_query = $this->meta_query->get_sql( |
817 | 817 | $this->meta_type |
@@ -820,11 +820,11 @@ discard block |
||
820 | 820 | , $this |
821 | 821 | ); |
822 | 822 | |
823 | - if ( ! empty( $meta_query['where'] ) ) { |
|
824 | - $this->wheres[] = ltrim( $meta_query['where'], ' AND' ); |
|
823 | + if ( ! empty($meta_query['where'])) { |
|
824 | + $this->wheres[] = ltrim($meta_query['where'], ' AND'); |
|
825 | 825 | } |
826 | 826 | |
827 | - $this->meta_join = $meta_query['join'] . "\n"; |
|
827 | + $this->meta_join = $meta_query['join']."\n"; |
|
828 | 828 | } |
829 | 829 | } |
830 | 830 |
@@ -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; |
@@ -63,22 +63,22 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @param WordPoints_Hook_Arg[] $args The hook args. |
65 | 65 | */ |
66 | - public function __construct( array $args ) { |
|
66 | + public function __construct(array $args) { |
|
67 | 67 | |
68 | 68 | parent::__construct(); |
69 | 69 | |
70 | - foreach ( $args as $arg ) { |
|
70 | + foreach ($args as $arg) { |
|
71 | 71 | |
72 | 72 | $entity = $arg->get_entity(); |
73 | 73 | $slug = $arg->get_slug(); |
74 | 74 | |
75 | - if ( ! $entity instanceof WordPoints_Entity ) { |
|
75 | + if ( ! $entity instanceof WordPoints_Entity) { |
|
76 | 76 | continue; |
77 | 77 | } |
78 | 78 | |
79 | - $this->entities[ $slug ] = $entity; |
|
79 | + $this->entities[$slug] = $entity; |
|
80 | 80 | |
81 | - if ( ! $arg->is_stateful() ) { |
|
81 | + if ( ! $arg->is_stateful()) { |
|
82 | 82 | // If any of the args aren't stateful the event isn't repeatable. |
83 | 83 | $this->is_repeatable = false; |
84 | 84 | $this->primary_arg_slug = $slug; |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function get_primary_arg() { |
116 | 116 | |
117 | - if ( ! $this->primary_arg_slug ) { |
|
117 | + if ( ! $this->primary_arg_slug) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | - return $this->entities[ $this->primary_arg_slug ]; |
|
121 | + return $this->entities[$this->primary_arg_slug]; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | |
133 | 133 | $stateful = $this->entities; |
134 | 134 | |
135 | - if ( $this->primary_arg_slug ) { |
|
136 | - unset( $stateful[ $this->primary_arg_slug ] ); |
|
135 | + if ($this->primary_arg_slug) { |
|
136 | + unset($stateful[$this->primary_arg_slug]); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $stateful; |
@@ -157,47 +157,47 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param WordPoints_Hook_Reaction_Validator $validator The validator. |
159 | 159 | */ |
160 | - public function set_validator( WordPoints_Hook_Reaction_Validator $validator ) { |
|
160 | + public function set_validator(WordPoints_Hook_Reaction_Validator $validator) { |
|
161 | 161 | $this->validator = $validator; |
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * @since 1.0.0 |
166 | 166 | */ |
167 | - public function descend( $child_slug ) { |
|
167 | + public function descend($child_slug) { |
|
168 | 168 | |
169 | - $result = parent::descend( $child_slug ); |
|
169 | + $result = parent::descend($child_slug); |
|
170 | 170 | |
171 | 171 | // Just in case no validator has been set. |
172 | - if ( ! $this->validator ) { |
|
172 | + if ( ! $this->validator) { |
|
173 | 173 | return $result; |
174 | 174 | } |
175 | 175 | |
176 | - if ( ! $result ) { |
|
176 | + if ( ! $result) { |
|
177 | 177 | |
178 | - if ( ! isset( $this->current ) ) { |
|
178 | + if ( ! isset($this->current)) { |
|
179 | 179 | |
180 | 180 | $this->validator->add_error( |
181 | 181 | sprintf( |
182 | - __( 'The %s arg is not registered for this event.', 'wordpoints' ) // TODO message |
|
182 | + __('The %s arg is not registered for this event.', 'wordpoints') // TODO message |
|
183 | 183 | , $child_slug |
184 | 184 | ) |
185 | 185 | ); |
186 | 186 | |
187 | - } elseif ( ! ( $this->current instanceof WordPoints_Entity_ParentI ) ) { |
|
187 | + } elseif ( ! ($this->current instanceof WordPoints_Entity_ParentI)) { |
|
188 | 188 | |
189 | 189 | $this->validator->add_error( |
190 | - __( 'Cannot get descendant of %s: not a parent.', 'wordpoints' ) // TODO message |
|
190 | + __('Cannot get descendant of %s: not a parent.', 'wordpoints') // TODO message |
|
191 | 191 | ); |
192 | 192 | |
193 | 193 | } else { |
194 | 194 | |
195 | - $child_arg = $this->current->get_child( $child_slug ); |
|
195 | + $child_arg = $this->current->get_child($child_slug); |
|
196 | 196 | |
197 | - if ( ! $child_arg ) { |
|
197 | + if ( ! $child_arg) { |
|
198 | 198 | $this->validator->add_error( |
199 | 199 | sprintf( |
200 | - __( '%s does not have a child "%s".', 'wordpoints' ) // TODO message |
|
200 | + __('%s does not have a child "%s".', 'wordpoints') // TODO message |
|
201 | 201 | , $this->current->get_slug() |
202 | 202 | , $child_slug |
203 | 203 | ) |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
209 | - } elseif ( $this->push_on_descend ) { |
|
209 | + } elseif ($this->push_on_descend) { |
|
210 | 210 | |
211 | - $this->validator->push_field( $child_slug ); |
|
211 | + $this->validator->push_field($child_slug); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | return $result; |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | |
222 | 222 | $ascended = parent::ascend(); |
223 | 223 | |
224 | - if ( $ascended && $this->validator ) { |
|
224 | + if ($ascended && $this->validator) { |
|
225 | 225 | $this->validator->pop_field(); |
226 | 226 | } |
227 | 227 | |
@@ -231,10 +231,10 @@ discard block |
||
231 | 231 | /** |
232 | 232 | * @since 1.0.0 |
233 | 233 | */ |
234 | - public function get_from_hierarchy( array $hierarchy ) { |
|
234 | + public function get_from_hierarchy(array $hierarchy) { |
|
235 | 235 | |
236 | 236 | $this->push_on_descend = false; |
237 | - $entityish = parent::get_from_hierarchy( $hierarchy ); |
|
237 | + $entityish = parent::get_from_hierarchy($hierarchy); |
|
238 | 238 | $this->push_on_descend = true; |
239 | 239 | |
240 | 240 | return $entityish; |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | WordPoints_Hook_Event_Args $event_args |
66 | 66 | ) { |
67 | 67 | |
68 | - if ( ! isset( $settings[ $this->slug ] ) ) { |
|
68 | + if ( ! isset($settings[$this->slug])) { |
|
69 | 69 | return $settings; |
70 | 70 | } |
71 | 71 | |
72 | - if ( ! is_array( $settings[ $this->slug ] ) ) { |
|
72 | + if ( ! is_array($settings[$this->slug])) { |
|
73 | 73 | |
74 | 74 | $validator->add_error( |
75 | - __( 'Invalid settings format.', 'wordpoints' ) |
|
75 | + __('Invalid settings format.', 'wordpoints') |
|
76 | 76 | , $this->slug |
77 | 77 | ); |
78 | 78 | |
@@ -82,13 +82,13 @@ discard block |
||
82 | 82 | $this->validator = $validator; |
83 | 83 | $this->event_args = $event_args; |
84 | 84 | |
85 | - $this->validator->push_field( $this->slug ); |
|
85 | + $this->validator->push_field($this->slug); |
|
86 | 86 | |
87 | - foreach ( $settings[ $this->slug ] as $action_type => $action_type_settings ) { |
|
87 | + foreach ($settings[$this->slug] as $action_type => $action_type_settings) { |
|
88 | 88 | |
89 | - $this->validator->push_field( $action_type ); |
|
89 | + $this->validator->push_field($action_type); |
|
90 | 90 | |
91 | - $settings[ $this->slug ][ $action_type ] = $this->validate_action_type_settings( |
|
91 | + $settings[$this->slug][$action_type] = $this->validate_action_type_settings( |
|
92 | 92 | $action_type_settings |
93 | 93 | ); |
94 | 94 | |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | /** |
104 | 104 | * @since 1.0.0 |
105 | 105 | */ |
106 | - public function update_settings( WordPoints_Hook_ReactionI $reaction, array $settings ) { |
|
106 | + public function update_settings(WordPoints_Hook_ReactionI $reaction, array $settings) { |
|
107 | 107 | |
108 | - if ( isset( $settings[ $this->slug ] ) ) { |
|
109 | - $reaction->update_meta( $this->slug, $settings[ $this->slug ] ); |
|
108 | + if (isset($settings[$this->slug])) { |
|
109 | + $reaction->update_meta($this->slug, $settings[$this->slug]); |
|
110 | 110 | } else { |
111 | - $reaction->delete_meta( $this->slug ); |
|
111 | + $reaction->delete_meta($this->slug); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return mixed The validated settings. |
123 | 123 | */ |
124 | - protected function validate_action_type_settings( $settings ) { |
|
124 | + protected function validate_action_type_settings($settings) { |
|
125 | 125 | return $settings; |
126 | 126 | } |
127 | 127 | |
@@ -138,16 +138,16 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return mixed The settings for the extension, or false if none. |
140 | 140 | */ |
141 | - protected function get_settings_from_fire( WordPoints_Hook_Fire $fire ) { |
|
141 | + protected function get_settings_from_fire(WordPoints_Hook_Fire $fire) { |
|
142 | 142 | |
143 | - $settings = $fire->reaction->get_meta( $this->slug ); |
|
143 | + $settings = $fire->reaction->get_meta($this->slug); |
|
144 | 144 | |
145 | - if ( ! is_array( $settings ) ) { |
|
145 | + if ( ! is_array($settings)) { |
|
146 | 146 | return $settings; |
147 | 147 | } |
148 | 148 | |
149 | - if ( isset( $settings[ $fire->action_type ] ) ) { |
|
150 | - return $settings[ $fire->action_type ]; |
|
149 | + if (isset($settings[$fire->action_type])) { |
|
150 | + return $settings[$fire->action_type]; |
|
151 | 151 | } else { |
152 | 152 | return false; |
153 | 153 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * |
163 | 163 | * @return bool Whether the target should be hit by this hook firing. |
164 | 164 | */ |
165 | - abstract public function should_hit( WordPoints_Hook_Fire $fire ); |
|
165 | + abstract public function should_hit(WordPoints_Hook_Fire $fire); |
|
166 | 166 | |
167 | 167 | /** |
168 | 168 | * After a reaction has hit the target. |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * |
172 | 172 | * @param WordPoints_Hook_Fire $fire The hook fire object. |
173 | 173 | */ |
174 | - public function after_hit( WordPoints_Hook_Fire $fire ) {} |
|
174 | + public function after_hit(WordPoints_Hook_Fire $fire) {} |
|
175 | 175 | |
176 | 176 | /** |
177 | 177 | * Get the data the scripts need for the UI. |