Passed
Push — master ( 63d34b...f710ce )
by Stiofan
27s
created
includes/class-wpinv-notes.php 1 patch
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -14,74 +14,74 @@  discard block
 block discarded – undo
14 14
     }
15 15
     
16 16
     public function init() {
17
-        do_action( 'wpinv_class_notes_init', $this );
17
+        do_action('wpinv_class_notes_init', $this);
18 18
     }
19 19
     
20 20
     public function includes() {
21
-        do_action( 'wpinv_class_notes_includes', $this );
21
+        do_action('wpinv_class_notes_includes', $this);
22 22
     }
23 23
     
24 24
     public function actions() {
25 25
         // Secure inovice notes
26
-        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
27
-        add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 );
26
+        add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
27
+        add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1);
28 28
         
29 29
         // Count comments
30
-        add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 );
30
+        add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2);
31 31
         
32 32
         // Delete comments count cache whenever there is a new comment or a comment status changes
33
-        add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
34
-        add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
33
+        add_action('wp_insert_comment', array($this, 'delete_comments_count_cache'));
34
+        add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache'));
35 35
         
36
-        do_action( 'wpinv_class_notes_actions', $this );
36
+        do_action('wpinv_class_notes_actions', $this);
37 37
     }
38 38
         
39
-    public function set_invoice_note_type( $query ) {
40
-        $post_ID        = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
39
+    public function set_invoice_note_type($query) {
40
+        $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
41 41
         
42
-        if ( $post_ID && in_array(get_post_type( $post_ID ), array($this->invoice_post_type, 'wpi_quote' )) ) {
42
+        if ($post_ID && in_array(get_post_type($post_ID), array($this->invoice_post_type, 'wpi_quote'))) {
43 43
             $query->query_vars['type__in']      = $this->comment_type;
44 44
             $query->query_vars['type__not_in']  = '';
45 45
         } else {        
46
-            if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) {
47
-                if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) {
48
-                    $key = array_search( $this->comment_type, $type_in );
49
-                    unset( $query->query_vars['type__in'][$key] );
50
-                } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) {
46
+            if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) {
47
+                if (is_array($type_in) && in_array($this->comment_type, $type_in)) {
48
+                    $key = array_search($this->comment_type, $type_in);
49
+                    unset($query->query_vars['type__in'][$key]);
50
+                } else if (!is_array($type_in) && $type_in == $this->comment_type) {
51 51
                     $query->query_vars['type__in'] = '';
52 52
                 }
53 53
             }
54 54
             
55
-            if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) {
56
-                if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) {
55
+            if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) {
56
+                if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) {
57 57
                     $query->query_vars['type__not_in'][] = $this->comment_type;
58
-                } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) {
58
+                } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) {
59 59
                     $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in'];
60 60
                     $query->query_vars['type__not_in'][] = $this->comment_type;
61 61
                 }
62 62
             } else {
63
-                $query->query_vars['type__not_in']  = $this->comment_type;
63
+                $query->query_vars['type__not_in'] = $this->comment_type;
64 64
             }
65 65
         }
66 66
         
67 67
         return $query;
68 68
     }
69 69
     
70
-    public function get_invoice_notes( $invoice_id = 0, $type = '' ) {
70
+    public function get_invoice_notes($invoice_id = 0, $type = '') {
71 71
         $args = array( 
72 72
             'post_id'   => $invoice_id,
73 73
             'orderby'   => 'comment_ID',
74 74
             'order'     => 'ASC',
75 75
         );
76 76
         
77
-        if ( $type == 'customer' ) {
77
+        if ($type == 'customer') {
78 78
             $args['meta_key']   = '_wpi_customer_note';
79 79
             $args['meta_value'] = 1;
80 80
         }
81 81
         
82
-        $args   = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
82
+        $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
83 83
         
84
-        return get_comments( $args );
84
+        return get_comments($args);
85 85
     }
86 86
     
87 87
     /**
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      * @return void
93 93
      */
94 94
     public function delete_comments_count_cache() {
95
-        delete_transient( 'wpinv_count_comments' );
95
+        delete_transient('wpinv_count_comments');
96 96
     }
97 97
     
98 98
     /**
@@ -103,16 +103,16 @@  discard block
 block discarded – undo
103 103
      * @param  int    $post_id Post ID.
104 104
      * @return object
105 105
      */
106
-    public function wp_count_comments( $stats, $post_id ) {
106
+    public function wp_count_comments($stats, $post_id) {
107 107
         global $wpdb;
108 108
 
109
-        if ( 0 === $post_id ) {
110
-            $stats = get_transient( 'wpinv_count_comments' );
109
+        if (0 === $post_id) {
110
+            $stats = get_transient('wpinv_count_comments');
111 111
 
112
-            if ( ! $stats ) {
112
+            if (!$stats) {
113 113
                 $stats = array();
114 114
 
115
-                $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A );
115
+                $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A);
116 116
 
117 117
                 $total = 0;
118 118
                 $approved = array(
@@ -123,33 +123,33 @@  discard block
 block discarded – undo
123 123
                     'post-trashed' => 'post-trashed',
124 124
                 );
125 125
 
126
-                foreach ( (array) $count as $row ) {
126
+                foreach ((array)$count as $row) {
127 127
                     // Do not count post-trashed toward totals.
128
-                    if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) {
128
+                    if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) {
129 129
                         $total += $row['num_comments'];
130 130
                     }
131
-                    if ( isset( $approved[ $row['comment_approved'] ] ) ) {
132
-                        $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
131
+                    if (isset($approved[$row['comment_approved']])) {
132
+                        $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
133 133
                     }
134 134
                 }
135 135
 
136 136
                 $stats['total_comments'] = $total;
137 137
                 $stats['all'] = $total;
138
-                foreach ( $approved as $key ) {
139
-                    if ( empty( $stats[ $key ] ) ) {
140
-                        $stats[ $key ] = 0;
138
+                foreach ($approved as $key) {
139
+                    if (empty($stats[$key])) {
140
+                        $stats[$key] = 0;
141 141
                     }
142 142
                 }
143 143
 
144
-                $stats = (object) $stats;
145
-                set_transient( 'wpinv_count_comments', $stats );
144
+                $stats = (object)$stats;
145
+                set_transient('wpinv_count_comments', $stats);
146 146
             }
147 147
         }
148 148
 
149 149
         return $stats;
150 150
     }
151 151
 
152
-    function wpinv_comment_feed_where($where){
153
-        return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' ";
152
+    function wpinv_comment_feed_where($where) {
153
+        return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' ";
154 154
     }
155 155
 }
Please login to merge, or discard this patch.