@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function saveAssignedToMetabox( $postId ) |
88 | 88 | { |
89 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ))return; |
|
89 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ) )return; |
|
90 | 90 | $assignedTo = glsr( Helper::class )->filterInput( 'assigned_to' ); |
91 | 91 | $assignedTo || $assignedTo = ''; |
92 | 92 | if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) { |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function saveResponseMetabox( $postId ) |
103 | 103 | { |
104 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ))return; |
|
104 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ) )return; |
|
105 | 105 | $response = glsr( Helper::class )->filterInput( 'response' ); |
106 | 106 | $response || $response = ''; |
107 | 107 | update_post_meta( $postId, 'response', trim( wp_kses( $response, [ |
108 | 108 | 'a' => ['href' => [], 'title' => []], |
109 | 109 | 'em' => [], |
110 | 110 | 'strong' => [], |
111 | - ]))); |
|
111 | + ] ) ) ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function getAssignedToPostId( $postId ) |
119 | 119 | { |
120 | - $assignedTo = intval( get_post_meta( $postId, 'assigned_to', true )); |
|
121 | - if(( $post = get_post( $assignedTo )) instanceof WP_Post ) { |
|
120 | + $assignedTo = intval( get_post_meta( $postId, 'assigned_to', true ) ); |
|
121 | + if( ($post = get_post( $assignedTo )) instanceof WP_Post ) { |
|
122 | 122 | return $post->ID; |
123 | 123 | } |
124 | 124 | return false; |
@@ -132,13 +132,13 @@ discard block |
||
132 | 132 | $meta = wp_parse_args( $meta, [ |
133 | 133 | 'rating' => get_post_meta( $review->ID, 'rating', true ), |
134 | 134 | 'review_type' => get_post_meta( $review->ID, 'review_type', true ), |
135 | - ]); |
|
135 | + ] ); |
|
136 | 136 | if( !array_key_exists( $meta['review_type'], glsr()->reviewTypes ) |
137 | 137 | || intval( $meta['rating'] ) > Rating::MAX_RATING |
138 | 138 | )return; |
139 | 139 | $counts = glsr( OptionManager::class )->get( 'counts.'.$meta['review_type'], [] ); |
140 | 140 | foreach( range( 0, Rating::MAX_RATING ) as $rating ) { |
141 | - if( isset( $counts[$rating] ))continue; |
|
141 | + if( isset($counts[$rating]) )continue; |
|
142 | 142 | $counts[$rating] = 0; |
143 | 143 | } |
144 | 144 | ksort( $counts ); |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | */ |
151 | 151 | protected function setReviewCounts( WP_Post $review, array $counts ) |
152 | 152 | { |
153 | - $type = strval( get_post_meta( $review->ID, 'review_type', true )); |
|
154 | - if( !array_key_exists( $type, glsr()->reviewTypes ))return; |
|
153 | + $type = strval( get_post_meta( $review->ID, 'review_type', true ) ); |
|
154 | + if( !array_key_exists( $type, glsr()->reviewTypes ) )return; |
|
155 | 155 | glsr( OptionManager::class )->set( 'counts.'.$type, $counts ); |
156 | 156 | } |
157 | 157 | |
@@ -160,10 +160,10 @@ discard block |
||
160 | 160 | */ |
161 | 161 | protected function increaseReviewCount( WP_Post $review, array $meta = [] ) |
162 | 162 | { |
163 | - if( $counts = $this->getReviewCounts( $review, $meta )) { |
|
164 | - $rating = isset( $meta['rating'] ) |
|
163 | + if( $counts = $this->getReviewCounts( $review, $meta ) ) { |
|
164 | + $rating = isset($meta['rating']) |
|
165 | 165 | ? $meta['rating'] |
166 | - : intval( get_post_meta( $review->ID, 'rating', true )); |
|
166 | + : intval( get_post_meta( $review->ID, 'rating', true ) ); |
|
167 | 167 | $counts[$rating] -= 1; |
168 | 168 | $this->setReviewCounts( $review, $counts ); |
169 | 169 | } |
@@ -174,8 +174,8 @@ discard block |
||
174 | 174 | */ |
175 | 175 | protected function decreaseReviewCount( WP_Post $review, array $meta = [] ) |
176 | 176 | { |
177 | - if( $counts = $this->getReviewCounts( $review, $meta )) { |
|
178 | - $rating = intval( get_post_meta( $review->ID, 'rating', true )); |
|
177 | + if( $counts = $this->getReviewCounts( $review, $meta ) ) { |
|
178 | + $rating = intval( get_post_meta( $review->ID, 'rating', true ) ); |
|
179 | 179 | $counts[$rating] += 1; |
180 | 180 | $this->setReviewCounts( $review, $counts ); |
181 | 181 | } |
@@ -202,19 +202,19 @@ discard block |
||
202 | 202 | */ |
203 | 203 | protected function updateAssignedToPost( WP_Post $review ) |
204 | 204 | { |
205 | - if( !( $postId = $this->getAssignedToPostId( $review->ID )))return; |
|
206 | - $reviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID )); |
|
207 | - if( empty( $reviewIds ))return; |
|
205 | + if( !($postId = $this->getAssignedToPostId( $review->ID )) )return; |
|
206 | + $reviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID ) ); |
|
207 | + if( empty($reviewIds) )return; |
|
208 | 208 | $this->updateReviewIdOfPost( $postId, $review, $reviewIds ); |
209 | - $updatedReviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID )); |
|
210 | - if( empty( $updatedReviewIds )) { |
|
209 | + $updatedReviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID ) ); |
|
210 | + if( empty($updatedReviewIds) ) { |
|
211 | 211 | delete_post_meta( $postId, static::META_RANKING ); |
212 | 212 | delete_post_meta( $postId, static::META_REVIEW_ID ); |
213 | 213 | } |
214 | - else if( !glsr( Helper::class )->compareArrays( $reviewIds, $updatedReviewIds )) { |
|
214 | + else if( !glsr( Helper::class )->compareArrays( $reviewIds, $updatedReviewIds ) ) { |
|
215 | 215 | $counts = glsr( Database::class )->buildReviewCountsFromIds( $updatedReviewIds ); |
216 | - update_post_meta( $postId, static::META_AVERAGE, $this->recalculatePostAverage( $counts )); |
|
217 | - update_post_meta( $postId, static::META_RANKING, $this->recalculatePostRanking( $counts )); |
|
216 | + update_post_meta( $postId, static::META_AVERAGE, $this->recalculatePostAverage( $counts ) ); |
|
217 | + update_post_meta( $postId, static::META_RANKING, $this->recalculatePostRanking( $counts ) ); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | if( $review->post_status != 'publish' ) { |
228 | 228 | delete_post_meta( $postId, static::META_REVIEW_ID, $review->ID ); |
229 | 229 | } |
230 | - else if( !in_array( $review->ID, $reviewIds )) { |
|
230 | + else if( !in_array( $review->ID, $reviewIds ) ) { |
|
231 | 231 | add_post_meta( $postId, static::META_REVIEW_ID, $review->ID ); |
232 | 232 | } |
233 | 233 | } |
@@ -21,7 +21,9 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function onBeforeDeleteReview( $postId ) |
23 | 23 | { |
24 | - if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE )return; |
|
24 | + if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE ) { |
|
25 | + return; |
|
26 | + } |
|
25 | 27 | $review = get_post( $postId ); |
26 | 28 | $review->post_status = 'deleted'; // change post_status first! |
27 | 29 | $this->updateAssignedToPost( $review ); |
@@ -37,7 +39,9 @@ discard block |
||
37 | 39 | public function onBeforeUpdateReview( WP_Post $review, $metaKey, $newValue ) |
38 | 40 | { |
39 | 41 | $previousValue = get_post_meta( $review->ID, $metaKey, true ); |
40 | - if( $previousValue == $newValue )return; |
|
42 | + if( $previousValue == $newValue ) { |
|
43 | + return; |
|
44 | + } |
|
41 | 45 | $this->decreaseReviewCount( $review ); |
42 | 46 | $this->increaseReviewCount( $review, [$metaKey => $newValue] ); |
43 | 47 | } |
@@ -50,7 +54,9 @@ discard block |
||
50 | 54 | */ |
51 | 55 | public function onCreateReview( $postData, $meta, $postId ) |
52 | 56 | { |
53 | - if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE )return; |
|
57 | + if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE ) { |
|
58 | + return; |
|
59 | + } |
|
54 | 60 | $review = get_post( $postId ); |
55 | 61 | $this->updateAssignedToPost( $review ); |
56 | 62 | $this->increaseReviewCount( $review ); |
@@ -86,7 +92,9 @@ discard block |
||
86 | 92 | */ |
87 | 93 | public function saveAssignedToMetabox( $postId ) |
88 | 94 | { |
89 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ))return; |
|
95 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' )) { |
|
96 | + return; |
|
97 | + } |
|
90 | 98 | $assignedTo = glsr( Helper::class )->filterInput( 'assigned_to' ); |
91 | 99 | $assignedTo || $assignedTo = ''; |
92 | 100 | if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) { |
@@ -101,7 +109,9 @@ discard block |
||
101 | 109 | */ |
102 | 110 | public function saveResponseMetabox( $postId ) |
103 | 111 | { |
104 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ))return; |
|
112 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' )) { |
|
113 | + return; |
|
114 | + } |
|
105 | 115 | $response = glsr( Helper::class )->filterInput( 'response' ); |
106 | 116 | $response || $response = ''; |
107 | 117 | update_post_meta( $postId, 'response', trim( wp_kses( $response, [ |
@@ -135,10 +145,14 @@ discard block |
||
135 | 145 | ]); |
136 | 146 | if( !array_key_exists( $meta['review_type'], glsr()->reviewTypes ) |
137 | 147 | || intval( $meta['rating'] ) > Rating::MAX_RATING |
138 | - )return; |
|
148 | + ) { |
|
149 | + return; |
|
150 | + } |
|
139 | 151 | $counts = glsr( OptionManager::class )->get( 'counts.'.$meta['review_type'], [] ); |
140 | 152 | foreach( range( 0, Rating::MAX_RATING ) as $rating ) { |
141 | - if( isset( $counts[$rating] ))continue; |
|
153 | + if( isset( $counts[$rating] )) { |
|
154 | + continue; |
|
155 | + } |
|
142 | 156 | $counts[$rating] = 0; |
143 | 157 | } |
144 | 158 | ksort( $counts ); |
@@ -151,7 +165,9 @@ discard block |
||
151 | 165 | protected function setReviewCounts( WP_Post $review, array $counts ) |
152 | 166 | { |
153 | 167 | $type = strval( get_post_meta( $review->ID, 'review_type', true )); |
154 | - if( !array_key_exists( $type, glsr()->reviewTypes ))return; |
|
168 | + if( !array_key_exists( $type, glsr()->reviewTypes )) { |
|
169 | + return; |
|
170 | + } |
|
155 | 171 | glsr( OptionManager::class )->set( 'counts.'.$type, $counts ); |
156 | 172 | } |
157 | 173 | |
@@ -202,9 +218,13 @@ discard block |
||
202 | 218 | */ |
203 | 219 | protected function updateAssignedToPost( WP_Post $review ) |
204 | 220 | { |
205 | - if( !( $postId = $this->getAssignedToPostId( $review->ID )))return; |
|
221 | + if( !( $postId = $this->getAssignedToPostId( $review->ID ))) { |
|
222 | + return; |
|
223 | + } |
|
206 | 224 | $reviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID )); |
207 | - if( empty( $reviewIds ))return; |
|
225 | + if( empty( $reviewIds )) { |
|
226 | + return; |
|
227 | + } |
|
208 | 228 | $this->updateReviewIdOfPost( $postId, $review, $reviewIds ); |
209 | 229 | $updatedReviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID )); |
210 | 230 | if( empty( $updatedReviewIds )) { |