@@ -147,24 +147,24 @@ discard block  | 
                                                    ||
| 147 | 147 | */  | 
                                                        
| 148 | 148 | public function renderAssignedToMetabox( WP_Post $post )  | 
                                                        
| 149 | 149 |  	{ | 
                                                        
| 150 | - if( !$this->isReviewPostType( $post ))return;  | 
                                                        |
| 150 | + if( !$this->isReviewPostType( $post ) )return;  | 
                                                        |
| 151 | 151 | $assignedTo = get_post_meta( $post->ID, 'assigned_to', true );  | 
                                                        
| 152 | 152 | $template = '';  | 
                                                        
| 153 | -		if( $assignedPost = get_post( $assignedTo )) { | 
                                                        |
| 153 | +		if( $assignedPost = get_post( $assignedTo ) ) { | 
                                                        |
| 154 | 154 | ob_start();  | 
                                                        
| 155 | 155 | glsr( Html::class )->renderTemplate( 'edit/assigned-post', [  | 
                                                        
| 156 | 156 | 'context' => [  | 
                                                        
| 157 | 157 | 'url' => (string)get_permalink( $assignedPost ),  | 
                                                        
| 158 | 158 | 'title' => get_the_title( $assignedPost ),  | 
                                                        
| 159 | 159 | ],  | 
                                                        
| 160 | - ]);  | 
                                                        |
| 160 | + ] );  | 
                                                        |
| 161 | 161 | $template = ob_get_clean();  | 
                                                        
| 162 | 162 | }  | 
                                                        
| 163 | 163 | wp_nonce_field( 'assigned_to', '_nonce-assigned-to', false );  | 
                                                        
| 164 | 164 | glsr()->render( 'edit/metabox-assigned-to', [  | 
                                                        
| 165 | 165 | 'id' => $assignedTo,  | 
                                                        
| 166 | 166 | 'template' => $template,  | 
                                                        
| 167 | - ]);  | 
                                                        |
| 167 | + ] );  | 
                                                        |
| 168 | 168 | }  | 
                                                        
| 169 | 169 | |
| 170 | 170 | /**  | 
                                                        
@@ -173,12 +173,12 @@ discard block  | 
                                                    ||
| 173 | 173 | */  | 
                                                        
| 174 | 174 | public function renderDetailsMetaBox( WP_Post $post )  | 
                                                        
| 175 | 175 |  	{ | 
                                                        
| 176 | - if( !$this->isReviewPostType( $post ))return;  | 
                                                        |
| 176 | + if( !$this->isReviewPostType( $post ) )return;  | 
                                                        |
| 177 | 177 | $review = glsr( Database::class )->getReview( $post );  | 
                                                        
| 178 | 178 | glsr()->render( 'edit/metabox-details', [  | 
                                                        
| 179 | 179 | 'button' => $this->buildDetailsMetaBoxRevertButton( $review, $post ),  | 
                                                        
| 180 | 180 | 'metabox' => $this->buildDetailsMetaBox( $review ),  | 
                                                        
| 181 | - ]);  | 
                                                        |
| 181 | + ] );  | 
                                                        |
| 182 | 182 | }  | 
                                                        
| 183 | 183 | |
| 184 | 184 | /**  | 
                                                        
@@ -187,11 +187,11 @@ discard block  | 
                                                    ||
| 187 | 187 | */  | 
                                                        
| 188 | 188 | public function renderPinnedInPublishMetaBox()  | 
                                                        
| 189 | 189 |  	{ | 
                                                        
| 190 | - if( !$this->isReviewPostType( get_post() ))return;  | 
                                                        |
| 190 | + if( !$this->isReviewPostType( get_post() ) )return;  | 
                                                        |
| 191 | 191 | $pinned = get_post_meta( get_the_ID(), 'pinned', true );  | 
                                                        
| 192 | 192 | glsr()->render( 'edit/pinned', [  | 
                                                        
| 193 | 193 | 'pinned' => $pinned,  | 
                                                        
| 194 | - ]);  | 
                                                        |
| 194 | + ] );  | 
                                                        |
