@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | natsort( $routines ); |
| 18 | 18 | array_walk( $routines, function( $routine ) { |
| 19 | 19 | $parts = explode( '__', $routine ); |
| 20 | - if( version_compare( glsr()->version, end( $parts ), '<' ))return; |
|
| 20 | + if( version_compare( glsr()->version, end( $parts ), '<' ) )return; |
|
| 21 | 21 | call_user_func( [$this, $routine] ); |
| 22 | 22 | }); |
| 23 | 23 | $this->updateVersion(); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | public function updateVersion() |
| 30 | 30 | { |
| 31 | 31 | $currentVersion = glsr( OptionManager::class )->get( 'version' ); |
| 32 | - if( version_compare( $currentVersion, glsr()->version, '<' )) { |
|
| 32 | + if( version_compare( $currentVersion, glsr()->version, '<' ) ) { |
|
| 33 | 33 | glsr( OptionManager::class )->set( 'version', glsr()->version ); |
| 34 | 34 | } |
| 35 | 35 | if( $currentVersion != glsr()->version ) { |
@@ -17,7 +17,9 @@ |
||
| 17 | 17 | natsort( $routines ); |
| 18 | 18 | array_walk( $routines, function( $routine ) { |
| 19 | 19 | $parts = explode( '__', $routine ); |
| 20 | - if( version_compare( glsr()->version, end( $parts ), '<' ))return; |
|
| 20 | + if( version_compare( glsr()->version, end( $parts ), '<' )) { |
|
| 21 | + return; |
|
| 22 | + } |
|
| 21 | 23 | call_user_func( [$this, $routine] ); |
| 22 | 24 | }); |
| 23 | 25 | $this->updateVersion(); |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | if( $review->review_type != 'local' )continue; |
| 44 | 44 | $reviews[] = $this->buildReview( $review ); |
| 45 | 45 | } |
| 46 | - if( !empty( $reviews )) { |
|
| 46 | + if( !empty($reviews) ) { |
|
| 47 | 47 | array_walk( $reviews, function( &$review ) { |
| 48 | - unset( $review['@context'] ); |
|
| 49 | - unset( $review['itemReviewed'] ); |
|
| 48 | + unset($review['@context']); |
|
| 49 | + unset($review['itemReviewed']); |
|
| 50 | 50 | }); |
| 51 | 51 | $schema['review'] = $reviews; |
| 52 | 52 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function buildSummary( $args = null ) |
| 61 | 61 | { |
| 62 | - if( is_array( $args )) { |
|
| 62 | + if( is_array( $args ) ) { |
|
| 63 | 63 | $this->args = $args; |
| 64 | 64 | } |
| 65 | 65 | $buildSummary = glsr( Helper::class )->buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' ); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $schema = method_exists( $this, $buildSummary ) |
| 68 | 68 | ? $this->$buildSummary() |
| 69 | 69 | : $this->buildSummaryForCustom(); |
| 70 | - if( !empty( $count )) { |
|
| 70 | + if( !empty($count) ) { |
|
| 71 | 71 | $schema->aggregateRating( |
| 72 | 72 | $this->getSchemaType( 'AggregateRating' ) |
| 73 | 73 | ->ratingValue( $this->getRatingValue() ) |
@@ -85,11 +85,11 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function render() |
| 87 | 87 | { |
| 88 | - if( is_null( glsr()->schemas ))return; |
|
| 88 | + if( is_null( glsr()->schemas ) )return; |
|
| 89 | 89 | printf( '<script type="application/ld+json">%s</script>', json_encode( |
| 90 | 90 | apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
| 91 | 91 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
| 92 | - )); |
|
| 92 | + ) ); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | { |
| 100 | 100 | $schemas = glsr()->schemas; |
| 101 | 101 | $schemas[] = $schema; |
| 102 | - glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ))); |
|
| 102 | + glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) ); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -109,16 +109,16 @@ discard block |
||
| 109 | 109 | protected function buildReview( $review ) |
| 110 | 110 | { |
| 111 | 111 | $schema = $this->getSchemaType( 'Review' ) |
| 112 | - ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use( $review ) { |
|
| 112 | + ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use($review) { |
|
| 113 | 113 | $schema->name( $review->title ); |
| 114 | 114 | }) |
| 115 | - ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use( $review ) { |
|
| 115 | + ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use($review) { |
|
| 116 | 116 | $schema->reviewBody( $review->content ); |
| 117 | 117 | }) |
| 118 | - ->datePublished(( new DateTime( $review->date ))) |
|
| 119 | - ->author( $this->getSchemaType( 'Person' )->name( $review->author )) |
|
| 120 | - ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ))); |
|
| 121 | - if( !empty( $review->rating )) { |
|
| 118 | + ->datePublished( (new DateTime( $review->date )) ) |
|
| 119 | + ->author( $this->getSchemaType( 'Person' )->name( $review->author ) ) |
|
| 120 | + ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) ); |
|
| 121 | + if( !empty($review->rating) ) { |
|
| 122 | 122 | $schema->reviewRating( |
| 123 | 123 | $this->getSchemaType( 'Rating' ) |
| 124 | 124 | ->ratingValue( $review->rating ) |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | { |
| 138 | 138 | foreach( $values as $value ) { |
| 139 | 139 | $option = $this->getSchemaOptionValue( $value ); |
| 140 | - if( empty( $option ))continue; |
|
| 140 | + if( empty($option) )continue; |
|
| 141 | 141 | $schema->$value( $option ); |
| 142 | 142 | } |
| 143 | 143 | return $schema; |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | return $this->buildSchemaValues( $this->getSchemaType(), [ |
| 152 | 152 | 'description', 'image', 'name', 'url', |
| 153 | - ]); |
|
| 153 | + ] ); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | { |
| 161 | 161 | return $this->buildSchemaValues( $this->buildSummaryForCustom(), [ |
| 162 | 162 | 'address', 'priceRange', 'telephone', |
| 163 | - ]); |
|
| 163 | + ] ); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | { |
| 171 | 171 | $offers = $this->buildSchemaValues( $this->getSchemaType( 'AggregateOffer' ), [ |
| 172 | 172 | 'highPrice', 'lowPrice', 'priceCurrency', |
| 173 | - ]); |
|
| 173 | + ] ); |
|
| 174 | 174 | return $this->buildSummaryForCustom() |
| 175 | 175 | ->offers( $offers ) |
| 176 | - ->setProperty( '@id', $this->getSchemaOptionValue( 'url' )); |
|
| 176 | + ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ) ); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -181,16 +181,16 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | protected function getRatingCounts() |
| 183 | 183 | { |
| 184 | - if( !isset( $this->ratingCounts )) { |
|
| 184 | + if( !isset($this->ratingCounts) ) { |
|
| 185 | 185 | $this->setPostCounts(); |
| 186 | 186 | $this->setTermCounts(); |
| 187 | - if( empty( $this->reviewCounts )) { |
|
| 187 | + if( empty($this->reviewCounts) ) { |
|
| 188 | 188 | $this->reviewCounts = glsr( CountsManager::class )->getCounts(); |
| 189 | 189 | } |
| 190 | 190 | $counts = array_column( $this->reviewCounts, 'local' ); |
| 191 | 191 | $this->ratingCounts = glsr( CountsManager::class )->flatten( $counts, [ |
| 192 | 192 | 'min' => $this->args['rating'], |
| 193 | - ]); |
|
| 193 | + ] ); |
|
| 194 | 194 | } |
| 195 | 195 | return $this->ratingCounts; |
| 196 | 196 | } |
@@ -211,14 +211,14 @@ discard block |
||
| 211 | 211 | protected function getSchemaOption( $option, $fallback ) |
| 212 | 212 | { |
| 213 | 213 | $option = strtolower( $option ); |
| 214 | - if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ))) { |
|
| 214 | + if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) { |
|
| 215 | 215 | return $schemaOption; |
| 216 | 216 | } |
| 217 | 217 | $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option ); |
| 218 | - if( is_array( $setting )) { |
|
| 218 | + if( is_array( $setting ) ) { |
|
| 219 | 219 | return $this->getSchemaOptionDefault( $setting, $fallback ); |
| 220 | 220 | } |
| 221 | - return !empty( $setting ) |
|
| 221 | + return !empty($setting) |
|
| 222 | 222 | ? $setting |
| 223 | 223 | : $fallback; |
| 224 | 224 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | $setting = wp_parse_args( $setting, [ |
| 233 | 233 | 'custom' => '', |
| 234 | 234 | 'default' => $fallback, |
| 235 | - ]); |
|
| 235 | + ] ); |
|
| 236 | 236 | return $setting['default'] != 'custom' |
| 237 | 237 | ? $setting['default'] |
| 238 | 238 | : $setting['custom']; |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | } |
| 252 | 252 | if( !is_single() && !is_page() )return; |
| 253 | 253 | $method = glsr( Helper::class )->buildMethodName( $option, 'getThing' ); |
| 254 | - if( method_exists( $this, $method )) { |
|
| 254 | + if( method_exists( $this, $method ) ) { |
|
| 255 | 255 | return $this->$method(); |
| 256 | 256 | } |
| 257 | 257 | } |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | protected function getSchemaType( $type = null ) |
| 264 | 264 | { |
| 265 | - if( !is_string( $type )) { |
|
| 265 | + if( !is_string( $type ) ) { |
|
| 266 | 266 | $type = $this->getSchemaOption( 'type', 'LocalBusiness' ); |
| 267 | 267 | } |
| 268 | 268 | $className = glsr( Helper::class )->buildClassName( $type, 'Modules\Schema' ); |
@@ -277,11 +277,11 @@ discard block |
||
| 277 | 277 | protected function getThingDescription() |
| 278 | 278 | { |
| 279 | 279 | $post = get_post(); |
| 280 | - if( !( $post instanceof WP_Post )) { |
|
| 280 | + if( !($post instanceof WP_Post) ) { |
|
| 281 | 281 | return ''; |
| 282 | 282 | } |
| 283 | - $text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt )); |
|
| 284 | - return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 )); |
|
| 283 | + $text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt ) ); |
|
| 284 | + return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) ); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | protected function setPostCounts() |
| 315 | 315 | { |
| 316 | - $postIds = array_map( 'trim', explode( ',', $this->args['assigned_to'] )); |
|
| 316 | + $postIds = array_map( 'trim', explode( ',', $this->args['assigned_to'] ) ); |
|
| 317 | 317 | foreach( $postIds as $postId ) { |
| 318 | 318 | $this->reviewCounts[] = glsr( CountsManager::class )->getPostCounts( $postId ); |
| 319 | 319 | } |
@@ -324,10 +324,10 @@ discard block |
||
| 324 | 324 | */ |
| 325 | 325 | protected function setTermCounts() |
| 326 | 326 | { |
| 327 | - $termIds = array_map( 'trim', explode( ',', $this->args['category'] )); |
|
| 327 | + $termIds = array_map( 'trim', explode( ',', $this->args['category'] ) ); |
|
| 328 | 328 | foreach( $termIds as $termId ) { |
| 329 | 329 | $term = get_term( $termId, Application::TAXONOMY ); |
| 330 | - if( !isset( $term->term_id ))continue; |
|
| 330 | + if( !isset($term->term_id) )continue; |
|
| 331 | 331 | $this->reviewCounts[] = glsr( CountsManager::class )->getTermCounts( $termId ); |
| 332 | 332 | } |
| 333 | 333 | } |
@@ -40,7 +40,9 @@ discard block |
||
| 40 | 40 | foreach( glsr( ReviewManager::class )->get( $this->args )->results as $review ) { |
| 41 | 41 | // Only include critic reviews that have been directly produced by your site, not reviews from third- party sites or syndicated reviews. |
| 42 | 42 | // @see https://developers.google.com/search/docs/data-types/review |
| 43 | - if( $review->review_type != 'local' )continue; |
|
| 43 | + if( $review->review_type != 'local' ) { |
|
| 44 | + continue; |
|
| 45 | + } |
|
| 44 | 46 | $reviews[] = $this->buildReview( $review ); |
| 45 | 47 | } |
| 46 | 48 | if( !empty( $reviews )) { |
@@ -85,7 +87,9 @@ discard block |
||
| 85 | 87 | */ |
| 86 | 88 | public function render() |
| 87 | 89 | { |
| 88 | - if( is_null( glsr()->schemas ))return; |
|
| 90 | + if( is_null( glsr()->schemas )) { |
|
| 91 | + return; |
|
| 92 | + } |
|
| 89 | 93 | printf( '<script type="application/ld+json">%s</script>', json_encode( |
| 90 | 94 | apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
| 91 | 95 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
@@ -137,7 +141,9 @@ discard block |
||
| 137 | 141 | { |
| 138 | 142 | foreach( $values as $value ) { |
| 139 | 143 | $option = $this->getSchemaOptionValue( $value ); |
| 140 | - if( empty( $option ))continue; |
|
| 144 | + if( empty( $option )) { |
|
| 145 | + continue; |
|
| 146 | + } |
|
| 141 | 147 | $schema->$value( $option ); |
| 142 | 148 | } |
| 143 | 149 | return $schema; |
@@ -249,7 +255,9 @@ discard block |
||
| 249 | 255 | if( $value != $fallback ) { |
| 250 | 256 | return $value; |
| 251 | 257 | } |
| 252 | - if( !is_single() && !is_page() )return; |
|
| 258 | + if( !is_single() && !is_page() ) { |
|
| 259 | + return; |
|
| 260 | + } |
|
| 253 | 261 | $method = glsr( Helper::class )->buildMethodName( $option, 'getThing' ); |
| 254 | 262 | if( method_exists( $this, $method )) { |
| 255 | 263 | return $this->$method(); |
@@ -327,7 +335,9 @@ discard block |
||
| 327 | 335 | $termIds = array_map( 'trim', explode( ',', $this->args['category'] )); |
| 328 | 336 | foreach( $termIds as $termId ) { |
| 329 | 337 | $term = get_term( $termId, Application::TAXONOMY ); |
| 330 | - if( !isset( $term->term_id ))continue; |
|
| 338 | + if( !isset( $term->term_id )) { |
|
| 339 | + continue; |
|
| 340 | + } |
|
| 331 | 341 | $this->reviewCounts[] = glsr( CountsManager::class )->getTermCounts( $termId ); |
| 332 | 342 | } |
| 333 | 343 | } |
@@ -23,11 +23,11 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function deleteAllSessions( $sessionCookiePrefix ) |
| 25 | 25 | { |
| 26 | - return $this->db->query(" |
|
| 26 | + return $this->db->query( " |
|
| 27 | 27 | DELETE |
| 28 | 28 | FROM {$this->db->options} |
| 29 | 29 | WHERE option_name LIKE '{$sessionCookiePrefix}_%' |
| 30 | - "); |
|
| 30 | + " ); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function deleteExpiredSessions( $expiredSessions ) |
| 38 | 38 | { |
| 39 | - return $this->db->query(" |
|
| 39 | + return $this->db->query( " |
|
| 40 | 40 | DELETE |
| 41 | 41 | FROM {$this->db->options} |
| 42 | 42 | WHERE option_name IN ('{$expiredSessions}') |
| 43 | - "); |
|
| 43 | + " ); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -49,14 +49,14 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function getReviewCountsFor( $metaKey ) |
| 51 | 51 | { |
| 52 | - return (array) $this->db->get_results(" |
|
| 52 | + return (array)$this->db->get_results( " |
|
| 53 | 53 | SELECT m.meta_value AS name, COUNT(*) num_posts |
| 54 | 54 | FROM {$this->db->posts} AS p |
| 55 | 55 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
| 56 | 56 | WHERE p.post_type = '{$this->postType}' |
| 57 | 57 | AND m.meta_key = '{$metaKey}' |
| 58 | 58 | GROUP BY name |
| 59 | - "); |
|
| 59 | + " ); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function getExpiredSessions( $sessionCookiePrefix, $limit ) |
| 68 | 68 | { |
| 69 | - return $this->db->get_results(" |
|
| 69 | + return $this->db->get_results( " |
|
| 70 | 70 | SELECT option_name AS name, option_value AS expiration |
| 71 | 71 | FROM {$this->db->options} |
| 72 | 72 | WHERE option_name LIKE '{$sessionCookiePrefix}_expires_%' |
| 73 | 73 | ORDER BY option_value ASC |
| 74 | 74 | LIMIT 0, {$limit} |
| 75 | - "); |
|
| 75 | + " ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function getReviewCounts( $lastPostId = 0, $limit = 500 ) |
| 84 | 84 | { |
| 85 | - return $this->db->get_results(" |
|
| 85 | + return $this->db->get_results( " |
|
| 86 | 86 | SELECT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
| 87 | 87 | FROM {$this->db->posts} AS p |
| 88 | 88 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function getReviewPostId( $metaReviewId ) |
| 105 | 105 | { |
| 106 | - $postId = $this->db->get_var(" |
|
| 106 | + $postId = $this->db->get_var( " |
|
| 107 | 107 | SELECT p.ID |
| 108 | 108 | FROM {$this->db->posts} AS p |
| 109 | 109 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
| 110 | 110 | WHERE p.post_type = '{$this->postType}' |
| 111 | 111 | AND m.meta_key = 'review_id' |
| 112 | 112 | AND m.meta_value = '{$metaReviewId}' |
| 113 | - "); |
|
| 113 | + " ); |
|
| 114 | 114 | return intval( $postId ); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | */ |
| 121 | 121 | public function getReviewIdsByType( $reviewType ) |
| 122 | 122 | { |
| 123 | - $query = $this->db->get_col(" |
|
| 123 | + $query = $this->db->get_col( " |
|
| 124 | 124 | SELECT m1.meta_value AS review_id |
| 125 | 125 | FROM {$this->db->posts} AS p |
| 126 | 126 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | AND m1.meta_key = 'review_id' |
| 130 | 130 | AND m2.meta_key = 'review_type' |
| 131 | 131 | AND m2.meta_value = '{$reviewType}' |
| 132 | - "); |
|
| 133 | - return array_keys( array_flip( $query )); |
|
| 132 | + " ); |
|
| 133 | + return array_keys( array_flip( $query ) ); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public function getReviewPostCounts( $postId, $lastPostId = 0, $limit = 500 ) |
| 143 | 143 | { |
| 144 | - return $this->db->get_results(" |
|
| 144 | + return $this->db->get_results( " |
|
| 145 | 145 | SELECT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
| 146 | 146 | FROM {$this->db->posts} AS p |
| 147 | 147 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 ) |
| 168 | 168 | { |
| 169 | 169 | sort( $postIds ); |
| 170 | - $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds )), $limit ); |
|
| 170 | + $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit ); |
|
| 171 | 171 | $postIds = implode( ',', $postIds ); |
| 172 | - return $this->db->get_results(" |
|
| 172 | + return $this->db->get_results( " |
|
| 173 | 173 | SELECT p.ID, m.meta_value AS rating |
| 174 | 174 | FROM {$this->db->posts} AS p |
| 175 | 175 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | $queryBuilder = glsr( QueryBuilder::class ); |
| 194 | 194 | $key = $queryBuilder->buildSqlOr( $key, "m.meta_key = '%s'" ); |
| 195 | 195 | $status = $queryBuilder->buildSqlOr( $status, "p.post_status = '%s'" ); |
| 196 | - return $this->db->get_col(" |
|
| 196 | + return $this->db->get_col( " |
|
| 197 | 197 | SELECT DISTINCT m.meta_value |
| 198 | 198 | FROM {$this->db->postmeta} m |
| 199 | 199 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | AND ({$key}) |
| 202 | 202 | AND ({$status}) |
| 203 | 203 | ORDER BY m.meta_value |
| 204 | - "); |
|
| 204 | + " ); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | public function getReviewTermCounts( $termId, $lastPostId = 0, $limit = 500 ) |
| 214 | 214 | { |
| 215 | - return $this->db->get_results(" |
|
| 215 | + return $this->db->get_results( " |
|
| 216 | 216 | SELECT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
| 217 | 217 | FROM {$this->db->posts} AS p |
| 218 | 218 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -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,15 +96,15 @@ 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, ['max' => Rating::MAX_RATING, 'min' => Rating::MIN_RATING] ); |
| 105 | - array_walk( $counts, function( &$ratings ) use( $args ) { |
|
| 105 | + array_walk( $counts, function( &$ratings ) use($args) { |
|
| 106 | 106 | foreach( $ratings as $index => &$num ) { |
| 107 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 107 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ) )continue; |
|
| 108 | 108 | $num = 0; |
| 109 | 109 | } |
| 110 | 110 | }); |
@@ -152,14 +152,14 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function increaseCounts( Review $review ) |
| 154 | 154 | { |
| 155 | - if( empty( $counts = $this->getCounts() )) { |
|
| 155 | + if( empty($counts = $this->getCounts()) ) { |
|
| 156 | 156 | $counts = $this->buildCounts(); |
| 157 | 157 | } |
| 158 | 158 | $this->setCounts( $this->increaseRating( |
| 159 | 159 | $counts, |
| 160 | 160 | $review->review_type, |
| 161 | 161 | $review->rating |
| 162 | - )); |
|
| 162 | + ) ); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | public function increasePostCounts( Review $review ) |
| 169 | 169 | { |
| 170 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 171 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) { |
|
| 170 | + if( !(get_post( $review->assigned_to ) instanceof WP_Post) )return; |
|
| 171 | + if( empty($counts = $this->getPostCounts( $review->assigned_to )) ) { |
|
| 172 | 172 | $counts = $this->buildPostCounts( $review->assigned_to ); |
| 173 | 173 | } |
| 174 | 174 | $counts = $this->increaseRating( $counts, $review->review_type, $review->rating ); |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | public function increaseTermCounts( Review $review ) |
| 182 | 182 | { |
| 183 | 183 | foreach( $review->term_ids as $termId ) { |
| 184 | - if( !( get_term( $termId, Application::TAXONOMY ) instanceof WP_Term ))continue; |
|
| 185 | - if( empty( $counts = $this->getTermCounts( $termId ))) { |
|
| 184 | + if( !(get_term( $termId, Application::TAXONOMY ) instanceof WP_Term) )continue; |
|
| 185 | + if( empty($counts = $this->getTermCounts( $termId )) ) { |
|
| 186 | 186 | $counts = $this->buildTermCounts( $termId ); |
| 187 | 187 | } |
| 188 | 188 | $counts = $this->increaseRating( $counts, $review->review_type, $review->rating ); |
@@ -206,8 +206,8 @@ discard block |
||
| 206 | 206 | { |
| 207 | 207 | $ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts ); |
| 208 | 208 | update_post_meta( $postId, static::META_COUNT, $reviewCounts ); |
| 209 | - update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 210 | - update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 209 | + update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 210 | + update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -216,11 +216,11 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public function setTermCounts( $termId, array $reviewCounts ) |
| 218 | 218 | { |
| 219 | - if( !term_exists( $termId ))return; |
|
| 219 | + if( !term_exists( $termId ) )return; |
|
| 220 | 220 | $ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts ); |
| 221 | 221 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 222 | - update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 223 | - update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 222 | + update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 223 | + update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -231,10 +231,10 @@ discard block |
||
| 231 | 231 | { |
| 232 | 232 | $counts = []; |
| 233 | 233 | $lastPostId = 0; |
| 234 | - while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) { |
|
| 235 | - $types = array_keys( array_flip( array_column( $reviews, 'type' ))); |
|
| 234 | + while( $reviews = $this->queryReviews( $args, $lastPostId, $limit ) ) { |
|
| 235 | + $types = array_keys( array_flip( array_column( $reviews, 'type' ) ) ); |
|
| 236 | 236 | foreach( $types as $type ) { |
| 237 | - if( isset( $counts[$type] ))continue; |
|
| 237 | + if( isset($counts[$type]) )continue; |
|
| 238 | 238 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 239 | 239 | } |
| 240 | 240 | foreach( $reviews as $review ) { |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | protected function decreaseRating( array $reviewCounts, $type, $rating ) |
| 254 | 254 | { |
| 255 | - if( isset( $reviewCounts[$type][$rating] )) { |
|
| 255 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
| 256 | 256 | $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
| 257 | 257 | } |
| 258 | 258 | return $reviewCounts; |
@@ -265,10 +265,10 @@ discard block |
||
| 265 | 265 | */ |
| 266 | 266 | protected function increaseRating( array $reviewCounts, $type, $rating ) |
| 267 | 267 | { |
| 268 | - if( !array_key_exists( $type, glsr()->reviewTypes )) { |
|
| 268 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
| 269 | 269 | return $reviewCounts; |
| 270 | 270 | } |
| 271 | - if( !array_key_exists( $type, $reviewCounts )) { |
|
| 271 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
| 272 | 272 | $reviewCounts[$type] = []; |
| 273 | 273 | } |
| 274 | 274 | $reviewCounts = $this->normalize( $reviewCounts ); |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | { |
| 284 | 284 | foreach( $reviewCounts as &$counts ) { |
| 285 | 285 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 286 | - if( isset( $counts[$index] ))continue; |
|
| 286 | + if( isset($counts[$index]) )continue; |
|
| 287 | 287 | $counts[$index] = 0; |
| 288 | 288 | } |
| 289 | 289 | ksort( $counts ); |
@@ -298,14 +298,14 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | protected function queryReviews( array $args = [], $lastPostId, $limit ) |
| 300 | 300 | { |
| 301 | - $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' )); |
|
| 302 | - if( empty( array_filter( $args ))) { |
|
| 301 | + $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' ) ); |
|
| 302 | + if( empty(array_filter( $args )) ) { |
|
| 303 | 303 | return glsr( SqlQueries::class )->getReviewCounts( $lastPostId, $limit ); |
| 304 | 304 | } |
| 305 | - if( !empty( $args['post_id'] )) { |
|
| 305 | + if( !empty($args['post_id']) ) { |
|
| 306 | 306 | return glsr( SqlQueries::class )->getReviewPostCounts( $args['post_id'], $lastPostId, $limit ); |
| 307 | 307 | } |
| 308 | - if( !empty( $args['term_id'] )) { |
|
| 308 | + if( !empty($args['term_id']) ) { |
|
| 309 | 309 | return glsr( SqlQueries::class )->getReviewTermCounts( $args['term_id'], $lastPostId, $limit ); |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -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 | } |
@@ -104,7 +108,9 @@ discard block |
||
| 104 | 108 | $args = wp_parse_args( $args, ['max' => Rating::MAX_RATING, 'min' => Rating::MIN_RATING] ); |
| 105 | 109 | array_walk( $counts, function( &$ratings ) use( $args ) { |
| 106 | 110 | foreach( $ratings as $index => &$num ) { |
| 107 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 111 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] )) { |
|
| 112 | + continue; |
|
| 113 | + } |
|
| 108 | 114 | $num = 0; |
| 109 | 115 | } |
| 110 | 116 | }); |
@@ -167,7 +173,9 @@ discard block |
||
| 167 | 173 | */ |
| 168 | 174 | public function increasePostCounts( Review $review ) |
| 169 | 175 | { |
| 170 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 176 | + if( !( get_post( $review->assigned_to ) instanceof WP_Post )) { |
|
| 177 | + return; |
|
| 178 | + } |
|
| 171 | 179 | if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) { |
| 172 | 180 | $counts = $this->buildPostCounts( $review->assigned_to ); |
| 173 | 181 | } |
@@ -181,7 +189,9 @@ discard block |
||
| 181 | 189 | public function increaseTermCounts( Review $review ) |
| 182 | 190 | { |
| 183 | 191 | foreach( $review->term_ids as $termId ) { |
| 184 | - if( !( get_term( $termId, Application::TAXONOMY ) instanceof WP_Term ))continue; |
|
| 192 | + if( !( get_term( $termId, Application::TAXONOMY ) instanceof WP_Term )) { |
|
| 193 | + continue; |
|
| 194 | + } |
|
| 185 | 195 | if( empty( $counts = $this->getTermCounts( $termId ))) { |
| 186 | 196 | $counts = $this->buildTermCounts( $termId ); |
| 187 | 197 | } |
@@ -216,7 +226,9 @@ discard block |
||
| 216 | 226 | */ |
| 217 | 227 | public function setTermCounts( $termId, array $reviewCounts ) |
| 218 | 228 | { |
| 219 | - if( !term_exists( $termId ))return; |
|
| 229 | + if( !term_exists( $termId )) { |
|
| 230 | + return; |
|
| 231 | + } |
|
| 220 | 232 | $ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts ); |
| 221 | 233 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 222 | 234 | update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
@@ -234,7 +246,9 @@ discard block |
||
| 234 | 246 | while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) { |
| 235 | 247 | $types = array_keys( array_flip( array_column( $reviews, 'type' ))); |
| 236 | 248 | foreach( $types as $type ) { |
| 237 | - if( isset( $counts[$type] ))continue; |
|
| 249 | + if( isset( $counts[$type] )) { |
|
| 250 | + continue; |
|
| 251 | + } |
|
| 238 | 252 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 239 | 253 | } |
| 240 | 254 | foreach( $reviews as $review ) { |
@@ -283,7 +297,9 @@ discard block |
||
| 283 | 297 | { |
| 284 | 298 | foreach( $reviewCounts as &$counts ) { |
| 285 | 299 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 286 | - if( isset( $counts[$index] ))continue; |
|
| 300 | + if( isset( $counts[$index] )) { |
|
| 301 | + continue; |
|
| 302 | + } |
|
| 287 | 303 | $counts[$index] = 0; |
| 288 | 304 | } |
| 289 | 305 | ksort( $counts ); |
@@ -13,10 +13,10 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | public function saveAssignedToMetabox( $postId ) |
| 15 | 15 | { |
| 16 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ))return; |
|
| 17 | - $assignedTo = strval( glsr( Helper::class )->filterInput( 'assigned_to' )); |
|
| 16 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ) )return; |
|
| 17 | + $assignedTo = strval( glsr( Helper::class )->filterInput( 'assigned_to' ) ); |
|
| 18 | 18 | if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) { |
| 19 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 19 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 20 | 20 | glsr( CountsManager::class )->decreasePostCounts( $review ); |
| 21 | 21 | } |
| 22 | 22 | update_post_meta( $postId, 'assigned_to', $assignedTo ); |
@@ -28,12 +28,12 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function saveResponseMetabox( $postId ) |
| 30 | 30 | { |
| 31 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ))return; |
|
| 32 | - $response = strval( glsr( Helper::class )->filterInput( 'response' )); |
|
| 31 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ) )return; |
|
| 32 | + $response = strval( glsr( Helper::class )->filterInput( 'response' ) ); |
|
| 33 | 33 | update_post_meta( $postId, 'response', trim( wp_kses( $response, [ |
| 34 | 34 | 'a' => ['href' => [], 'title' => []], |
| 35 | 35 | 'em' => [], |
| 36 | 36 | 'strong' => [], |
| 37 | - ]))); |
|
| 37 | + ] ) ) ); |
|
| 38 | 38 | } |
| 39 | 39 | } |
@@ -13,7 +13,9 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | public function saveAssignedToMetabox( $postId ) |
| 15 | 15 | { |
| 16 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ))return; |
|
| 16 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' )) { |
|
| 17 | + return; |
|
| 18 | + } |
|
| 17 | 19 | $assignedTo = strval( glsr( Helper::class )->filterInput( 'assigned_to' )); |
| 18 | 20 | if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) { |
| 19 | 21 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
@@ -28,7 +30,9 @@ discard block |
||
| 28 | 30 | */ |
| 29 | 31 | public function saveResponseMetabox( $postId ) |
| 30 | 32 | { |
| 31 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ))return; |
|
| 33 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' )) { |
|
| 34 | + return; |
|
| 35 | + } |
|
| 32 | 36 | $response = strval( glsr( Helper::class )->filterInput( 'response' )); |
| 33 | 37 | update_post_meta( $postId, 'response', trim( wp_kses( $response, [ |
| 34 | 38 | 'a' => ['href' => [], 'title' => []], |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function enqueueAssets() |
| 27 | 27 | { |
| 28 | - $command = new EnqueueAdminAssets([ |
|
| 28 | + $command = new EnqueueAdminAssets( [ |
|
| 29 | 29 | 'pointers' => [[ |
| 30 | 30 | 'content' => __( 'You can pin exceptional reviews so that they are always shown first.', 'site-reviews' ), |
| 31 | 31 | 'id' => 'glsr-pointer-pinned', |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | 'target' => '#misc-pub-pinned', |
| 38 | 38 | 'title' => __( 'Pin Your Reviews', 'site-reviews' ), |
| 39 | 39 | ]], |
| 40 | - ]); |
|
| 40 | + ] ); |
|
| 41 | 41 | $this->execute( $command ); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | $links['settings'] = glsr( Builder::class )->a( __( 'Settings', 'site-reviews' ), [ |
| 51 | 51 | 'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=settings' ), |
| 52 | - ]); |
|
| 52 | + ] ); |
|
| 53 | 53 | return $links; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -60,19 +60,19 @@ discard block |
||
| 60 | 60 | public function filterDashboardGlanceItems( array $items ) |
| 61 | 61 | { |
| 62 | 62 | $postCount = wp_count_posts( Application::POST_TYPE ); |
| 63 | - if( empty( $postCount->publish )) { |
|
| 63 | + if( empty($postCount->publish) ) { |
|
| 64 | 64 | return $items; |
| 65 | 65 | } |
| 66 | 66 | $text = _n( '%s Review', '%s Reviews', $postCount->publish, 'site-reviews' ); |
| 67 | - $text = sprintf( $text, number_format_i18n( $postCount->publish )); |
|
| 67 | + $text = sprintf( $text, number_format_i18n( $postCount->publish ) ); |
|
| 68 | 68 | $items[] = current_user_can( get_post_type_object( Application::POST_TYPE )->cap->edit_posts ) |
| 69 | 69 | ? glsr( Builder::class )->a( $text, [ |
| 70 | 70 | 'class' => 'glsr-review-count', |
| 71 | 71 | 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
| 72 | - ]) |
|
| 72 | + ] ) |
|
| 73 | 73 | : glsr( Builder::class )->span( $text, [ |
| 74 | 74 | 'class' => 'glsr-review-count', |
| 75 | - ]); |
|
| 75 | + ] ); |
|
| 76 | 76 | return $items; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | public function filterTinymcePlugins( array $plugins ) |
| 84 | 84 | { |
| 85 | 85 | if( user_can_richedit() |
| 86 | - && ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ))) { |
|
| 86 | + && (current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' )) ) { |
|
| 87 | 87 | $plugins['glsr_shortcode'] = glsr()->url( 'assets/scripts/mce-plugin.js' ); |
| 88 | 88 | } |
| 89 | 89 | return $plugins; |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function registerShortcodeButtons() |
| 97 | 97 | { |
| 98 | - $command = new RegisterShortcodeButtons([ |
|
| 98 | + $command = new RegisterShortcodeButtons( [ |
|
| 99 | 99 | 'site_reviews' => esc_html__( 'Recent Reviews', 'site-reviews' ), |
| 100 | 100 | 'site_reviews_form' => esc_html__( 'Submit a Review', 'site-reviews' ), |
| 101 | 101 | 'site_reviews_summary' => esc_html__( 'Summary of Reviews', 'site-reviews' ), |
| 102 | - ]); |
|
| 102 | + ] ); |
|
| 103 | 103 | $this->execute( $command ); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -109,10 +109,10 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function renderReviewEditor( WP_Post $post ) |
| 111 | 111 | { |
| 112 | - if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ))return; |
|
| 112 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) )return; |
|
| 113 | 113 | glsr()->render( 'partials/editor/review', [ |
| 114 | 114 | 'post' => $post, |
| 115 | - ]); |
|
| 115 | + ] ); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function renderReviewNotice( WP_Post $post ) |
| 123 | 123 | { |
| 124 | - if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ))return; |
|
| 125 | - glsr( Notice::class )->addWarning( __( 'This review is read-only.', 'site-reviews' )); |
|
| 124 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) )return; |
|
| 125 | + glsr( Notice::class )->addWarning( __( 'This review is read-only.', 'site-reviews' ) ); |
|
| 126 | 126 | glsr( Html::class )->renderTemplate( 'partials/editor/notice', [ |
| 127 | 127 | 'context' => [ |
| 128 | 128 | 'notices' => glsr( Notice::class )->get(), |
| 129 | 129 | ], |
| 130 | - ]); |
|
| 130 | + ] ); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -139,13 +139,13 @@ discard block |
||
| 139 | 139 | if( glsr_current_screen()->base != 'post' )return; |
| 140 | 140 | $shortcodes = []; |
| 141 | 141 | foreach( glsr()->mceShortcodes as $shortcode => $values ) { |
| 142 | - if( !apply_filters( sanitize_title( $shortcode ).'_condition', true ))continue; |
|
| 142 | + if( !apply_filters( sanitize_title( $shortcode ).'_condition', true ) )continue; |
|
| 143 | 143 | $shortcodes[$shortcode] = $values; |
| 144 | 144 | } |
| 145 | - if( empty( $shortcodes ))return; |
|
| 145 | + if( empty($shortcodes) )return; |
|
| 146 | 146 | glsr()->render( 'partials/editor/tinymce', [ |
| 147 | 147 | 'shortcodes' => $shortcodes, |
| 148 | - ]); |
|
| 148 | + ] ); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | public function routerClearConsole() |
| 155 | 155 | { |
| 156 | 156 | glsr( Console::class )->clear(); |
| 157 | - glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' )); |
|
| 157 | + glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' ) ); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -163,19 +163,19 @@ discard block |
||
| 163 | 163 | public function routerCountReviews() |
| 164 | 164 | { |
| 165 | 165 | $countManager = glsr( CountsManager::class ); |
| 166 | - $terms = get_terms([ |
|
| 166 | + $terms = get_terms( [ |
|
| 167 | 167 | 'hide_empty' => true, |
| 168 | 168 | 'taxonomy' => Application::TAXONOMY, |
| 169 | - ]); |
|
| 169 | + ] ); |
|
| 170 | 170 | foreach( $terms as $term ) { |
| 171 | - $countManager->setTermCounts( $term->term_id, $countManager->buildTermCounts( $term->term_id )); |
|
| 171 | + $countManager->setTermCounts( $term->term_id, $countManager->buildTermCounts( $term->term_id ) ); |
|
| 172 | 172 | } |
| 173 | 173 | $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' ); |
| 174 | 174 | foreach( $postIds as $postId ) { |
| 175 | - $countManager->setPostCounts( $postId, $countManager->buildPostCounts( $postId )); |
|
| 175 | + $countManager->setPostCounts( $postId, $countManager->buildPostCounts( $postId ) ); |
|
| 176 | 176 | } |
| 177 | 177 | $countManager->setCounts( $countManager->buildCounts() ); |
| 178 | - glsr( Notice::class )->addSuccess( __( 'Recalculated review counts.', 'site-reviews' )); |
|
| 178 | + glsr( Notice::class )->addSuccess( __( 'Recalculated review counts.', 'site-reviews' ) ); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -209,17 +209,17 @@ discard block |
||
| 209 | 209 | { |
| 210 | 210 | $file = $_FILES['import-file']; |
| 211 | 211 | if( $file['error'] !== UPLOAD_ERR_OK ) { |
| 212 | - return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] )); |
|
| 212 | + return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] ) ); |
|
| 213 | 213 | } |
| 214 | - if( $file['type'] !== 'application/json' || !glsr( Helper::class )->endsWith( '.json', $file['name'] )) { |
|
| 215 | - return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' )); |
|
| 214 | + if( $file['type'] !== 'application/json' || !glsr( Helper::class )->endsWith( '.json', $file['name'] ) ) { |
|
| 215 | + return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' ) ); |
|
| 216 | 216 | } |
| 217 | 217 | $settings = json_decode( file_get_contents( $file['tmp_name'] ), true ); |
| 218 | - if( empty( $settings )) { |
|
| 219 | - return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' )); |
|
| 218 | + if( empty($settings) ) { |
|
| 219 | + return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' ) ); |
|
| 220 | 220 | } |
| 221 | - glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings )); |
|
| 222 | - glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' )); |
|
| 221 | + glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings ) ); |
|
| 222 | + glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' ) ); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | /** |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | UPLOAD_ERR_CANT_WRITE => __( 'Failed to write file to disk.', 'site-reviews' ), |
| 238 | 238 | UPLOAD_ERR_EXTENSION => __( 'A PHP extension stopped the file upload.', 'site-reviews' ), |
| 239 | 239 | ]; |
| 240 | - return !isset( $errors[$errorCode] ) |
|
| 240 | + return !isset($errors[$errorCode]) |
|
| 241 | 241 | ? __( 'Unknown upload error.', 'site-reviews' ) |
| 242 | 242 | : $errors[$errorCode]; |
| 243 | 243 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public function download( $filename, $content ) |
| 17 | 17 | { |
| 18 | - if( !current_user_can( Application::CAPABILITY ))return; |
|
| 18 | + if( !current_user_can( Application::CAPABILITY ) )return; |
|
| 19 | 19 | nocache_headers(); |
| 20 | 20 | header( 'Content-Type: text/plain' ); |
| 21 | 21 | header( 'Content-Disposition: attachment; filename="'.$filename.'"' ); |
@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function execute( $command ) |
| 32 | 32 | { |
| 33 | - $handlerClass = str_replace( 'Commands', 'Handlers', get_class( $command )); |
|
| 34 | - if( !class_exists( $handlerClass )) { |
|
| 33 | + $handlerClass = str_replace( 'Commands', 'Handlers', get_class( $command ) ); |
|
| 34 | + if( !class_exists( $handlerClass ) ) { |
|
| 35 | 35 | throw new InvalidArgumentException( 'Handler '.$handlerClass.' not found.' ); |
| 36 | 36 | } |
| 37 | 37 | try { |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | catch( Exception $e ) { |
| 41 | 41 | status_header( 400 ); |
| 42 | - glsr( Notice::class )->addError( new WP_Error( 'site_reviews_error', $e->getMessage() )); |
|
| 42 | + glsr( Notice::class )->addError( new WP_Error( 'site_reviews_error', $e->getMessage() ) ); |
|
| 43 | 43 | glsr_log()->error( $e->getMessage() ); |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | protected function getPostId() |
| 51 | 51 | { |
| 52 | - return intval( filter_input( INPUT_GET, 'post' )); |
|
| 52 | + return intval( filter_input( INPUT_GET, 'post' ) ); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function onAfterChangeCategory( $postId, $terms, $termIds, $taxonomySlug, $append, $oldTermIds ) |
| 25 | 25 | { |
| 26 | - if( !$this->isReviewPostId( $postId ))return; |
|
| 27 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 26 | + if( !$this->isReviewPostId( $postId ) )return; |
|
| 27 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 28 | 28 | $ignoredTerms = array_intersect( $oldTermIds, $termIds ); |
| 29 | 29 | $review->term_ids = array_diff( $oldTermIds, $ignoredTerms ); |
| 30 | 30 | glsr( CountsManager::class )->decreaseTermCounts( $review ); |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function onAfterCreate( $postData, $meta, $postId ) |
| 43 | 43 | { |
| 44 | - if( !$this->isReviewPostId( $postId ))return; |
|
| 45 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 44 | + if( !$this->isReviewPostId( $postId ) )return; |
|
| 45 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 46 | 46 | glsr( CountsManager::class )->increase( $review ); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function onBeforeDelete( $postId ) |
| 55 | 55 | { |
| 56 | - if( !$this->isReviewPostId( $postId ))return; |
|
| 57 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 56 | + if( !$this->isReviewPostId( $postId ) )return; |
|
| 57 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 58 | 58 | glsr( CountsManager::class )->decrease( $review ); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | if( !$this->isReviewPostId( $postId ) |
| 72 | 72 | || !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] ) |
| 73 | 73 | )return; |
| 74 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 74 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 75 | 75 | if( $review->$metaKey == $metaValue )return; |
| 76 | 76 | $method = glsr( Helper::class )->buildMethodName( $metaKey, 'onBeforeChange' ); |
| 77 | 77 | call_user_func( [$this, $method], $review, $metaValue ); |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | public function onChangeStatus( $newStatus, $oldStatus, WP_Post $post ) |
| 120 | 120 | { |
| 121 | - if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ))return; |
|
| 122 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 121 | + if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ) )return; |
|
| 122 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 123 | 123 | if( $status == 'publish' ) { |
| 124 | 124 | glsr( CountsManager::class )->increase( $review ); |
| 125 | 125 | } |
@@ -23,7 +23,9 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function onAfterChangeCategory( $postId, $terms, $termIds, $taxonomySlug, $append, $oldTermIds ) |
| 25 | 25 | { |
| 26 | - if( !$this->isReviewPostId( $postId ))return; |
|
| 26 | + if( !$this->isReviewPostId( $postId )) { |
|
| 27 | + return; |
|
| 28 | + } |
|
| 27 | 29 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
| 28 | 30 | $ignoredTerms = array_intersect( $oldTermIds, $termIds ); |
| 29 | 31 | $review->term_ids = array_diff( $oldTermIds, $ignoredTerms ); |
@@ -41,7 +43,9 @@ discard block |
||
| 41 | 43 | */ |
| 42 | 44 | public function onAfterCreate( $postData, $meta, $postId ) |
| 43 | 45 | { |
| 44 | - if( !$this->isReviewPostId( $postId ))return; |
|
| 46 | + if( !$this->isReviewPostId( $postId )) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 45 | 49 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
| 46 | 50 | glsr( CountsManager::class )->increase( $review ); |
| 47 | 51 | } |
@@ -53,7 +57,9 @@ discard block |
||
| 53 | 57 | */ |
| 54 | 58 | public function onBeforeDelete( $postId ) |
| 55 | 59 | { |
| 56 | - if( !$this->isReviewPostId( $postId ))return; |
|
| 60 | + if( !$this->isReviewPostId( $postId )) { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 57 | 63 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
| 58 | 64 | glsr( CountsManager::class )->decrease( $review ); |
| 59 | 65 | } |
@@ -70,9 +76,13 @@ discard block |
||
| 70 | 76 | { |
| 71 | 77 | if( !$this->isReviewPostId( $postId ) |
| 72 | 78 | || !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] ) |
| 73 | - )return; |
|
| 79 | + ) { |
|
| 80 | + return; |
|
| 81 | + } |
|
| 74 | 82 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
| 75 | - if( $review->$metaKey == $metaValue )return; |
|
| 83 | + if( $review->$metaKey == $metaValue ) { |
|
| 84 | + return; |
|
| 85 | + } |
|
| 76 | 86 | $method = glsr( Helper::class )->buildMethodName( $metaKey, 'onBeforeChange' ); |
| 77 | 87 | call_user_func( [$this, $method], $review, $metaValue ); |
| 78 | 88 | } |
@@ -118,7 +128,9 @@ discard block |
||
| 118 | 128 | */ |
| 119 | 129 | public function onChangeStatus( $newStatus, $oldStatus, WP_Post $post ) |
| 120 | 130 | { |
| 121 | - if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ))return; |
|
| 131 | + if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] )) { |
|
| 132 | + return; |
|
| 133 | + } |
|
| 122 | 134 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
| 123 | 135 | if( $status == 'publish' ) { |
| 124 | 136 | glsr( CountsManager::class )->increase( $review ); |