@@ -23,7 +23,9 @@ discard block |
||
23 | 23 | public function onBeforeUpdateReview( WP_Post $review, $metaKey, $metaValue ) |
24 | 24 | { |
25 | 25 | $previousValue = get_post_meta( $review->ID, $metaKey, true ); |
26 | - if( $previousValue == $metaValue )return; |
|
26 | + if( $previousValue == $metaValue ) { |
|
27 | + return; |
|
28 | + } |
|
27 | 29 | $this->decreaseReviewCount( $review ); |
28 | 30 | $this->increaseReviewCount( $review, [$metaKey => $metaValue] ); |
29 | 31 | } |
@@ -36,7 +38,9 @@ discard block |
||
36 | 38 | */ |
37 | 39 | public function onCreateReview( $postData, $meta, $postId ) |
38 | 40 | { |
39 | - if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE )return; |
|
41 | + if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE ) { |
|
42 | + return; |
|
43 | + } |
|
40 | 44 | $review = get_post( $postId ) |
41 | 45 | $this->updateAssignedToPost( $review ); |
42 | 46 | $this->increaseReviewCount( $review ); |
@@ -48,7 +52,9 @@ discard block |
||
48 | 52 | */ |
49 | 53 | public function onDeleteReview( $postId ) |
50 | 54 | { |
51 | - if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE )return; |
|
55 | + if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE ) { |
|
56 | + return; |
|
57 | + } |
|
52 | 58 | $review = get_post( $postId ) |
53 | 59 | $review->post_status = 'deleted'; // important to change the post_status here first! |
54 | 60 | $this->updateAssignedToPost( $review ); |
@@ -85,7 +91,9 @@ discard block |
||
85 | 91 | */ |
86 | 92 | public function saveAssignedToMetabox( $postId ) |
87 | 93 | { |
88 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ))return; |
|
94 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' )) { |
|
95 | + return; |
|
96 | + } |
|
89 | 97 | $assignedTo = glsr( Helper::class )->filterInput( 'assigned_to' ); |
90 | 98 | $assignedTo || $assignedTo = ''; |
91 | 99 | if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) { |
@@ -100,7 +108,9 @@ discard block |
||
100 | 108 | */ |
101 | 109 | public function saveResponseMetabox( $postId ) |
102 | 110 | { |
103 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ))return; |
|
111 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' )) { |
|
112 | + return; |
|
113 | + } |
|
104 | 114 | $response = glsr( Helper::class )->filterInput( 'response' ); |
105 | 115 | $response || $response = ''; |
106 | 116 | update_post_meta( $postId, 'response', trim( wp_kses( $response, [ |
@@ -134,10 +144,14 @@ discard block |
||
134 | 144 | ]); |
135 | 145 | if( !in_array( $meta['review_type'], glsr()->reviewTypes ) |
136 | 146 | || intval( $meta['rating'] ) > Rating::MAX_RATING |
137 | - )return; |
|
147 | + ) { |
|
148 | + return; |
|
149 | + } |
|
138 | 150 | $counts = glsr( OptionManager::class )->get( 'counts.'.$meta['review_type'], [] ); |
139 | 151 | foreach( range( 0, Rating::MAX_RATING ) as $rating ) { |
140 | - if( isset( $counts[$rating] ))continue; |
|
152 | + if( isset( $counts[$rating] )) { |
|
153 | + continue; |
|
154 | + } |
|
141 | 155 | $counts[$rating] = 0; |
142 | 156 | } |
143 | 157 | ksort( $counts ); |
@@ -150,7 +164,9 @@ discard block |
||
150 | 164 | protected function setReviewCounts( WP_Post $review, array $counts ) |
151 | 165 | { |
152 | 166 | $type = get_post_meta( $review->ID, 'review_type', true ); |
153 | - if( !in_array( $type, glsr()->reviewTypes ))return; |
|
167 | + if( !in_array( $type, glsr()->reviewTypes )) { |
|
168 | + return; |
|
169 | + } |
|
154 | 170 | glsr( OptionManager::class )->set( 'counts.'.$type, $counts ); |
155 | 171 | } |
156 | 172 | |
@@ -197,9 +213,13 @@ discard block |
||
197 | 213 | */ |
198 | 214 | protected function updateAssignedToPost( WP_Post $review ) |
199 | 215 | { |
200 | - if( !( $postId = $this->getAssignedToPostId( $review->ID )))return; |
|
216 | + if( !( $postId = $this->getAssignedToPostId( $review->ID ))) { |
|
217 | + return; |
|
218 | + } |
|
201 | 219 | $reviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID )); |
202 | - if( empty( $reviewIds ))return; |
|
220 | + if( empty( $reviewIds )) { |
|
221 | + return; |
|
222 | + } |
|
203 | 223 | $this->updateReviewIdOfPost( $postId, $review, $reviewIds ); |
204 | 224 | $updatedReviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID )); |
205 | 225 | if( empty( $updatedReviewIds )) { |
@@ -92,7 +92,9 @@ discard block |
||
92 | 92 | if( !in_array( $metaKey, ['rating', 'review_type'] ) |
93 | 93 | || get_post_field( 'post_type', $postId ) != Application::POST_TYPE |
94 | 94 | || get_post_field( 'post_status', $postId ) != 'publish' // only fire on an existing published post |
95 | - )return; |
|
95 | + ) { |
|
96 | + return; |
|
97 | + } |
|
96 | 98 | glsr( Metaboxes::class )->onBeforeUpdateReview( get_post( $postId ), $metaKey, $metaValue ); |
97 | 99 | } |
98 | 100 | |
@@ -127,7 +129,9 @@ discard block |
||
127 | 129 | { |
128 | 130 | if( in_array( $oldStatus, ['new', $newStatus] ) |
129 | 131 | || $post->post_type != Application::POST_TYPE |
130 | - )return; |
|
132 | + ) { |
|
133 | + return; |
|
134 | + } |
|
131 | 135 | glsr( Metaboxes::class )->onReviewStatusChange( $newStatus, $post ); |
132 | 136 | } |
133 | 137 | |
@@ -148,7 +152,9 @@ discard block |
||
148 | 152 | */ |
149 | 153 | public function registerMetaBoxes( $postType ) |
150 | 154 | { |
151 | - if( $postType != Application::POST_TYPE )return; |
|
155 | + if( $postType != Application::POST_TYPE ) { |
|
156 | + return; |
|
157 | + } |
|
152 | 158 | add_meta_box( Application::ID.'_assigned_to', __( 'Assigned To', 'site-reviews' ), [$this, 'renderAssignedToMetabox'], null, 'side' ); |
153 | 159 | add_meta_box( Application::ID.'_review', __( 'Details', 'site-reviews' ), [$this, 'renderDetailsMetaBox'], null, 'side' ); |
154 | 160 | add_meta_box( Application::ID.'_response', __( 'Respond Publicly', 'site-reviews' ), [$this, 'renderResponseMetaBox'], null, 'normal' ); |
@@ -178,7 +184,9 @@ discard block |
||
178 | 184 | */ |
179 | 185 | public function renderAssignedToMetabox( WP_Post $post ) |
180 | 186 | { |
181 | - if( !$this->isReviewPostType( $post ))return; |
|
187 | + if( !$this->isReviewPostType( $post )) { |
|
188 | + return; |
|
189 | + } |
|
182 | 190 | $assignedTo = (string)get_post_meta( $post->ID, 'assigned_to', true ); |
183 | 191 | wp_nonce_field( 'assigned_to', '_nonce-assigned-to', false ); |
184 | 192 | glsr()->render( 'partials/editor/metabox-assigned-to', [ |
@@ -193,7 +201,9 @@ discard block |
||
193 | 201 | */ |
194 | 202 | public function renderDetailsMetaBox( WP_Post $post ) |
195 | 203 | { |
196 | - if( !$this->isReviewPostType( $post ))return; |
|
204 | + if( !$this->isReviewPostType( $post )) { |
|
205 | + return; |
|
206 | + } |
|
197 | 207 | $review = glsr( Database::class )->getReview( $post ); |
198 | 208 | glsr()->render( 'partials/editor/metabox-details', [ |
199 | 209 | 'button' => $this->buildDetailsMetaBoxRevertButton( $review, $post ), |
@@ -207,7 +217,9 @@ discard block |
||
207 | 217 | */ |
208 | 218 | public function renderPinnedInPublishMetaBox() |
209 | 219 | { |
210 | - if( !$this->isReviewPostType( get_post() ))return; |
|
220 | + if( !$this->isReviewPostType( get_post() )) { |
|
221 | + return; |
|
222 | + } |
|
211 | 223 | glsr( Html::class )->renderTemplate( 'partials/editor/pinned', [ |
212 | 224 | 'context' => [ |
213 | 225 | 'no' => __( 'No', 'site-reviews' ), |
@@ -223,7 +235,9 @@ discard block |
||
223 | 235 | */ |
224 | 236 | public function renderResponseMetaBox( WP_Post $post ) |
225 | 237 | { |
226 | - if( !$this->isReviewPostType( $post ))return; |
|
238 | + if( !$this->isReviewPostType( $post )) { |
|
239 | + return; |
|
240 | + } |
|
227 | 241 | wp_nonce_field( 'response', '_nonce-response', false ); |
228 | 242 | glsr()->render( 'partials/editor/metabox-response', [ |
229 | 243 | 'response' => glsr( Database::class )->getReview( $post )->response, |
@@ -237,7 +251,9 @@ discard block |
||
237 | 251 | */ |
238 | 252 | public function renderTaxonomyMetabox( WP_Post $post ) |
239 | 253 | { |
240 | - if( !$this->isReviewPostType( $post ))return; |
|
254 | + if( !$this->isReviewPostType( $post )) { |
|
255 | + return; |
|
256 | + } |
|
241 | 257 | glsr()->render( 'partials/editor/metabox-categories', [ |
242 | 258 | 'post' => $post, |
243 | 259 | 'tax_name' => Application::TAXONOMY, |
@@ -275,7 +291,9 @@ discard block |
||
275 | 291 | protected function buildAssignedToTemplate( $assignedTo, WP_Post $post ) |
276 | 292 | { |
277 | 293 | $assignedPost = glsr( Database::class )->getAssignedToPost( $post, $assignedTo ); |
278 | - if( !( $assignedPost instanceof WP_Post ))return; |
|
294 | + if( !( $assignedPost instanceof WP_Post )) { |
|
295 | + return; |
|
296 | + } |
|
279 | 297 | return glsr( Html::class )->buildTemplate( 'partials/editor/assigned-post', [ |
280 | 298 | 'context' => [ |
281 | 299 | 'data.url' => (string)get_permalink( $assignedPost ), |
@@ -317,7 +335,9 @@ discard block |
||
317 | 335 | */ |
318 | 336 | protected function getReviewType( $review ) |
319 | 337 | { |
320 | - if( count( glsr()->reviewTypes ) < 2 )return; |
|
338 | + if( count( glsr()->reviewTypes ) < 2 ) { |
|
339 | + return; |
|
340 | + } |
|
321 | 341 | $reviewType = array_key_exists( $review->review_type, glsr()->reviewTypes ) |
322 | 342 | ? glsr()->reviewTypes[$review->review_type] |
323 | 343 | : __( 'Unknown', 'site-reviews' ); |
@@ -64,7 +64,9 @@ discard block |
||
64 | 64 | public function getAssignedToPost( $post, $assignedTo = '' ) |
65 | 65 | { |
66 | 66 | $post = get_post( $post ); |
67 | - if( !( $post instanceof WP_Post ))return; |
|
67 | + if( !( $post instanceof WP_Post )) { |
|
68 | + return; |
|
69 | + } |
|
68 | 70 | if( empty( $assignedTo )) { |
69 | 71 | $assignedTo = get_post_meta( $post->ID, 'assigned_to', true ); |
70 | 72 | } |
@@ -82,7 +84,9 @@ discard block |
||
82 | 84 | */ |
83 | 85 | public function getReview( $post ) |
84 | 86 | { |
85 | - if( !( $post instanceof WP_Post ) || $post->post_type != Application::POST_TYPE )return; |
|
87 | + if( !( $post instanceof WP_Post ) || $post->post_type != Application::POST_TYPE ) { |
|
88 | + return; |
|
89 | + } |
|
86 | 90 | $review = $this->getReviewMeta( $post->ID ); |
87 | 91 | $modified = $this->isReviewModified( $post, $review ); |
88 | 92 | $review->content = $post->post_content; |
@@ -256,7 +260,9 @@ discard block |
||
256 | 260 | $termIds = array_map( 'trim', explode( ',', $termIds )); |
257 | 261 | foreach( $termIds as $termId ) { |
258 | 262 | $term = term_exists( $termId, Application::TAXONOMY ); |
259 | - if( !isset( $term['term_id'] ))continue; |
|
263 | + if( !isset( $term['term_id'] )) { |
|
264 | + continue; |
|
265 | + } |
|
260 | 266 | $terms[] = intval( $term['term_id'] ); |
261 | 267 | } |
262 | 268 | return $terms; |
@@ -268,7 +274,9 @@ discard block |
||
268 | 274 | */ |
269 | 275 | public function revertReview( $postId ) |
270 | 276 | { |
271 | - if( get_post_field( 'post_type', $postId ) != Application::POST_TYPE )return; |
|
277 | + if( get_post_field( 'post_type', $postId ) != Application::POST_TYPE ) { |
|
278 | + return; |
|
279 | + } |
|
272 | 280 | delete_post_meta( $postId, '_edit_last' ); |
273 | 281 | $result = wp_update_post([ |
274 | 282 | 'ID' => $postId, |
@@ -303,7 +311,9 @@ discard block |
||
303 | 311 | add_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2 ); |
304 | 312 | $search = new WP_Query( $args ); |
305 | 313 | remove_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500 ); |
306 | - if( !$search->have_posts() )return; |
|
314 | + if( !$search->have_posts() ) { |
|
315 | + return; |
|
316 | + } |
|
307 | 317 | $results = ''; |
308 | 318 | while( $search->have_posts() ) { |
309 | 319 | $search->the_post(); |
@@ -327,7 +337,9 @@ discard block |
||
327 | 337 | public function setReviewTerms( $postId, $termIds ) |
328 | 338 | { |
329 | 339 | $terms = $this->normalizeTerms( $termIds ); |
330 | - if( empty( $terms ))return; |
|
340 | + if( empty( $terms )) { |
|
341 | + return; |
|
342 | + } |
|
331 | 343 | $result = wp_set_object_terms( $postId, $terms, Application::TAXONOMY ); |
332 | 344 | if( is_wp_error( $result )) { |
333 | 345 | glsr_log()->error( $result->get_error_message() ); |