| 195 | 195 | }  | 
                                                        
| 196 | 196 | |
| 197 | 197 | /**  | 
                                                        
@@ -200,12 +200,12 @@ discard block  | 
                                                    ||
| 200 | 200 | */  | 
                                                        
| 201 | 201 | public function renderResponseMetaBox( WP_Post $post )  | 
                                                        
| 202 | 202 |  	{ | 
                                                        
| 203 | - if( !$this->isReviewPostType( $post ))return;  | 
                                                        |
| 203 | + if( !$this->isReviewPostType( $post ) )return;  | 
                                                        |
| 204 | 204 | $review = glsr( Database::class )->getReview( $post );  | 
                                                        
| 205 | 205 | wp_nonce_field( 'response', '_nonce-response', false );  | 
                                                        
| 206 | 206 | glsr()->render( 'edit/metabox-response', [  | 
                                                        
| 207 | 207 | 'response' => $review->response,  | 
                                                        
| 208 | - ]);  | 
                                                        |
| 208 | + ] );  | 
                                                        |
| 209 | 209 | }  | 
                                                        
| 210 | 210 | |
| 211 | 211 | /**  | 
                                                        
@@ -215,12 +215,12 @@ discard block  | 
                                                    ||
| 215 | 215 | */  | 
                                                        
| 216 | 216 | public function renderTaxonomyMetabox( WP_Post $post )  | 
                                                        
| 217 | 217 |  	{ | 
                                                        
| 218 | - if( !$this->isReviewPostType( $post ))return;  | 
                                                        |
| 218 | + if( !$this->isReviewPostType( $post ) )return;  | 
                                                        |
| 219 | 219 | glsr()->render( 'edit/metabox-categories', [  | 
                                                        
| 220 | 220 | 'post' => $post,  | 
                                                        
| 221 | 221 | 'tax_name' => esc_attr( Application::TAXONOMY ),  | 
                                                        
| 222 | 222 | 'taxonomy' => get_taxonomy( Application::TAXONOMY ),  | 
                                                        
| 223 | - ]);  | 
                                                        |
| 223 | + ] );  | 
                                                        |
| 224 | 224 | }  | 
                                                        
| 225 | 225 | |
| 226 | 226 | /**  | 
                                                        
@@ -230,7 +230,7 @@ discard block  | 
                                                    ||
| 230 | 230 | */  | 
                                                        
| 231 | 231 | public function revertReview()  | 
                                                        
| 232 | 232 |  	{ | 
                                                        
| 233 | - check_admin_referer( 'revert-review_'.( $postId = $this->getPostId() ));  | 
                                                        |
| 233 | + check_admin_referer( 'revert-review_'.($postId = $this->getPostId()) );  | 
                                                        |
| 234 | 234 | glsr( Database::class )->revertReview( $postId );  | 
                                                        
| 235 | 235 | $this->redirect( $postId, 52 );  | 
                                                        
| 236 | 236 | }  | 
                                                        
@@ -252,16 +252,16 @@ discard block  | 
                                                    ||
| 252 | 252 | */  | 
                                                        
| 253 | 253 | protected function buildDetailsMetaBox( $review )  | 
                                                        
| 254 | 254 |  	{ | 
                                                        
| 255 | - $reviewer = empty( $review->user_id )  | 
                                                        |
| 255 | + $reviewer = empty($review->user_id)  | 
                                                        |
| 256 | 256 | ? __( 'Unregistered user', 'site-reviews' )  | 
                                                        
| 257 | 257 | : glsr( Builder::class )->a( get_the_author_meta( 'display_name', $review->user_id ), [  | 
                                                        
| 258 | 258 | 'href' => get_author_posts_url( $review->user_id ),  | 
                                                        
| 259 | - ]);  | 
                                                        |
| 260 | - $email = empty( $review->email )  | 
                                                        |
| 259 | + ] );  | 
                                                        |
| 260 | + $email = empty($review->email)  | 
                                                        |
| 261 | 261 | ? '—'  | 
                                                        
