@@ -34,7 +34,9 @@ discard block |
||
| 34 | 34 | foreach( glsr( ReviewManager::class )->get( $this->args )->results as $review ) { |
| 35 | 35 | // Only include critic reviews that have been directly produced by your site, not reviews from third- party sites or syndicated reviews. |
| 36 | 36 | // @see https://developers.google.com/search/docs/data-types/review |
| 37 | - if( $review->review_type != 'local' )continue; |
|
| 37 | + if( $review->review_type != 'local' ) { |
|
| 38 | + continue; |
|
| 39 | + } |
|
| 38 | 40 | $reviews[] = $this->buildReview( $review ); |
| 39 | 41 | } |
| 40 | 42 | if( !empty( $reviews )) { |
@@ -79,7 +81,9 @@ discard block |
||
| 79 | 81 | */ |
| 80 | 82 | public function render() |
| 81 | 83 | { |
| 82 | - if( is_null( glsr()->schemas ))return; |
|
| 84 | + if( is_null( glsr()->schemas )) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 83 | 87 | printf( '<script type="application/ld+json">%s</script>', json_encode( |
| 84 | 88 | apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
| 85 | 89 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
@@ -131,7 +135,9 @@ discard block |
||
| 131 | 135 | { |
| 132 | 136 | foreach( $values as $value ) { |
| 133 | 137 | $option = $this->getSchemaOptionValue( $value ); |
| 134 | - if( empty( $option ))continue; |
|
| 138 | + if( empty( $option )) { |
|
| 139 | + continue; |
|
| 140 | + } |
|
| 135 | 141 | $schema->$value( $option ); |
| 136 | 142 | } |
| 137 | 143 | return $schema; |
@@ -237,7 +243,9 @@ discard block |
||
| 237 | 243 | if( $value != $fallback ) { |
| 238 | 244 | return $value; |
| 239 | 245 | } |
| 240 | - if( !is_single() && !is_page() )return; |
|
| 246 | + if( !is_single() && !is_page() ) { |
|
| 247 | + return; |
|
| 248 | + } |
|
| 241 | 249 | $method = glsr( Helper::class )->buildMethodName( $option, 'getThing' ); |
| 242 | 250 | if( method_exists( $this, $method )) { |
| 243 | 251 | return $this->$method(); |
@@ -38,10 +38,10 @@ discard block |
||
| 38 | 38 | if( $review->review_type != 'local' )continue; |
| 39 | 39 | $reviews[] = $this->buildReview( $review ); |
| 40 | 40 | } |
| 41 | - if( !empty( $reviews )) { |
|
| 41 | + if( !empty($reviews) ) { |
|
| 42 | 42 | array_walk( $reviews, function( &$review ) { |
| 43 | - unset( $review['@context'] ); |
|
| 44 | - unset( $review['itemReviewed'] ); |
|
| 43 | + unset($review['@context']); |
|
| 44 | + unset($review['itemReviewed']); |
|
| 45 | 45 | }); |
| 46 | 46 | $schema['review'] = $reviews; |
| 47 | 47 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function buildSummary( $args = null ) |
| 56 | 56 | { |
| 57 | - if( is_array( $args )) { |
|
| 57 | + if( is_array( $args ) ) { |
|
| 58 | 58 | $this->args = $args; |
| 59 | 59 | } |
| 60 | 60 | $buildSummary = glsr( Helper::class )->buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' ); |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | $schema = method_exists( $this, $buildSummary ) |
| 63 | 63 | ? $this->$buildSummary() |
| 64 | 64 | : $this->buildSummaryForCustom(); |
| 65 | - if( !empty( $count )) { |
|
| 65 | + if( !empty($count) ) { |
|
| 66 | 66 | $schema->aggregateRating( |
| 67 | 67 | $this->getSchemaType( 'AggregateRating' ) |
| 68 | 68 | ->ratingValue( $this->getRatingValue() ) |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function render() |
| 82 | 82 | { |
| 83 | - if( is_null( glsr()->schemas ))return; |
|
| 83 | + if( is_null( glsr()->schemas ) )return; |
|
| 84 | 84 | printf( '<script type="application/ld+json">%s</script>', json_encode( |
| 85 | 85 | apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
| 86 | 86 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
| 87 | - )); |
|
| 87 | + ) ); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | { |
| 95 | 95 | $schemas = glsr()->schemas; |
| 96 | 96 | $schemas[] = $schema; |
| 97 | - glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ))); |
|
| 97 | + glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) ); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -104,16 +104,16 @@ discard block |
||
| 104 | 104 | protected function buildReview( $review ) |
| 105 | 105 | { |
| 106 | 106 | $schema = $this->getSchemaType( 'Review' ) |
| 107 | - ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use( $review ) { |
|
| 107 | + ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use($review) { |
|
| 108 | 108 | $schema->name( $review->title ); |
| 109 | 109 | }) |
| 110 | - ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use( $review ) { |
|
| 110 | + ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use($review) { |
|
| 111 | 111 | $schema->reviewBody( $review->content ); |
| 112 | 112 | }) |
| 113 | - ->datePublished(( new DateTime( $review->date ))) |
|
| 114 | - ->author( $this->getSchemaType( 'Person' )->name( $review->author )) |
|
| 115 | - ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ))); |
|
| 116 | - if( !empty( $review->rating )) { |
|
| 113 | + ->datePublished( (new DateTime( $review->date )) ) |
|
| 114 | + ->author( $this->getSchemaType( 'Person' )->name( $review->author ) ) |
|
| 115 | + ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) ); |
|
| 116 | + if( !empty($review->rating) ) { |
|
| 117 | 117 | $schema->reviewRating( |
| 118 | 118 | $this->getSchemaType( 'Rating' ) |
| 119 | 119 | ->ratingValue( $review->rating ) |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | { |
| 133 | 133 | foreach( $values as $value ) { |
| 134 | 134 | $option = $this->getSchemaOptionValue( $value ); |
| 135 | - if( empty( $option ))continue; |
|
| 135 | + if( empty($option) )continue; |
|
| 136 | 136 | $schema->$value( $option ); |
| 137 | 137 | } |
| 138 | 138 | return $schema; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | { |
| 146 | 146 | return $this->buildSchemaValues( $this->getSchemaType(), [ |
| 147 | 147 | 'description', 'image', 'name', 'url', |
| 148 | - ]); |
|
| 148 | + ] ); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | { |
| 156 | 156 | return $this->buildSchemaValues( $this->buildSummaryForCustom(), [ |
| 157 | 157 | 'address', 'priceRange', 'telephone', |
| 158 | - ]); |
|
| 158 | + ] ); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -165,10 +165,10 @@ discard block |
||
| 165 | 165 | { |
| 166 | 166 | $offers = $this->buildSchemaValues( $this->getSchemaType( 'AggregateOffer' ), [ |
| 167 | 167 | 'highPrice', 'lowPrice', 'priceCurrency', |
| 168 | - ]); |
|
| 168 | + ] ); |
|
| 169 | 169 | return $this->buildSummaryForCustom() |
| 170 | 170 | ->offers( $offers ) |
| 171 | - ->setProperty( '@id', $this->getSchemaOptionValue( 'url' )); |
|
| 171 | + ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ) ); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | protected function getRatingCounts() |
| 178 | 178 | { |
| 179 | - if( !isset( $this->ratingCounts )) { |
|
| 180 | - $counts = glsr( CountsManager::class )->get([ |
|
| 181 | - 'post_ids' => array_filter( array_map( 'trim', explode( ',', $this->args['assigned_to'] ))), |
|
| 182 | - 'term_ids' => array_filter( array_map( 'trim', explode( ',', $this->args['category'] ))), |
|
| 183 | - ]); |
|
| 179 | + if( !isset($this->ratingCounts) ) { |
|
| 180 | + $counts = glsr( CountsManager::class )->get( [ |
|
| 181 | + 'post_ids' => array_filter( array_map( 'trim', explode( ',', $this->args['assigned_to'] ) ) ), |
|
| 182 | + 'term_ids' => array_filter( array_map( 'trim', explode( ',', $this->args['category'] ) ) ), |
|
| 183 | + ] ); |
|
| 184 | 184 | $this->ratingCounts = glsr( CountsManager::class )->flatten( $counts, [ |
| 185 | 185 | 'min' => $this->args['rating'], |
| 186 | - ]); |
|
| 186 | + ] ); |
|
| 187 | 187 | } |
| 188 | 188 | return $this->ratingCounts; |
| 189 | 189 | } |
@@ -204,14 +204,14 @@ discard block |
||
| 204 | 204 | protected function getSchemaOption( $option, $fallback ) |
| 205 | 205 | { |
| 206 | 206 | $option = strtolower( $option ); |
| 207 | - if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ))) { |
|
| 207 | + if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) { |
|
| 208 | 208 | return $schemaOption; |
| 209 | 209 | } |
| 210 | 210 | $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option ); |
| 211 | - if( is_array( $setting )) { |
|
| 211 | + if( is_array( $setting ) ) { |
|
| 212 | 212 | return $this->getSchemaOptionDefault( $setting, $fallback ); |
| 213 | 213 | } |
| 214 | - return !empty( $setting ) |
|
| 214 | + return !empty($setting) |
|
| 215 | 215 | ? $setting |
| 216 | 216 | : $fallback; |
| 217 | 217 | } |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | $setting = wp_parse_args( $setting, [ |
| 226 | 226 | 'custom' => '', |
| 227 | 227 | 'default' => $fallback, |
| 228 | - ]); |
|
| 228 | + ] ); |
|
| 229 | 229 | return $setting['default'] != 'custom' |
| 230 | 230 | ? $setting['default'] |
| 231 | 231 | : $setting['custom']; |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | } |
| 245 | 245 | if( !is_single() && !is_page() )return; |
| 246 | 246 | $method = glsr( Helper::class )->buildMethodName( $option, 'getThing' ); |
| 247 | - if( method_exists( $this, $method )) { |
|
| 247 | + if( method_exists( $this, $method ) ) { |
|
| 248 | 248 | return $this->$method(); |
| 249 | 249 | } |
| 250 | 250 | } |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | protected function getSchemaType( $type = null ) |
| 257 | 257 | { |
| 258 | - if( !is_string( $type )) { |
|
| 258 | + if( !is_string( $type ) ) { |
|
| 259 | 259 | $type = $this->getSchemaOption( 'type', 'LocalBusiness' ); |
| 260 | 260 | } |
| 261 | 261 | $className = glsr( Helper::class )->buildClassName( $type, 'Modules\Schema' ); |
@@ -270,11 +270,11 @@ discard block |
||
| 270 | 270 | protected function getThingDescription() |
| 271 | 271 | { |
| 272 | 272 | $post = get_post(); |
| 273 | - if( !( $post instanceof WP_Post )) { |
|
| 273 | + if( !($post instanceof WP_Post) ) { |
|
| 274 | 274 | return ''; |
| 275 | 275 | } |
| 276 | - $text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt )); |
|
| 277 | - return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 )); |
|
| 276 | + $text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt ) ); |
|
| 277 | + return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) ); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
@@ -33,14 +33,14 @@ discard block |
||
| 33 | 33 | public function build( array $args = [] ) |
| 34 | 34 | { |
| 35 | 35 | $this->args = $args; |
| 36 | - $counts = glsr( CountsManager::class )->get([ |
|
| 37 | - 'post_ids' => array_filter( array_map( 'trim', explode( ',', $args['assigned_to'] ))), |
|
| 38 | - 'term_ids' => array_filter( array_map( 'trim', explode( ',', $args['category'] ))), |
|
| 39 | - ]); |
|
| 36 | + $counts = glsr( CountsManager::class )->get( [ |
|
| 37 | + 'post_ids' => array_filter( array_map( 'trim', explode( ',', $args['assigned_to'] ) ) ), |
|
| 38 | + 'term_ids' => array_filter( array_map( 'trim', explode( ',', $args['category'] ) ) ), |
|
| 39 | + ] ); |
|
| 40 | 40 | $this->ratingCounts = glsr( CountsManager::class )->flatten( $counts, [ |
| 41 | 41 | 'min' => $args['rating'], |
| 42 | - ]); |
|
| 43 | - if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ))return; |
|
| 42 | + ] ); |
|
| 43 | + if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ) )return; |
|
| 44 | 44 | $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts ); |
| 45 | 45 | $this->generateSchema(); |
| 46 | 46 | return glsr( Template::class )->build( 'templates/reviews-summary', [ |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | 'stars' => $this->buildStars(), |
| 53 | 53 | 'text' => $this->buildText(), |
| 54 | 54 | ], |
| 55 | - ]); |
|
| 55 | + ] ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,16 +60,16 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | protected function buildPercentage() |
| 62 | 62 | { |
| 63 | - if( $this->isHidden( 'bars' ))return; |
|
| 63 | + if( $this->isHidden( 'bars' ) )return; |
|
| 64 | 64 | $range = range( Rating::MAX_RATING, 1 ); |
| 65 | - $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts )); |
|
| 66 | - $bars = array_reduce( $range, function( $carry, $level ) use( $percentages ) { |
|
| 65 | + $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts ) ); |
|
| 66 | + $bars = array_reduce( $range, function( $carry, $level ) use($percentages) { |
|
| 67 | 67 | $label = $this->buildPercentageLabel( $this->args['labels'][$level] ); |
| 68 | 68 | $background = $this->buildPercentageBackground( $percentages[$level] ); |
| 69 | 69 | $percent = $this->buildPercentagePercent( $percentages[$level] ); |
| 70 | 70 | return $carry.glsr( Builder::class )->div( $label.$background.$percent, [ |
| 71 | 71 | 'class' => 'glsr-bar', |
| 72 | - ]); |
|
| 72 | + ] ); |
|
| 73 | 73 | }); |
| 74 | 74 | return $this->wrap( 'percentage', $bars ); |
| 75 | 75 | } |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | protected function buildPercentageBackground( $percent ) |
| 82 | 82 | { |
| 83 | - $backgroundPercent = glsr( Builder::class )->span([ |
|
| 83 | + $backgroundPercent = glsr( Builder::class )->span( [ |
|
| 84 | 84 | 'class' => 'glsr-bar-background-percent', |
| 85 | 85 | 'style' => 'width:'.$percent, |
| 86 | - ]); |
|
| 86 | + ] ); |
|
| 87 | 87 | return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>'; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | protected function buildRating() |
| 112 | 112 | { |
| 113 | - if( $this->isHidden( 'rating' ))return; |
|
| 113 | + if( $this->isHidden( 'rating' ) )return; |
|
| 114 | 114 | return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' ); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | protected function buildStars() |
| 121 | 121 | { |
| 122 | - if( $this->isHidden( 'stars' ))return; |
|
| 122 | + if( $this->isHidden( 'stars' ) )return; |
|
| 123 | 123 | $stars = glsr( Partial::class )->build( 'star-rating', [ |
| 124 | 124 | 'rating' => $this->averageRating, |
| 125 | - ]); |
|
| 125 | + ] ); |
|
| 126 | 126 | return $this->wrap( 'stars', $stars ); |
| 127 | 127 | } |
| 128 | 128 | |
@@ -131,9 +131,9 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | protected function buildText() |
| 133 | 133 | { |
| 134 | - if( $this->isHidden( 'summary' ))return; |
|
| 135 | - $count = intval( array_sum( $this->ratingCounts )); |
|
| 136 | - if( empty( $this->args['text'] )) { |
|
| 134 | + if( $this->isHidden( 'summary' ) )return; |
|
| 135 | + $count = intval( array_sum( $this->ratingCounts ) ); |
|
| 136 | + if( empty($this->args['text']) ) { |
|
| 137 | 137 | // @todo document this change |
| 138 | 138 | $this->args['text'] = _nx( |
| 139 | 139 | '{rating} out of {max} stars (based on {num} review)', |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | ); |
| 145 | 145 | } |
| 146 | 146 | $summary = str_replace( |
| 147 | - ['{rating}','{max}', '{num}'], |
|
| 147 | + ['{rating}', '{max}', '{num}'], |
|
| 148 | 148 | [$this->averageRating, Rating::MAX_RATING, $count], |
| 149 | 149 | $this->args['text'] |
| 150 | 150 | ); |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | protected function generateSchema() |
| 158 | 158 | { |
| 159 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
| 159 | + if( !wp_validate_boolean( $this->args['schema'] ) )return; |
|
| 160 | 160 | glsr( Schema::class )->store( |
| 161 | 161 | glsr( Schema::class )->buildSummary( $this->args ) |
| 162 | 162 | ); |
@@ -188,6 +188,6 @@ discard block |
||
| 188 | 188 | { |
| 189 | 189 | return glsr( Builder::class )->div( $value, [ |
| 190 | 190 | 'class' => 'glsr-summary-'.$key, |
| 191 | - ]); |
|
| 191 | + ] ); |
|
| 192 | 192 | } |
| 193 | 193 | } |
@@ -40,7 +40,9 @@ discard block |
||
| 40 | 40 | $this->ratingCounts = glsr( CountsManager::class )->flatten( $counts, [ |
| 41 | 41 | 'min' => $args['rating'], |
| 42 | 42 | ]); |
| 43 | - if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ))return; |
|
| 43 | + if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' )) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 44 | 46 | $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts ); |
| 45 | 47 | $this->generateSchema(); |
| 46 | 48 | return glsr( Template::class )->build( 'templates/reviews-summary', [ |
@@ -60,7 +62,9 @@ discard block |
||
| 60 | 62 | */ |
| 61 | 63 | protected function buildPercentage() |
| 62 | 64 | { |
| 63 | - if( $this->isHidden( 'bars' ))return; |
|
| 65 | + if( $this->isHidden( 'bars' )) { |
|
| 66 | + return; |
|
| 67 | + } |
|
| 64 | 68 | $range = range( Rating::MAX_RATING, 1 ); |
| 65 | 69 | $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts )); |
| 66 | 70 | $bars = array_reduce( $range, function( $carry, $level ) use( $percentages ) { |
@@ -110,7 +114,9 @@ discard block |
||
| 110 | 114 | */ |
| 111 | 115 | protected function buildRating() |
| 112 | 116 | { |
| 113 | - if( $this->isHidden( 'rating' ))return; |
|
| 117 | + if( $this->isHidden( 'rating' )) { |
|
| 118 | + return; |
|
| 119 | + } |
|
| 114 | 120 | return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' ); |
| 115 | 121 | } |
| 116 | 122 | |
@@ -119,7 +125,9 @@ discard block |
||
| 119 | 125 | */ |
| 120 | 126 | protected function buildStars() |
| 121 | 127 | { |
| 122 | - if( $this->isHidden( 'stars' ))return; |
|
| 128 | + if( $this->isHidden( 'stars' )) { |
|
| 129 | + return; |
|
| 130 | + } |
|
| 123 | 131 | $stars = glsr( Partial::class )->build( 'star-rating', [ |
| 124 | 132 | 'rating' => $this->averageRating, |
| 125 | 133 | ]); |
@@ -131,7 +139,9 @@ discard block |
||
| 131 | 139 | */ |
| 132 | 140 | protected function buildText() |
| 133 | 141 | { |
| 134 | - if( $this->isHidden( 'summary' ))return; |
|
| 142 | + if( $this->isHidden( 'summary' )) { |
|
| 143 | + return; |
|
| 144 | + } |
|
| 135 | 145 | $count = intval( array_sum( $this->ratingCounts )); |
| 136 | 146 | if( empty( $this->args['text'] )) { |
| 137 | 147 | // @todo document this change |
@@ -156,7 +166,9 @@ discard block |
||
| 156 | 166 | */ |
| 157 | 167 | protected function generateSchema() |
| 158 | 168 | { |
| 159 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
| 169 | + if( !wp_validate_boolean( $this->args['schema'] )) { |
|
| 170 | + return; |
|
| 171 | + } |
|
| 160 | 172 | glsr( Schema::class )->store( |
| 161 | 173 | glsr( Schema::class )->buildSummary( $this->args ) |
| 162 | 174 | ); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $this->getCounts(), |
| 66 | 66 | $review->review_type, |
| 67 | 67 | $review->rating |
| 68 | - )); |
|
| 68 | + ) ); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function decreasePostCounts( Review $review ) |
| 75 | 75 | { |
| 76 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
| 76 | + if( empty($counts = $this->getPostCounts( $review->assigned_to )) )return; |
|
| 77 | 77 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 78 | 78 | $this->setPostCounts( $review->assigned_to, $counts ); |
| 79 | 79 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | public function decreaseTermCounts( Review $review ) |
| 85 | 85 | { |
| 86 | 86 | foreach( $review->term_ids as $termId ) { |
| 87 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
| 87 | + if( empty($counts = $this->getTermCounts( $termId )) )continue; |
|
| 88 | 88 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 89 | 89 | $this->setTermCounts( $termId, $counts ); |
| 90 | 90 | } |
@@ -96,17 +96,17 @@ discard block |
||
| 96 | 96 | public function flatten( array $reviewCounts, array $args = [] ) |
| 97 | 97 | { |
| 98 | 98 | $counts = []; |
| 99 | - array_walk_recursive( $reviewCounts, function( $num, $index ) use( &$counts ) { |
|
| 100 | - $counts[$index] = isset( $counts[$index] ) |
|
| 99 | + array_walk_recursive( $reviewCounts, function( $num, $index ) use(&$counts) { |
|
| 100 | + $counts[$index] = isset($counts[$index]) |
|
| 101 | 101 | ? $num + $counts[$index] |
| 102 | 102 | : $num; |
| 103 | 103 | }); |
| 104 | 104 | $args = wp_parse_args( $args, [ |
| 105 | 105 | 'max' => Rating::MAX_RATING, |
| 106 | 106 | 'min' => Rating::MIN_RATING, |
| 107 | - ]); |
|
| 107 | + ] ); |
|
| 108 | 108 | foreach( $counts as $index => &$num ) { |
| 109 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 109 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ) )continue; |
|
| 110 | 110 | $num = 0; |
| 111 | 111 | } |
| 112 | 112 | return $counts; |
@@ -121,17 +121,17 @@ discard block |
||
| 121 | 121 | 'post_ids' => [], |
| 122 | 122 | 'term_ids' => [], |
| 123 | 123 | 'type' => 'local', |
| 124 | - ]); |
|
| 124 | + ] ); |
|
| 125 | 125 | $counts = []; |
| 126 | 126 | foreach( $args['post_ids'] as $postId ) { |
| 127 | 127 | $counts[] = $this->getPostCounts( $postId ); |
| 128 | 128 | } |
| 129 | 129 | foreach( $args['term_ids'] as $termId ) { |
| 130 | 130 | $term = get_term( $termId, Application::TAXONOMY ); |
| 131 | - if( !isset( $term->term_id ))continue; |
|
| 131 | + if( !isset($term->term_id) )continue; |
|
| 132 | 132 | $counts[] = $this->getTermCounts( $termId ); |
| 133 | 133 | } |
| 134 | - if( empty( $counts )) { |
|
| 134 | + if( empty($counts) ) { |
|
| 135 | 135 | $counts[] = $this->getCounts(); |
| 136 | 136 | } |
| 137 | 137 | return array_column( $counts, $args['type'] ); |
@@ -178,14 +178,14 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public function increaseCounts( Review $review ) |
| 180 | 180 | { |
| 181 | - if( empty( $counts = $this->getCounts() )) { |
|
| 181 | + if( empty($counts = $this->getCounts()) ) { |
|
| 182 | 182 | $counts = $this->buildCounts(); |
| 183 | 183 | } |
| 184 | 184 | $this->setCounts( $this->increaseRating( |
| 185 | 185 | $counts, |
| 186 | 186 | $review->review_type, |
| 187 | 187 | $review->rating |
| 188 | - )); |
|
| 188 | + ) ); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -193,8 +193,8 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | public function increasePostCounts( Review $review ) |
| 195 | 195 | { |
| 196 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 197 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) { |
|
| 196 | + if( !(get_post( $review->assigned_to ) instanceof WP_Post) )return; |
|
| 197 | + if( empty($counts = $this->getPostCounts( $review->assigned_to )) ) { |
|
| 198 | 198 | $counts = $this->buildPostCounts( $review->assigned_to ); |
| 199 | 199 | } |
| 200 | 200 | $counts = $this->increaseRating( $counts, $review->review_type, $review->rating ); |
@@ -207,8 +207,8 @@ discard block |
||
| 207 | 207 | public function increaseTermCounts( Review $review ) |
| 208 | 208 | { |
| 209 | 209 | foreach( $review->term_ids as $termId ) { |
| 210 | - if( !( get_term( $termId, Application::TAXONOMY ) instanceof WP_Term ))continue; |
|
| 211 | - if( empty( $counts = $this->getTermCounts( $termId ))) { |
|
| 210 | + if( !(get_term( $termId, Application::TAXONOMY ) instanceof WP_Term) )continue; |
|
| 211 | + if( empty($counts = $this->getTermCounts( $termId )) ) { |
|
| 212 | 212 | $counts = $this->buildTermCounts( $termId ); |
| 213 | 213 | } |
| 214 | 214 | $counts = $this->increaseRating( $counts, $review->review_type, $review->rating ); |
@@ -232,8 +232,8 @@ discard block |
||
| 232 | 232 | { |
| 233 | 233 | $ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts ); |
| 234 | 234 | update_post_meta( $postId, static::META_COUNT, $reviewCounts ); |
| 235 | - update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 236 | - update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 235 | + update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 236 | + update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -242,11 +242,11 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | public function setTermCounts( $termId, array $reviewCounts ) |
| 244 | 244 | { |
| 245 | - if( !term_exists( $termId ))return; |
|
| 245 | + if( !term_exists( $termId ) )return; |
|
| 246 | 246 | $ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts ); |
| 247 | 247 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 248 | - update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 249 | - update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 248 | + update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 249 | + update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -257,10 +257,10 @@ discard block |
||
| 257 | 257 | { |
| 258 | 258 | $counts = []; |
| 259 | 259 | $lastPostId = 0; |
| 260 | - while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) { |
|
| 261 | - $types = array_keys( array_flip( array_column( $reviews, 'type' ))); |
|
| 260 | + while( $reviews = $this->queryReviews( $args, $lastPostId, $limit ) ) { |
|
| 261 | + $types = array_keys( array_flip( array_column( $reviews, 'type' ) ) ); |
|
| 262 | 262 | foreach( $types as $type ) { |
| 263 | - if( isset( $counts[$type] ))continue; |
|
| 263 | + if( isset($counts[$type]) )continue; |
|
| 264 | 264 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 265 | 265 | } |
| 266 | 266 | foreach( $reviews as $review ) { |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | */ |
| 279 | 279 | protected function decreaseRating( array $reviewCounts, $type, $rating ) |
| 280 | 280 | { |
| 281 | - if( isset( $reviewCounts[$type][$rating] )) { |
|
| 281 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
| 282 | 282 | $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
| 283 | 283 | } |
| 284 | 284 | return $reviewCounts; |
@@ -291,10 +291,10 @@ discard block |
||
| 291 | 291 | */ |
| 292 | 292 | protected function increaseRating( array $reviewCounts, $type, $rating ) |
| 293 | 293 | { |
| 294 | - if( !array_key_exists( $type, glsr()->reviewTypes )) { |
|
| 294 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
| 295 | 295 | return $reviewCounts; |
| 296 | 296 | } |
| 297 | - if( !array_key_exists( $type, $reviewCounts )) { |
|
| 297 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
| 298 | 298 | $reviewCounts[$type] = []; |
| 299 | 299 | } |
| 300 | 300 | $reviewCounts = $this->normalize( $reviewCounts ); |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | { |
| 310 | 310 | foreach( $reviewCounts as &$counts ) { |
| 311 | 311 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 312 | - if( isset( $counts[$index] ))continue; |
|
| 312 | + if( isset($counts[$index]) )continue; |
|
| 313 | 313 | $counts[$index] = 0; |
| 314 | 314 | } |
| 315 | 315 | ksort( $counts ); |
@@ -324,14 +324,14 @@ discard block |
||
| 324 | 324 | */ |
| 325 | 325 | protected function queryReviews( array $args = [], $lastPostId, $limit ) |
| 326 | 326 | { |
| 327 | - $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' )); |
|
| 328 | - if( empty( array_filter( $args ))) { |
|
| 327 | + $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' ) ); |
|
| 328 | + if( empty(array_filter( $args )) ) { |
|
| 329 | 329 | return glsr( SqlQueries::class )->getReviewCounts( $lastPostId, $limit ); |
| 330 | 330 | } |
| 331 | - if( !empty( $args['post_id'] )) { |
|
| 331 | + if( !empty($args['post_id']) ) { |
|
| 332 | 332 | return glsr( SqlQueries::class )->getReviewPostCounts( $args['post_id'], $lastPostId, $limit ); |
| 333 | 333 | } |
| 334 | - if( !empty( $args['term_id'] )) { |
|
| 334 | + if( !empty($args['term_id']) ) { |
|
| 335 | 335 | return glsr( SqlQueries::class )->getReviewTermCounts( $args['term_id'], $lastPostId, $limit ); |
| 336 | 336 | } |
| 337 | 337 | } |
@@ -73,7 +73,9 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function decreasePostCounts( Review $review ) |
| 75 | 75 | { |
| 76 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
| 76 | + if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) { |
|
| 77 | + return; |
|
| 78 | + } |
|
| 77 | 79 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 78 | 80 | $this->setPostCounts( $review->assigned_to, $counts ); |
| 79 | 81 | } |
@@ -84,7 +86,9 @@ discard block |
||
| 84 | 86 | public function decreaseTermCounts( Review $review ) |
| 85 | 87 | { |
| 86 | 88 | foreach( $review->term_ids as $termId ) { |
| 87 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
| 89 | + if( empty( $counts = $this->getTermCounts( $termId ))) { |
|
| 90 | + continue; |
|
| 91 | + } |
|
| 88 | 92 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 89 | 93 | $this->setTermCounts( $termId, $counts ); |
| 90 | 94 | } |
@@ -106,7 +110,9 @@ discard block |
||
| 106 | 110 | 'min' => Rating::MIN_RATING, |
| 107 | 111 | ]); |
| 108 | 112 | foreach( $counts as $index => &$num ) { |
| 109 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 113 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] )) { |
|
| 114 | + continue; |
|
| 115 | + } |
|
| 110 | 116 | $num = 0; |
| 111 | 117 | } |
| 112 | 118 | return $counts; |
@@ -128,7 +134,9 @@ discard block |
||
| 128 | 134 | } |
| 129 | 135 | foreach( $args['term_ids'] as $termId ) { |
| 130 | 136 | $term = get_term( $termId, Application::TAXONOMY ); |
| 131 | - if( !isset( $term->term_id ))continue; |
|
| 137 | + if( !isset( $term->term_id )) { |
|
| 138 | + continue; |
|
| 139 | + } |
|
| 132 | 140 | $counts[] = $this->getTermCounts( $termId ); |
| 133 | 141 | } |
| 134 | 142 | if( empty( $counts )) { |
@@ -193,7 +201,9 @@ discard block |
||
| 193 | 201 | */ |
| 194 | 202 | public function increasePostCounts( Review $review ) |
| 195 | 203 | { |
| 196 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 204 | + if( !( get_post( $review->assigned_to ) instanceof WP_Post )) { |
|
| 205 | + return; |
|
| 206 | + } |
|
| 197 | 207 | if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) { |
| 198 | 208 | $counts = $this->buildPostCounts( $review->assigned_to ); |
| 199 | 209 | } |
@@ -207,7 +217,9 @@ discard block |
||
| 207 | 217 | public function increaseTermCounts( Review $review ) |
| 208 | 218 | { |
| 209 | 219 | foreach( $review->term_ids as $termId ) { |
| 210 | - if( !( get_term( $termId, Application::TAXONOMY ) instanceof WP_Term ))continue; |
|
| 220 | + if( !( get_term( $termId, Application::TAXONOMY ) instanceof WP_Term )) { |
|
| 221 | + continue; |
|
| 222 | + } |
|
| 211 | 223 | if( empty( $counts = $this->getTermCounts( $termId ))) { |
| 212 | 224 | $counts = $this->buildTermCounts( $termId ); |
| 213 | 225 | } |
@@ -242,7 +254,9 @@ discard block |
||
| 242 | 254 | */ |
| 243 | 255 | public function setTermCounts( $termId, array $reviewCounts ) |
| 244 | 256 | { |
| 245 | - if( !term_exists( $termId ))return; |
|
| 257 | + if( !term_exists( $termId )) { |
|
| 258 | + return; |
|
| 259 | + } |
|
| 246 | 260 | $ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts ); |
| 247 | 261 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 248 | 262 | update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
@@ -260,7 +274,9 @@ discard block |
||
| 260 | 274 | while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) { |
| 261 | 275 | $types = array_keys( array_flip( array_column( $reviews, 'type' ))); |
| 262 | 276 | foreach( $types as $type ) { |
| 263 | - if( isset( $counts[$type] ))continue; |
|
| 277 | + if( isset( $counts[$type] )) { |
|
| 278 | + continue; |
|
| 279 | + } |
|
| 264 | 280 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 265 | 281 | } |
| 266 | 282 | foreach( $reviews as $review ) { |
@@ -309,7 +325,9 @@ discard block |
||
| 309 | 325 | { |
| 310 | 326 | foreach( $reviewCounts as &$counts ) { |
| 311 | 327 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 312 | - if( isset( $counts[$index] ))continue; |
|
| 328 | + if( isset( $counts[$index] )) { |
|
| 329 | + continue; |
|
| 330 | + } |
|
| 313 | 331 | $counts[$index] = 0; |
| 314 | 332 | } |
| 315 | 333 | ksort( $counts ); |