@@ -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( empty( $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( empty($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( empty( $reviewIds ))return; |
|
| 135 | + if( empty( $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 )) { |