| 262 | 262 | : glsr( Builder::class )->a( $review->email, [  | 
                                                        
| 263 | 263 | 'href' => 'mailto:'.$review->email.'?subject='.esc_attr( __( 'RE:', 'site-reviews' ).' '.$review->title ),  | 
                                                        
| 264 | - ]);  | 
                                                        |
| 264 | + ] );  | 
                                                        |
| 265 | 265 | $metabox = [  | 
                                                        
| 266 | 266 | __( 'Rating', 'site-reviews' ) => glsr( Html::class )->renderPartial( 'star-rating', ['rating' => $review->rating] ),  | 
                                                        
| 267 | 267 | __( 'Type', 'site-reviews' ) => $this->getReviewType( $review ),  | 
                                                        
@@ -292,8 +292,8 @@ discard block  | 
                                                    ||
| 292 | 292 | 'revert-review_'.$post->ID  | 
                                                        
| 293 | 293 | );  | 
                                                        
| 294 | 294 | return !$modified  | 
                                                        
| 295 | - ? sprintf( '<button id="revert" class="button button-large" disabled>%s</button>', __( 'Nothing to Revert', 'site-reviews' ))  | 
                                                        |
| 296 | - : sprintf( '<a href="%s" id="revert" class="button button-large">%s</a>', $revertUrl, __( 'Revert Changes', 'site-reviews' ));  | 
                                                        |
| 295 | + ? sprintf( '<button id="revert" class="button button-large" disabled>%s</button>', __( 'Nothing to Revert', 'site-reviews' ) )  | 
                                                        |
| 296 | + : sprintf( '<a href="%s" id="revert" class="button button-large">%s</a>', $revertUrl, __( 'Revert Changes', 'site-reviews' ) );  | 
                                                        |
| 297 | 297 | }  | 
                                                        
| 298 | 298 | |
| 299 | 299 | /**  | 
                                                        
@@ -303,11 +303,11 @@ discard block  | 
                                                    ||
| 303 | 303 | protected function getReviewType( $review )  | 
                                                        
| 304 | 304 |  	{ | 
                                                        
| 305 | 305 | $reviewType = $review->review_type;  | 
                                                        
| 306 | -		if( !empty( $review->url )) { | 
                                                        |
| 306 | +		if( !empty($review->url) ) { | 
                                                        |
| 307 | 307 | $reviewType = glsr( Builder::class )->a( $reviewType, [  | 
                                                        
| 308 | 308 | 'href' => $review->url,  | 
                                                        
| 309 | 309 | 'target' => '_blank',  | 
                                                        
| 310 | - ]);  | 
                                                        |
| 310 | + ] );  | 
                                                        |
| 311 | 311 | }  | 
                                                        
| 312 | 312 | return in_array( $reviewType, glsr()->reviewTypes )  | 
                                                        
| 313 | 313 | ? glsr()->reviewTypes[$reviewType]  | 
                                                        
@@ -337,7 +337,7 @@ discard block  | 
                                                    ||
| 337 | 337 | $redirectUri = $hasReferer  | 
                                                        
| 338 | 338 | ? remove_query_arg( ['deleted', 'ids', 'trashed', 'untrashed'], $referer )  | 
                                                        
| 339 | 339 | : get_edit_post_link( $postId, false );  | 
                                                        
| 340 | - wp_safe_redirect( add_query_arg( ['message' => $messageIndex], $redirectUri ));  | 
                                                        |
| 340 | + wp_safe_redirect( add_query_arg( ['message' => $messageIndex], $redirectUri ) );  | 
                                                        |
| 341 | 341 | exit;  | 
                                                        
| 342 | 342 | }  | 
                                                        
| 343 | 343 | }  | 
                                                        
@@ -22,7 +22,7 @@ discard block  | 
                                                    ||
| 22 | 22 | */  | 
                                                        
| 23 | 23 | public function onCreateReview( $postData, $meta, $postId )  | 
                                                        
