@@ -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,50 +157,50 @@ 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' ) |
|
182 | + __('The “%s” arg is not registered for this event.', 'wordpoints') |
|
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 | 190 | sprintf( |
191 | - __( 'Cannot get descendant of %s: not a parent.', 'wordpoints' ) |
|
191 | + __('Cannot get descendant of %s: not a parent.', 'wordpoints') |
|
192 | 192 | , $this->current->get_title() |
193 | 193 | ) |
194 | 194 | ); |
195 | 195 | |
196 | 196 | } else { |
197 | 197 | |
198 | - $child_arg = $this->current->get_child( $child_slug ); |
|
198 | + $child_arg = $this->current->get_child($child_slug); |
|
199 | 199 | |
200 | - if ( ! $child_arg ) { |
|
200 | + if ( ! $child_arg) { |
|
201 | 201 | $this->validator->add_error( |
202 | 202 | sprintf( |
203 | - __( '%s does not have a child “%s”.', 'wordpoints' ) |
|
203 | + __('%s does not have a child “%s”.', 'wordpoints') |
|
204 | 204 | , $this->current->get_slug() |
205 | 205 | , $child_slug |
206 | 206 | ) |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
212 | - } elseif ( $this->push_on_descend ) { |
|
212 | + } elseif ($this->push_on_descend) { |
|
213 | 213 | |
214 | - $this->validator->push_field( $child_slug ); |
|
214 | + $this->validator->push_field($child_slug); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | return $result; |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | |
225 | 225 | $ascended = parent::ascend(); |
226 | 226 | |
227 | - if ( $ascended && $this->validator ) { |
|
227 | + if ($ascended && $this->validator) { |
|
228 | 228 | $this->validator->pop_field(); |
229 | 229 | } |
230 | 230 | |
@@ -234,10 +234,10 @@ discard block |
||
234 | 234 | /** |
235 | 235 | * @since 1.0.0 |
236 | 236 | */ |
237 | - public function get_from_hierarchy( array $hierarchy ) { |
|
237 | + public function get_from_hierarchy(array $hierarchy) { |
|
238 | 238 | |
239 | 239 | $this->push_on_descend = false; |
240 | - $entityish = parent::get_from_hierarchy( $hierarchy ); |
|
240 | + $entityish = parent::get_from_hierarchy($hierarchy); |
|
241 | 241 | $this->push_on_descend = true; |
242 | 242 | |
243 | 243 | 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 |
@@ -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 |
@@ -7,25 +7,25 @@ |
||
7 | 7 | * @since 1.0.0 |
8 | 8 | */ |
9 | 9 | |
10 | -add_action( 'wordpoints_init_app-apps', 'wordpoints_apps_init' ); |
|
11 | -add_action( 'wordpoints_init_app-entities', 'wordpoints_entities_app_init' ); |
|
10 | +add_action('wordpoints_init_app-apps', 'wordpoints_apps_init'); |
|
11 | +add_action('wordpoints_init_app-entities', 'wordpoints_entities_app_init'); |
|
12 | 12 | |
13 | -add_action( 'wordpoints_init_app_registry-apps-entities', 'wordpoints_entities_init' ); |
|
14 | -add_action( 'wordpoints_init_app_registry-entities-contexts', 'wordpoints_entity_contexts_init' ); |
|
13 | +add_action('wordpoints_init_app_registry-apps-entities', 'wordpoints_entities_init'); |
|
14 | +add_action('wordpoints_init_app_registry-entities-contexts', 'wordpoints_entity_contexts_init'); |
|
15 | 15 | |
16 | -add_action( 'wordpoints_init_app_registry-apps-data_types', 'wordpoints_data_types_init' ); |
|
16 | +add_action('wordpoints_init_app_registry-apps-data_types', 'wordpoints_data_types_init'); |
|
17 | 17 | |
18 | -add_action( 'wordpoints_init_app_registry-hooks-events', 'wordpoints_hook_events_init' ); |
|
19 | -add_action( 'wordpoints_init_app_registry-hooks-actions', 'wordpoints_hook_actions_init' ); |
|
20 | -add_action( 'wordpoints_init_app_registry-hooks-reactors', 'wordpoints_hook_reactors_init' ); |
|
21 | -add_action( 'wordpoints_init_app_registry-hooks-reaction_stores', 'wordpoints_hook_reaction_stores_init' ); |
|
22 | -add_action( 'wordpoints_init_app_registry-hooks-extensions', 'wordpoints_hook_extension_init' ); |
|
23 | -add_action( 'wordpoints_init_app_registry-hooks-conditions', 'wordpoints_hook_conditions_init' ); |
|
18 | +add_action('wordpoints_init_app_registry-hooks-events', 'wordpoints_hook_events_init'); |
|
19 | +add_action('wordpoints_init_app_registry-hooks-actions', 'wordpoints_hook_actions_init'); |
|
20 | +add_action('wordpoints_init_app_registry-hooks-reactors', 'wordpoints_hook_reactors_init'); |
|
21 | +add_action('wordpoints_init_app_registry-hooks-reaction_stores', 'wordpoints_hook_reaction_stores_init'); |
|
22 | +add_action('wordpoints_init_app_registry-hooks-extensions', 'wordpoints_hook_extension_init'); |
|
23 | +add_action('wordpoints_init_app_registry-hooks-conditions', 'wordpoints_hook_conditions_init'); |
|
24 | 24 | |
25 | -add_action( 'wordpoints_modules_loaded', 'wordpoints_init_hooks' ); |
|
25 | +add_action('wordpoints_modules_loaded', 'wordpoints_init_hooks'); |
|
26 | 26 | |
27 | -add_action( 'init', 'wordpoints_hooks_api_add_global_cache_groups', 5 ); |
|
27 | +add_action('init', 'wordpoints_hooks_api_add_global_cache_groups', 5); |
|
28 | 28 | |
29 | -add_filter( 'wordpoints_user_can_view_points_log', 'wordpoints_hooks_user_can_view_points_log' ); |
|
29 | +add_filter('wordpoints_user_can_view_points_log', 'wordpoints_hooks_user_can_view_points_log'); |
|
30 | 30 | |
31 | 31 | // EOF |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | ) { |
101 | 101 | |
102 | 102 | return 'wordpoints_create_hook_reaction|' . $reaction_store->get_slug() |
103 | - . '|' . wordpoints_hooks()->get_current_mode() |
|
104 | - . '|' . wp_json_encode( $reaction_store->get_context_id() ); |
|
103 | + . '|' . wordpoints_hooks()->get_current_mode() |
|
104 | + . '|' . wp_json_encode( $reaction_store->get_context_id() ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | WordPoints_Hook_ReactionI $reaction |
132 | 132 | ) { |
133 | 133 | return 'wordpoints_update_hook_reaction|' |
134 | - . wp_json_encode( $reaction->get_guid() ); |
|
134 | + . wp_json_encode( $reaction->get_guid() ); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | WordPoints_Hook_ReactionI $reaction |
162 | 162 | ) { |
163 | 163 | return 'wordpoints_delete_hook_reaction|' |
164 | - . wp_json_encode( $reaction->get_guid() ); |
|
164 | + . wp_json_encode( $reaction->get_guid() ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return array The hook reaction data extracted into an array. |
54 | 54 | */ |
55 | - public static function prepare_hook_reaction( WordPoints_Hook_ReactionI $reaction ) { |
|
55 | + public static function prepare_hook_reaction(WordPoints_Hook_ReactionI $reaction) { |
|
56 | 56 | |
57 | 57 | return array_merge( |
58 | 58 | $reaction->get_all_meta() |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | 'id' => $reaction->ID, |
61 | 61 | 'event' => $reaction->get_event_slug(), |
62 | 62 | 'reaction_store' => $reaction->get_store_slug(), |
63 | - 'nonce' => self::get_update_nonce( $reaction ), |
|
64 | - 'delete_nonce' => self::get_delete_nonce( $reaction ), |
|
63 | + 'nonce' => self::get_update_nonce($reaction), |
|
64 | + 'delete_nonce' => self::get_delete_nonce($reaction), |
|
65 | 65 | ) |
66 | 66 | ); |
67 | 67 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | WordPoints_Hook_Reaction_StoreI $reaction_store |
82 | 82 | ) { |
83 | 83 | |
84 | - return wp_create_nonce( self::get_create_nonce_action( $reaction_store ) ); |
|
84 | + return wp_create_nonce(self::get_create_nonce_action($reaction_store)); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | WordPoints_Hook_Reaction_StoreI $reaction_store |
100 | 100 | ) { |
101 | 101 | |
102 | - return 'wordpoints_create_hook_reaction|' . $reaction_store->get_slug() |
|
103 | - . '|' . wordpoints_hooks()->get_current_mode() |
|
104 | - . '|' . wp_json_encode( $reaction_store->get_context_id() ); |
|
102 | + return 'wordpoints_create_hook_reaction|'.$reaction_store->get_slug() |
|
103 | + . '|'.wordpoints_hooks()->get_current_mode() |
|
104 | + . '|'.wp_json_encode($reaction_store->get_context_id()); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return string A nonce for updating this reaction. |
115 | 115 | */ |
116 | - public static function get_update_nonce( WordPoints_Hook_ReactionI $reaction ) { |
|
116 | + public static function get_update_nonce(WordPoints_Hook_ReactionI $reaction) { |
|
117 | 117 | |
118 | - return wp_create_nonce( self::get_update_nonce_action( $reaction ) ); |
|
118 | + return wp_create_nonce(self::get_update_nonce_action($reaction)); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | WordPoints_Hook_ReactionI $reaction |
132 | 132 | ) { |
133 | 133 | return 'wordpoints_update_hook_reaction|' |
134 | - . wp_json_encode( $reaction->get_guid() ); |
|
134 | + . wp_json_encode($reaction->get_guid()); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @return string A nonce for deleting this reaction. |
145 | 145 | */ |
146 | - public static function get_delete_nonce( WordPoints_Hook_ReactionI $reaction ) { |
|
146 | + public static function get_delete_nonce(WordPoints_Hook_ReactionI $reaction) { |
|
147 | 147 | |
148 | - return wp_create_nonce( self::get_delete_nonce_action( $reaction ) ); |
|
148 | + return wp_create_nonce(self::get_delete_nonce_action($reaction)); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | WordPoints_Hook_ReactionI $reaction |
162 | 162 | ) { |
163 | 163 | return 'wordpoints_delete_hook_reaction|' |
164 | - . wp_json_encode( $reaction->get_guid() ); |
|
164 | + . wp_json_encode($reaction->get_guid()); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // |
@@ -187,17 +187,17 @@ discard block |
||
187 | 187 | |
188 | 188 | add_action( |
189 | 189 | 'wp_ajax_wordpoints_admin_create_hook_reaction' |
190 | - , array( $this, 'create_hook_reaction' ) |
|
190 | + , array($this, 'create_hook_reaction') |
|
191 | 191 | ); |
192 | 192 | |
193 | 193 | add_action( |
194 | 194 | 'wp_ajax_wordpoints_admin_update_hook_reaction' |
195 | - , array( $this, 'update_hook_reaction' ) |
|
195 | + , array($this, 'update_hook_reaction') |
|
196 | 196 | ); |
197 | 197 | |
198 | 198 | add_action( |
199 | 199 | 'wp_ajax_wordpoints_admin_delete_hook_reaction' |
200 | - , array( $this, 'delete_hook_reaction' ) |
|
200 | + , array($this, 'delete_hook_reaction') |
|
201 | 201 | ); |
202 | 202 | } |
203 | 203 | |
@@ -212,11 +212,11 @@ discard block |
||
212 | 212 | |
213 | 213 | $reaction_store = $this->get_reaction_store(); |
214 | 214 | |
215 | - $this->verify_request( $this->get_create_nonce_action( $reaction_store ) ); |
|
215 | + $this->verify_request($this->get_create_nonce_action($reaction_store)); |
|
216 | 216 | |
217 | - $reaction = $reaction_store->create_reaction( $this->get_data() ); |
|
217 | + $reaction = $reaction_store->create_reaction($this->get_data()); |
|
218 | 218 | |
219 | - $this->send_json_result( $reaction, 'create' ); |
|
219 | + $this->send_json_result($reaction, 'create'); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -231,14 +231,14 @@ discard block |
||
231 | 231 | $reaction_store = $this->get_reaction_store(); |
232 | 232 | $reaction = $this->get_reaction(); |
233 | 233 | |
234 | - $this->verify_request( $this->get_update_nonce_action( $reaction ) ); |
|
234 | + $this->verify_request($this->get_update_nonce_action($reaction)); |
|
235 | 235 | |
236 | 236 | $reaction = $reaction_store->update_reaction( |
237 | 237 | $reaction->ID |
238 | 238 | , $this->get_data() |
239 | 239 | ); |
240 | 240 | |
241 | - $this->send_json_result( $reaction, 'update' ); |
|
241 | + $this->send_json_result($reaction, 'update'); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -253,12 +253,12 @@ discard block |
||
253 | 253 | $reaction_store = $this->get_reaction_store(); |
254 | 254 | $reaction = $this->get_reaction(); |
255 | 255 | |
256 | - $this->verify_request( $this->get_delete_nonce_action( $reaction ) ); |
|
256 | + $this->verify_request($this->get_delete_nonce_action($reaction)); |
|
257 | 257 | |
258 | - $result = $reaction_store->delete_reaction( $reaction->ID ); |
|
258 | + $result = $reaction_store->delete_reaction($reaction->ID); |
|
259 | 259 | |
260 | - if ( ! $result ) { |
|
261 | - wp_send_json_error( array( 'message' => __( 'There was an error deleting the reaction. Please try again.', 'wordpoints' ) ) ); |
|
260 | + if ( ! $result) { |
|
261 | + wp_send_json_error(array('message' => __('There was an error deleting the reaction. Please try again.', 'wordpoints'))); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | wp_send_json_success(); |
@@ -279,11 +279,11 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @param string $debug_context Context sent with the message (for debugging). |
281 | 281 | */ |
282 | - private function unexpected_error( $debug_context ) { |
|
282 | + private function unexpected_error($debug_context) { |
|
283 | 283 | |
284 | 284 | wp_send_json_error( |
285 | 285 | array( |
286 | - 'message' => __( 'There was an unexpected error. Try reloading the page.', 'wordpoints' ), |
|
286 | + 'message' => __('There was an unexpected error. Try reloading the page.', 'wordpoints'), |
|
287 | 287 | 'debug' => $debug_context, |
288 | 288 | ) |
289 | 289 | ); |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | */ |
300 | 300 | private function verify_user_can() { |
301 | 301 | |
302 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
303 | - wp_send_json_error( array( 'message' => __( 'You do not have permission to perform this action. Maybe you have been logged out?', 'wordpoints' ) ) ); |
|
302 | + if ( ! current_user_can('manage_options')) { |
|
303 | + wp_send_json_error(array('message' => __('You do not have permission to perform this action. Maybe you have been logged out?', 'wordpoints'))); |
|
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
@@ -313,14 +313,14 @@ discard block |
||
313 | 313 | * |
314 | 314 | * @param string $action The action the nonce should be for. |
315 | 315 | */ |
316 | - private function verify_request( $action ) { |
|
316 | + private function verify_request($action) { |
|
317 | 317 | |
318 | 318 | if ( |
319 | - empty( $_POST['nonce'] ) |
|
320 | - || ! wordpoints_verify_nonce( 'nonce', $action, null, 'post' ) |
|
319 | + empty($_POST['nonce']) |
|
320 | + || ! wordpoints_verify_nonce('nonce', $action, null, 'post') |
|
321 | 321 | ) { |
322 | 322 | wp_send_json_error( |
323 | - array( 'message' => __( 'Your security token for this action has expired. Refresh the page and try again.', 'wordpoints' ) ) |
|
323 | + array('message' => __('Your security token for this action has expired. Refresh the page and try again.', 'wordpoints')) |
|
324 | 324 | ); |
325 | 325 | } |
326 | 326 | } |
@@ -334,16 +334,16 @@ discard block |
||
334 | 334 | */ |
335 | 335 | protected function get_reaction_store() { |
336 | 336 | |
337 | - if ( ! isset( $_POST['reaction_store'] ) ) { // WPCS: CSRF OK. |
|
338 | - $this->unexpected_error( 'reaction_store' ); |
|
337 | + if ( ! isset($_POST['reaction_store'])) { // WPCS: CSRF OK. |
|
338 | + $this->unexpected_error('reaction_store'); |
|
339 | 339 | } |
340 | 340 | |
341 | - $reactor_slug = sanitize_key( $_POST['reaction_store'] ); // WPCS: CSRF OK. |
|
341 | + $reactor_slug = sanitize_key($_POST['reaction_store']); // WPCS: CSRF OK. |
|
342 | 342 | |
343 | - $reaction_store = wordpoints_hooks()->get_reaction_store( $reactor_slug ); |
|
343 | + $reaction_store = wordpoints_hooks()->get_reaction_store($reactor_slug); |
|
344 | 344 | |
345 | - if ( ! $reaction_store instanceof WordPoints_Hook_Reaction_StoreI ) { |
|
346 | - $this->unexpected_error( 'reaction_store_invalid' ); |
|
345 | + if ( ! $reaction_store instanceof WordPoints_Hook_Reaction_StoreI) { |
|
346 | + $this->unexpected_error('reaction_store_invalid'); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | $this->reaction_store_slug = $reactor_slug; |
@@ -361,16 +361,16 @@ discard block |
||
361 | 361 | */ |
362 | 362 | protected function get_reaction() { |
363 | 363 | |
364 | - if ( ! isset( $_POST['id'] ) ) { // WPCS: CSRF OK. |
|
365 | - $this->unexpected_error( 'id' ); |
|
364 | + if ( ! isset($_POST['id'])) { // WPCS: CSRF OK. |
|
365 | + $this->unexpected_error('id'); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | $reaction = $this->reaction_store->get_reaction( |
369 | - wordpoints_int( $_POST['id'] ) // WPCS: CSRF OK. |
|
369 | + wordpoints_int($_POST['id']) // WPCS: CSRF OK. |
|
370 | 370 | ); |
371 | 371 | |
372 | - if ( ! $reaction ) { |
|
373 | - wp_send_json_error( array( 'message' => __( 'The reaction ID passed to the server is invalid. Perhaps it has been deleted. Try reloading the page.', 'wordpoints' ) ) ); |
|
372 | + if ( ! $reaction) { |
|
373 | + wp_send_json_error(array('message' => __('The reaction ID passed to the server is invalid. Perhaps it has been deleted. Try reloading the page.', 'wordpoints'))); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | return $reaction; |
@@ -385,9 +385,9 @@ discard block |
||
385 | 385 | */ |
386 | 386 | protected function get_data() { |
387 | 387 | |
388 | - $data = wp_unslash( $_POST ); // WPCS: CSRF OK. |
|
388 | + $data = wp_unslash($_POST); // WPCS: CSRF OK. |
|
389 | 389 | |
390 | - unset( $data['id'], $data['action'], $data['nonce'], $data['reaction_store'] ); |
|
390 | + unset($data['id'], $data['action'], $data['nonce'], $data['reaction_store']); |
|
391 | 391 | |
392 | 392 | return $data; |
393 | 393 | } |
@@ -400,30 +400,30 @@ discard block |
||
400 | 400 | * @param mixed $result The result of the action. |
401 | 401 | * @param string $action The action being performed: 'create' or 'update'. |
402 | 402 | */ |
403 | - private function send_json_result( $result, $action ) { |
|
403 | + private function send_json_result($result, $action) { |
|
404 | 404 | |
405 | - if ( ! $result ) { |
|
405 | + if ( ! $result) { |
|
406 | 406 | |
407 | - if ( 'create' === $action ) { |
|
408 | - $message = __( 'There was an error adding the reaction. Please try again.', 'wordpoints' ); |
|
407 | + if ('create' === $action) { |
|
408 | + $message = __('There was an error adding the reaction. Please try again.', 'wordpoints'); |
|
409 | 409 | } else { |
410 | - $message = __( 'There was an error updating the reaction. Please try again.', 'wordpoints' ); |
|
410 | + $message = __('There was an error updating the reaction. Please try again.', 'wordpoints'); |
|
411 | 411 | } |
412 | 412 | |
413 | - wp_send_json_error( array( 'message' => $message ) ); |
|
413 | + wp_send_json_error(array('message' => $message)); |
|
414 | 414 | |
415 | - } elseif ( $result instanceof WordPoints_Hook_Reaction_Validator ) { |
|
415 | + } elseif ($result instanceof WordPoints_Hook_Reaction_Validator) { |
|
416 | 416 | |
417 | - wp_send_json_error( array( 'errors' => $result->get_errors() ) ); |
|
417 | + wp_send_json_error(array('errors' => $result->get_errors())); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | $data = null; |
421 | 421 | |
422 | - if ( 'create' === $action ) { |
|
423 | - $data = self::prepare_hook_reaction( $result ); |
|
422 | + if ('create' === $action) { |
|
423 | + $data = self::prepare_hook_reaction($result); |
|
424 | 424 | } |
425 | 425 | |
426 | - wp_send_json_success( $data ); |
|
426 | + wp_send_json_success($data); |
|
427 | 427 | } |
428 | 428 | } |
429 | 429 |