@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | 'post_type' => Application::POST_TYPE, |
| 36 | 36 | ]; |
| 37 | 37 | $postId = wp_insert_post( $postValues, true ); |
| 38 | - if( is_wp_error( $postId )) { |
|
| 38 | + if( is_wp_error( $postId ) ) { |
|
| 39 | 39 | glsr_log()->error( $postId->get_error_message() )->debug( $postValues ); |
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | $this->setTerms( $postId, $command->category ); |
| 43 | - $review = $this->single( get_post( $postId )); |
|
| 43 | + $review = $this->single( get_post( $postId ) ); |
|
| 44 | 44 | do_action( 'site-reviews/review/created', $review, $command ); |
| 45 | 45 | return $review; |
| 46 | 46 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function delete( $metaReviewId ) |
| 53 | 53 | { |
| 54 | - if( $postId = $this->getPostId( $metaReviewId )) { |
|
| 54 | + if( $postId = $this->getPostId( $metaReviewId ) ) { |
|
| 55 | 55 | wp_delete_post( $postId, true ); |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | $paged = glsr( QueryBuilder::class )->getPaged( |
| 74 | 74 | wp_validate_boolean( $args['pagination'] ) |
| 75 | 75 | ); |
| 76 | - $reviews = new WP_Query([ |
|
| 76 | + $reviews = new WP_Query( [ |
|
| 77 | 77 | 'meta_key' => 'pinned', |
| 78 | 78 | 'meta_query' => $metaQuery, |
| 79 | 79 | 'offset' => $args['offset'], |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | 'post_type' => Application::POST_TYPE, |
| 87 | 87 | 'posts_per_page' => $args['count'], |
| 88 | 88 | 'tax_query' => $taxQuery, |
| 89 | - ]); |
|
| 89 | + ] ); |
|
| 90 | 90 | return (object)[ |
| 91 | 91 | 'results' => array_map( [$this, 'single'], $reviews->posts ), |
| 92 | 92 | 'max_num_pages' => $reviews->max_num_pages, |
@@ -111,11 +111,11 @@ discard block |
||
| 111 | 111 | $terms = []; |
| 112 | 112 | $termIds = glsr( Helper::class )->convertStringToArray( $commaSeparatedTermIds ); |
| 113 | 113 | foreach( $termIds as $termId ) { |
| 114 | - if( is_numeric( $termId )) { |
|
| 114 | + if( is_numeric( $termId ) ) { |
|
| 115 | 115 | $termId = intval( $termId ); |
| 116 | 116 | } |
| 117 | 117 | $term = term_exists( $termId, Application::TAXONOMY ); |
| 118 | - if( !isset( $term['term_id'] ))continue; |
|
| 118 | + if( !isset($term['term_id']) )continue; |
|
| 119 | 119 | $terms[] = intval( $term['term_id'] ); |
| 120 | 120 | } |
| 121 | 121 | return $terms; |
@@ -129,13 +129,13 @@ discard block |
||
| 129 | 129 | { |
| 130 | 130 | if( get_post_field( 'post_type', $postId ) != Application::POST_TYPE )return; |
| 131 | 131 | delete_post_meta( $postId, '_edit_last' ); |
| 132 | - $result = wp_update_post([ |
|
| 132 | + $result = wp_update_post( [ |
|
| 133 | 133 | 'ID' => $postId, |
| 134 | 134 | 'post_content' => get_post_meta( $postId, 'content', true ), |
| 135 | 135 | 'post_date' => get_post_meta( $postId, 'date', true ), |
| 136 | 136 | 'post_title' => get_post_meta( $postId, 'title', true ), |
| 137 | - ]); |
|
| 138 | - if( is_wp_error( $result )) { |
|
| 137 | + ] ); |
|
| 138 | + if( is_wp_error( $result ) ) { |
|
| 139 | 139 | glsr_log()->error( $result->get_error_message() ); |
| 140 | 140 | } |
| 141 | 141 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | protected function getNewPostStatus( array $review, $isBlacklisted ) |
| 158 | 158 | { |
| 159 | 159 | $requireApprovalOption = glsr( OptionManager::class )->get( 'settings.general.require.approval' ); |
| 160 | - return $review['review_type'] == 'local' && ( $requireApprovalOption == 'yes' || $isBlacklisted ) |
|
| 160 | + return $review['review_type'] == 'local' && ($requireApprovalOption == 'yes' || $isBlacklisted) |
|
| 161 | 161 | ? 'pending' |
| 162 | 162 | : 'publish'; |
| 163 | 163 | } |
@@ -170,9 +170,9 @@ discard block |
||
| 170 | 170 | protected function setTerms( $postId, $termIds ) |
| 171 | 171 | { |
| 172 | 172 | $terms = $this->normalizeTerms( $termIds ); |
| 173 | - if( empty( $terms ))return; |
|
| 173 | + if( empty($terms) )return; |
|
| 174 | 174 | $result = wp_set_object_terms( $postId, $terms, Application::TAXONOMY ); |
| 175 | - if( is_wp_error( $result )) { |
|
| 175 | + if( is_wp_error( $result ) ) { |
|
| 176 | 176 | glsr_log()->error( $result->get_error_message() ); |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -115,7 +115,9 @@ discard block |
||
| 115 | 115 | $termId = intval( $termId ); |
| 116 | 116 | } |
| 117 | 117 | $term = term_exists( $termId, Application::TAXONOMY ); |
| 118 | - if( !isset( $term['term_id'] ))continue; |
|
| 118 | + if( !isset( $term['term_id'] )) { |
|
| 119 | + continue; |
|
| 120 | + } |
|
| 119 | 121 | $terms[] = intval( $term['term_id'] ); |
| 120 | 122 | } |
| 121 | 123 | return $terms; |
@@ -127,7 +129,9 @@ discard block |
||
| 127 | 129 | */ |
| 128 | 130 | public function revert( $postId ) |
| 129 | 131 | { |
| 130 | - if( get_post_field( 'post_type', $postId ) != Application::POST_TYPE )return; |
|
| 132 | + if( get_post_field( 'post_type', $postId ) != Application::POST_TYPE ) { |
|
| 133 | + return; |
|
| 134 | + } |
|
| 131 | 135 | delete_post_meta( $postId, '_edit_last' ); |
| 132 | 136 | $result = wp_update_post([ |
| 133 | 137 | 'ID' => $postId, |
@@ -145,7 +149,9 @@ discard block |
||
| 145 | 149 | */ |
| 146 | 150 | public function single( WP_Post $post ) |
| 147 | 151 | { |
| 148 | - if( $post->post_type != Application::POST_TYPE )return; |
|
| 152 | + if( $post->post_type != Application::POST_TYPE ) { |
|
| 153 | + return; |
|
| 154 | + } |
|
| 149 | 155 | $review = new Review( $post ); |
| 150 | 156 | return apply_filters( 'site-reviews/get/review', $review, $post ); |
| 151 | 157 | } |
@@ -170,7 +176,9 @@ discard block |
||
| 170 | 176 | protected function setTerms( $postId, $termIds ) |
| 171 | 177 | { |
| 172 | 178 | $terms = $this->normalizeTerms( $termIds ); |
| 173 | - if( empty( $terms ))return; |
|
| 179 | + if( empty( $terms )) { |
|
| 180 | + return; |
|
| 181 | + } |
|
| 174 | 182 | $result = wp_set_object_terms( $postId, $terms, Application::TAXONOMY ); |
| 175 | 183 | if( is_wp_error( $result )) { |
| 176 | 184 | glsr_log()->error( $result->get_error_message() ); |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | public function build( array $args = [] ) |
| 36 | 36 | { |
| 37 | 37 | $this->args = $args; |
| 38 | - $counts = glsr( CountsManager::class )->get([ |
|
| 38 | + $counts = glsr( CountsManager::class )->get( [ |
|
| 39 | 39 | 'post_ids' => glsr( Helper::class )->convertStringToArray( $args['assigned_to'] ), |
| 40 | 40 | 'term_ids' => glsr( ReviewManager::class )->normalizeTerms( $args['category'] ), |
| 41 | 41 | 'type' => $args['type'], |
| 42 | - ]); |
|
| 42 | + ] ); |
|
| 43 | 43 | $this->ratingCounts = glsr( CountsManager::class )->flatten( $counts, [ |
| 44 | 44 | 'min' => $args['rating'], |
| 45 | - ]); |
|
| 46 | - if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ))return; |
|
| 45 | + ] ); |
|
| 46 | + if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ) )return; |
|
| 47 | 47 | $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts ); |
| 48 | 48 | $this->generateSchema(); |
| 49 | 49 | return glsr( Template::class )->build( 'templates/reviews-summary', [ |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | 'stars' => $this->buildStars(), |
| 56 | 56 | 'text' => $this->buildText(), |
| 57 | 57 | ], |
| 58 | - ]); |
|
| 58 | + ] ); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | protected function buildPercentage() |
| 65 | 65 | { |
| 66 | - if( $this->isHidden( 'bars' ))return; |
|
| 67 | - $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts )); |
|
| 68 | - $bars = array_reduce( range( Rating::MAX_RATING, 1 ), function( $carry, $level ) use( $percentages ) { |
|
| 66 | + if( $this->isHidden( 'bars' ) )return; |
|
| 67 | + $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts ) ); |
|
| 68 | + $bars = array_reduce( range( Rating::MAX_RATING, 1 ), function( $carry, $level ) use($percentages) { |
|
| 69 | 69 | $label = $this->buildPercentageLabel( $this->args['labels'][$level] ); |
| 70 | 70 | $background = $this->buildPercentageBackground( $percentages[$level] ); |
| 71 | 71 | $count = apply_filters( 'site-reviews/summary/counts', |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $percent = $this->buildPercentageCount( $count ); |
| 76 | 76 | return $carry.glsr( Builder::class )->div( $label.$background.$percent, [ |
| 77 | 77 | 'class' => 'glsr-bar', |
| 78 | - ]); |
|
| 78 | + ] ); |
|
| 79 | 79 | }); |
| 80 | 80 | return $this->wrap( 'percentage', $bars ); |
| 81 | 81 | } |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | protected function buildPercentageBackground( $percent ) |
| 88 | 88 | { |
| 89 | - $backgroundPercent = glsr( Builder::class )->span([ |
|
| 89 | + $backgroundPercent = glsr( Builder::class )->span( [ |
|
| 90 | 90 | 'class' => 'glsr-bar-background-percent', |
| 91 | 91 | 'style' => 'width:'.$percent, |
| 92 | - ]); |
|
| 92 | + ] ); |
|
| 93 | 93 | return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>'; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | protected function buildRating() |
| 118 | 118 | { |
| 119 | - if( $this->isHidden( 'rating' ))return; |
|
| 119 | + if( $this->isHidden( 'rating' ) )return; |
|
| 120 | 120 | return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' ); |
| 121 | 121 | } |
| 122 | 122 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | protected function buildStars() |
| 127 | 127 | { |
| 128 | - if( $this->isHidden( 'stars' ))return; |
|
| 128 | + if( $this->isHidden( 'stars' ) )return; |
|
| 129 | 129 | $stars = glsr( Partial::class )->build( 'star-rating', ['rating' => $this->averageRating] ); |
| 130 | 130 | return $this->wrap( 'stars', $stars ); |
| 131 | 131 | } |
@@ -135,9 +135,9 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | protected function buildText() |
| 137 | 137 | { |
| 138 | - if( $this->isHidden( 'summary' ))return; |
|
| 139 | - $count = intval( array_sum( $this->ratingCounts )); |
|
| 140 | - if( empty( $this->args['text'] )) { |
|
| 138 | + if( $this->isHidden( 'summary' ) )return; |
|
| 139 | + $count = intval( array_sum( $this->ratingCounts ) ); |
|
| 140 | + if( empty($this->args['text']) ) { |
|
| 141 | 141 | // @todo document this change |
| 142 | 142 | $this->args['text'] = _nx( |
| 143 | 143 | '{rating} out of {max} stars (based on {num} review)', |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | ); |
| 149 | 149 | } |
| 150 | 150 | $summary = str_replace( |
| 151 | - ['{rating}','{max}', '{num}'], |
|
| 151 | + ['{rating}', '{max}', '{num}'], |
|
| 152 | 152 | [$this->averageRating, Rating::MAX_RATING, $count], |
| 153 | 153 | $this->args['text'] |
| 154 | 154 | ); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | protected function generateSchema() |
| 162 | 162 | { |
| 163 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
| 163 | + if( !wp_validate_boolean( $this->args['schema'] ) )return; |
|
| 164 | 164 | glsr( Schema::class )->store( |
| 165 | 165 | glsr( Schema::class )->buildSummary( $this->args ) |
| 166 | 166 | ); |
@@ -192,6 +192,6 @@ discard block |
||
| 192 | 192 | { |
| 193 | 193 | return glsr( Builder::class )->div( $value, [ |
| 194 | 194 | 'class' => 'glsr-summary-'.$key, |
| 195 | - ]); |
|
| 195 | + ] ); |
|
| 196 | 196 | } |
| 197 | 197 | } |