| 24 | 24 |  	{ | 
                                                        
| 25 | - if( !$this->isReviewPostType( $review = get_post( $postId )))return;  | 
                                                        |
| 25 | + if( !$this->isReviewPostType( $review = get_post( $postId ) ) )return;  | 
                                                        |
| 26 | 26 | $this->updateAssignedToPost( $review );  | 
                                                        
| 27 | 27 | }  | 
                                                        
| 28 | 28 | |
@@ -32,7 +32,7 @@ discard block  | 
                                                    ||
| 32 | 32 | */  | 
                                                        
| 33 | 33 | public function onDeleteReview( $postId )  | 
                                                        
| 34 | 34 |  	{ | 
                                                        
| 35 | - if( !$this->isReviewPostType( $review = get_post( $postId )))return;  | 
                                                        |
| 35 | + if( !$this->isReviewPostType( $review = get_post( $postId ) ) )return;  | 
                                                        |
| 36 | 36 | $review->post_status = 'deleted'; // important to change the post_status here first!  | 
                                                        
| 37 | 37 | $this->updateAssignedToPost( $review );  | 
                                                        
| 38 | 38 | }  | 
                                                        
@@ -52,7 +52,7 @@ discard block  | 
                                                    ||
| 52 | 52 | */  | 
                                                        
| 53 | 53 | public function saveAssignedToMetabox( $postId )  | 
                                                        
| 54 | 54 |  	{ | 
                                                        
| 55 | - if( !wp_verify_nonce( filter_input( INPUT_POST, '_nonce-assigned-to' ), 'assigned_to' ))return;  | 
                                                        |
| 55 | + if( !wp_verify_nonce( filter_input( INPUT_POST, '_nonce-assigned-to' ), 'assigned_to' ) )return;  | 
                                                        |
| 56 | 56 | $assignedTo = filter_input( INPUT_POST, 'assigned_to' );  | 
                                                        
| 57 | 57 | $assignedTo || $assignedTo = '';  | 
                                                        
| 58 | 58 |  		if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) { | 
                                                        
@@ -67,14 +67,14 @@ discard block  | 
                                                    ||
| 67 | 67 | */  | 
                                                        
| 68 | 68 | public function saveResponseMetabox( $postId )  | 
                                                        
| 69 | 69 |  	{ | 
                                                        
| 70 | - if( !wp_verify_nonce( filter_input( INPUT_POST, '_nonce-response' ), 'response' ))return;  | 
                                                        |
| 70 | + if( !wp_verify_nonce( filter_input( INPUT_POST, '_nonce-response' ), 'response' ) )return;  | 
                                                        |
| 71 | 71 | $response = filter_input( INPUT_POST, 'response' );  | 
                                                        
| 72 | 72 | $response || $response = '';  | 
                                                        
| 73 | 73 | update_post_meta( $postId, 'response', trim( wp_kses( $response, [  | 
                                                        
| 74 | 74 | 'a' => ['href' => [], 'title' => []],  | 
                                                        
| 75 | 75 | 'em' => [],  | 
                                                        
| 76 | 76 | 'strong' => [],  | 
                                                        
| 77 | - ])));  | 
                                                        |
| 77 | + ] ) ) );  | 
                                                        |
| 78 | 78 | }  | 
                                                        
| 79 | 79 | |
| 80 | 80 | /**  | 
                                                        
@@ -84,7 +84,7 @@ discard block  | 
                                                    ||
| 84 | 84 | protected function getAssignedToPostId( $postId )  | 
                                                        
| 85 | 85 |  	{ | 
                                                        
| 86 | 86 | $assignedTo = get_post_meta( $postId, 'assigned_to', true );  | 
                                                        
| 87 | -		if(( $post = get_post( $assignedTo )) instanceof WP_Post ) { | 
                                                        |
| 87 | +		if( ($post = get_post( $assignedTo )) instanceof WP_Post ) { | 
                                                        |
| 88 | 88 | return $post->ID;  | 
                                                        
| 89 | 89 | }  | 
                                                        
| 90 | 90 | return false;  | 
                                                        
@@ -120,22 +120,22 @@ discard block  | 
                                                    ||
| 120 | 120 | */  | 
                                                        
| 121 | 121 | protected function updateAssignedToPost( WP_Post $review )  | 
                                                        
| 122 | 122 |  	{ | 
                                                        
| 123 | - if( !( $postId = $this->getAssignedToPostId( $review->ID )))return;  | 
                                                        |
| 124 | - $reviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID ));  | 
                                                        |
| 125 | - if( !is_array( $reviewIds ))return;  | 
                                                        |
| 123 | + if( !($postId = $this->getAssignedToPostId( $review->ID )) )return;  | 
                                                        |
| 124 | + $reviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID ) );  | 
                                                        |
| 125 | + if( !is_array( $reviewIds ) )return;  | 
                                                        |
| 126 | 126 | $this->updateReviewIdOfPost( $postId, $review, $reviewIds );  | 
                                                        
| 127 | - $updatedReviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID ));  | 
                                                        |
| 128 | -		if( empty( $updatedReviewIds )) { | 
                                                        |
| 127 | + $updatedReviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID ) );  | 
                                                        |
| 128 | +		if( empty($updatedReviewIds) ) { | 
                                                        |
| 129 | 129 | delete_post_meta( $postId, static::META_RANKING );  | 
                                                        
| 130 | 130 | delete_post_meta( $postId, static::META_REVIEW_ID );  | 
                                                        
| 131 | 131 | }  | 
                                                        
| 132 | -		else if( !glsr( Helper::class )->compareArrays( $reviewIds, $updatedReviewIds )) { | 
                                                        |
| 133 | - $reviews = glsr( Database::class )->getReviews([  | 
                                                        |
| 132 | +		else if( !glsr( Helper::class )->compareArrays( $reviewIds, $updatedReviewIds ) ) { | 
                                                        |
| 133 | + $reviews = glsr( Database::class )->getReviews( [  | 
                                                        |
| 134 | 134 | 'count' => -1,  | 
                                                        
| 135 | 135 | 'post__in' => $updatedReviewIds,  | 
                                                        
| 136 | - ]);  | 
                                                        |
| 137 | - update_post_meta( $postId, static::META_AVERAGE, $this->recalculatePostAverage( $reviews->results ));  | 
                                                        |
| 138 | - update_post_meta( $postId, static::META_RANKING, $this->recalculatePostRanking( $reviews->results ));  | 
                                                        |
| 136 | + ] );  | 
                                                        |
| 137 | + update_post_meta( $postId, static::META_AVERAGE, $this->recalculatePostAverage( $reviews->results ) );  | 
                                                        |
| 138 | + update_post_meta( $postId, static::META_RANKING, $this->recalculatePostRanking( $reviews->results ) );  | 
                                                        |
| 139 | 139 | }  | 
                                                        
| 140 | 140 | }  | 
                                                        
| 141 | 141 | |
@@ -148,7 +148,7 @@ discard block  | 
                                                    ||
| 148 | 148 |  		if( $review->post_status != 'publish' ) { | 
                                                        
| 149 | 149 | delete_post_meta( $postId, static::META_REVIEW_ID, $review->ID );  | 
                                                        
| 150 | 150 | }  | 
                                                        
| 151 | -		else if( !in_array( $review->ID, $reviewIds )) { | 
                                                        |
| 151 | +		else if( !in_array( $review->ID, $reviewIds ) ) { | 
                                                        |
| 152 | 152 | add_post_meta( $postId, static::META_REVIEW_ID, $review->ID );  | 
                                                        
| 153 | 153 | }  | 
                                                        
| 154 | 154 | }  | 
                                                        
@@ -22,7 +22,9 @@ discard block  | 
                                                    ||
| 22 | 22 | */  | 
                                                        
| 23 | 23 | public function onCreateReview( $postData, $meta, $postId )  | 
                                                        
| 24 | 24 |  	{ | 
                                                        
| 25 | - if( !$this->isReviewPostType( $review = get_post( $postId )))return;  | 
                                                        |
| 25 | +		if( !$this->isReviewPostType( $review = get_post( $postId ))) { | 
                                                        |
| 26 | + return;  | 
                                                        |
| 27 | + }  | 
                                                        |
| 26 | 28 | $this->updateAssignedToPost( $review );  | 
                                                        
| 27 | 29 | }  | 
                                                        
| 28 | 30 | |
@@ -32,7 +34,9 @@ discard block  | 
                                                    ||
| 32 | 34 | */  | 
                                                        
| 33 | 35 | public function onDeleteReview( $postId )  | 
                                                        
| 34 | 36 |  	{ | 
                                                        
| 35 | - if( !$this->isReviewPostType( $review = get_post( $postId )))return;  | 
                                                        |
| 37 | +		if( !$this->isReviewPostType( $review = get_post( $postId ))) { | 
                                                        |
| 38 | + return;  | 
                                                        |
| 39 | + }  | 
                                                        |
| 36 | 40 | $review->post_status = 'deleted'; // important to change the post_status here first!  | 
                                                        
| 37 | 41 | $this->updateAssignedToPost( $review );  | 
                                                        
| 38 | 42 | }  | 
                                                        
@@ -52,7 +56,9 @@ discard block  | 
                                                    ||
| 52 | 56 | */  | 
                                                        
| 53 | 57 | public function saveAssignedToMetabox( $postId )  | 
                                                        
| 54 | 58 |  	{ | 
                                                        
| 55 | - if( !wp_verify_nonce( filter_input( INPUT_POST, '_nonce-assigned-to' ), 'assigned_to' ))return;  | 
                                                        |
| 59 | +		if( !wp_verify_nonce( filter_input( INPUT_POST, '_nonce-assigned-to' ), 'assigned_to' )) { | 
                                                        |
| 60 | + return;  | 
                                                        |
| 61 | + }  | 
                                                        |
| 56 | 62 | $assignedTo = filter_input( INPUT_POST, 'assigned_to' );  | 
                                                        
| 57 | 63 | $assignedTo || $assignedTo = '';  | 
                                                        
| 58 | 64 |  		if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) { | 
                                                        
@@ -67,7 +73,9 @@ discard block  | 
                                                    ||
| 67 | 73 | */  | 
                                                        
| 68 | 74 | public function saveResponseMetabox( $postId )  | 
                                                        
| 69 | 75 |  	{ | 
                                                        
| 70 | - if( !wp_verify_nonce( filter_input( INPUT_POST, '_nonce-response' ), 'response' ))return;  | 
                                                        |
| 76 | +		if( !wp_verify_nonce( filter_input( INPUT_POST, '_nonce-response' ), 'response' )) { | 
                                                        |
| 77 | + return;  | 
                                                        |
| 78 | + }  | 
                                                        |
| 71 | 79 | $response = filter_input( INPUT_POST, 'response' );  | 
                                                        
| 72 | 80 | $response || $response = '';  | 
                                                        
| 73 | 81 | update_post_meta( $postId, 'response', trim( wp_kses( $response, [  | 
                                                        
@@ -120,9 +128,13 @@ discard block  | 
                                                    ||
| 120 | 128 | */  | 
                                                        
| 121 | 129 | protected function updateAssignedToPost( WP_Post $review )  | 
                                                        
| 122 | 130 |  	{ | 
                                                        
| 123 | - if( !( $postId = $this->getAssignedToPostId( $review->ID )))return;  | 
                                                        |
| 131 | +		if( !( $postId = $this->getAssignedToPostId( $review->ID ))) { | 
                                                        |
| 132 | + return;  | 
                                                        |
| 133 | + }  | 
                                                        |
| 124 | 134 | $reviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID ));  | 
                                                        
| 125 | - if( !is_array( $reviewIds ))return;  | 
                                                        |
| 135 | +		if( !is_array( $reviewIds )) { | 
                                                        |
| 136 | + return;  | 
                                                        |
| 137 | + }  | 
                                                        |
| 126 | 138 | $this->updateReviewIdOfPost( $postId, $review, $reviewIds );  | 
                                                        
| 127 | 139 | $updatedReviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID ));  | 
                                                        
| 128 | 140 |  		if( empty( $updatedReviewIds )) { |