@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function renderTaxonomyFilter() |
| 37 | 37 | { |
| 38 | - if( !is_object_in_taxonomy( glsr_current_screen()->post_type, Application::TAXONOMY ))return; |
|
| 38 | + if( !is_object_in_taxonomy( glsr_current_screen()->post_type, Application::TAXONOMY ) )return; |
|
| 39 | 39 | echo glsr( Builder::class )->label( __( 'Filter by category', 'site-reviews' ), [ |
| 40 | 40 | 'class' => 'screen-reader-text', |
| 41 | 41 | 'for' => Application::TAXONOMY, |
| 42 | - ]); |
|
| 43 | - wp_dropdown_categories([ |
|
| 42 | + ] ); |
|
| 43 | + wp_dropdown_categories( [ |
|
| 44 | 44 | 'depth' => 3, |
| 45 | 45 | 'hide_empty' => true, |
| 46 | 46 | 'hide_if_empty' => true, |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | 'show_option_all' => $this->getShowOptionAll(), |
| 53 | 53 | 'taxonomy' => Application::TAXONOMY, |
| 54 | 54 | 'value_field' => 'slug', |
| 55 | - ]); |
|
| 55 | + ] ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | protected function getSelected() |
| 62 | 62 | { |
| 63 | 63 | global $wp_query; |
| 64 | - return isset( $wp_query->query[Application::TAXONOMY] ) |
|
| 64 | + return isset($wp_query->query[Application::TAXONOMY]) |
|
| 65 | 65 | ? $wp_query->query[Application::TAXONOMY] |
| 66 | 66 | : ''; |
| 67 | 67 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $taxonomy = get_taxonomy( Application::TAXONOMY ); |
| 75 | 75 | return $taxonomy |
| 76 | - ? ucfirst( strtolower( $taxonomy->labels->all_items )) |
|
| 76 | + ? ucfirst( strtolower( $taxonomy->labels->all_items ) ) |
|
| 77 | 77 | : ''; |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -35,7 +35,9 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | public function renderTaxonomyFilter() |
| 37 | 37 | { |
| 38 | - if( !is_object_in_taxonomy( glsr_current_screen()->post_type, Application::TAXONOMY ))return; |
|
| 38 | + if( !is_object_in_taxonomy( glsr_current_screen()->post_type, Application::TAXONOMY )) { |
|
| 39 | + return; |
|
| 40 | + } |
|
| 39 | 41 | echo glsr( Builder::class )->label( __( 'Filter by category', 'site-reviews' ), [ |
| 40 | 42 | 'class' => 'screen-reader-text', |
| 41 | 43 | 'for' => Application::TAXONOMY, |
@@ -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() ); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $this->getCounts(), |
| 67 | 67 | $review->review_type, |
| 68 | 68 | $review->rating |
| 69 | - )); |
|
| 69 | + ) ); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function decreasePostCounts( Review $review ) |
| 76 | 76 | { |
| 77 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
| 77 | + if( empty($counts = $this->getPostCounts( $review->assigned_to )) )return; |
|
| 78 | 78 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 79 | 79 | $this->setPostCounts( $review->assigned_to, $counts ); |
| 80 | 80 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | public function decreaseTermCounts( Review $review ) |
| 86 | 86 | { |
| 87 | 87 | foreach( $review->term_ids as $termId ) { |
| 88 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
| 88 | + if( empty($counts = $this->getTermCounts( $termId )) )continue; |
|
| 89 | 89 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 90 | 90 | $this->setTermCounts( $termId, $counts ); |
| 91 | 91 | } |
@@ -97,17 +97,17 @@ discard block |
||
| 97 | 97 | public function flatten( array $reviewCounts, array $args = [] ) |
| 98 | 98 | { |
| 99 | 99 | $counts = []; |
| 100 | - array_walk_recursive( $reviewCounts, function( $num, $index ) use( &$counts ) { |
|
| 101 | - $counts[$index] = isset( $counts[$index] ) |
|
| 100 | + array_walk_recursive( $reviewCounts, function( $num, $index ) use(&$counts) { |
|
| 101 | + $counts[$index] = isset($counts[$index]) |
|
| 102 | 102 | ? $num + $counts[$index] |
| 103 | 103 | : $num; |
| 104 | 104 | }); |
| 105 | 105 | $args = wp_parse_args( $args, [ |
| 106 | 106 | 'max' => Rating::MAX_RATING, |
| 107 | 107 | 'min' => Rating::MIN_RATING, |
| 108 | - ]); |
|
| 108 | + ] ); |
|
| 109 | 109 | foreach( $counts as $index => &$num ) { |
| 110 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 110 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ) )continue; |
|
| 111 | 111 | $num = 0; |
| 112 | 112 | } |
| 113 | 113 | return $counts; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | 'post_ids' => [], |
| 123 | 123 | 'term_ids' => [], |
| 124 | 124 | 'type' => 'local', |
| 125 | - ]); |
|
| 125 | + ] ); |
|
| 126 | 126 | $counts = []; |
| 127 | 127 | foreach( glsr( Polylang::class )->getPostIds( $args['post_ids'] ) as $postId ) { |
| 128 | 128 | $counts[] = $this->getPostCounts( $postId ); |
@@ -130,12 +130,12 @@ discard block |
||
| 130 | 130 | foreach( $args['term_ids'] as $termId ) { |
| 131 | 131 | $counts[] = $this->getTermCounts( $termId ); |
| 132 | 132 | } |
| 133 | - if( empty( $counts )) { |
|
| 133 | + if( empty($counts) ) { |
|
| 134 | 134 | $counts[] = $this->getCounts(); |
| 135 | 135 | } |
| 136 | 136 | return in_array( $args['type'], ['', 'all'] ) |
| 137 | 137 | ? $this->normalize( [$this->flatten( $counts )] ) |
| 138 | - : $this->normalize( array_column( $counts, $args['type'] )); |
|
| 138 | + : $this->normalize( array_column( $counts, $args['type'] ) ); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | public function getCounts() |
| 145 | 145 | { |
| 146 | 146 | $counts = glsr( OptionManager::class )->get( 'counts', [] ); |
| 147 | - if( !is_array( $counts )) { |
|
| 147 | + if( !is_array( $counts ) ) { |
|
| 148 | 148 | glsr_log()->error( 'CountsManager: counts is not an array' )->debug( $counts ); |
| 149 | 149 | return []; |
| 150 | 150 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | public function getPostCounts( $postId ) |
| 159 | 159 | { |
| 160 | - return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true )); |
|
| 160 | + return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true ) ); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public function getTermCounts( $termId ) |
| 168 | 168 | { |
| 169 | - return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true )); |
|
| 169 | + return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true ) ); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -184,14 +184,14 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public function increaseCounts( Review $review ) |
| 186 | 186 | { |
| 187 | - if( empty( $counts = $this->getCounts() )) { |
|
| 187 | + if( empty($counts = $this->getCounts()) ) { |
|
| 188 | 188 | $counts = $this->buildCounts(); |
| 189 | 189 | } |
| 190 | 190 | $this->setCounts( $this->increaseRating( |
| 191 | 191 | $counts, |
| 192 | 192 | $review->review_type, |
| 193 | 193 | $review->rating |
| 194 | - )); |
|
| 194 | + ) ); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | public function increasePostCounts( Review $review ) |
| 201 | 201 | { |
| 202 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 202 | + if( !(get_post( $review->assigned_to ) instanceof WP_Post) )return; |
|
| 203 | 203 | $counts = $this->getPostCounts( $review->assigned_to ); |
| 204 | - $counts = empty( $counts ) |
|
| 204 | + $counts = empty($counts) |
|
| 205 | 205 | ? $this->buildPostCounts( $review->assigned_to ) |
| 206 | 206 | : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
| 207 | 207 | $this->setPostCounts( $review->assigned_to, $counts ); |
@@ -212,10 +212,10 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | public function increaseTermCounts( Review $review ) |
| 214 | 214 | { |
| 215 | - $termIds = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids )); |
|
| 215 | + $termIds = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) ); |
|
| 216 | 216 | foreach( $termIds as $termId ) { |
| 217 | 217 | $counts = $this->getTermCounts( $termId ); |
| 218 | - $counts = empty( $counts ) |
|
| 218 | + $counts = empty($counts) |
|
| 219 | 219 | ? $this->buildTermCounts( $termId ) |
| 220 | 220 | : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
| 221 | 221 | $this->setTermCounts( $termId, $counts ); |
@@ -238,8 +238,8 @@ discard block |
||
| 238 | 238 | { |
| 239 | 239 | $ratingCounts = $this->flatten( $reviewCounts ); |
| 240 | 240 | update_post_meta( $postId, static::META_COUNT, $reviewCounts ); |
| 241 | - update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 242 | - update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 241 | + update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 242 | + update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -248,11 +248,11 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | public function setTermCounts( $termId, array $reviewCounts ) |
| 250 | 250 | { |
| 251 | - if( !term_exists( $termId ))return; |
|
| 251 | + if( !term_exists( $termId ) )return; |
|
| 252 | 252 | $ratingCounts = $this->flatten( $reviewCounts ); |
| 253 | 253 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 254 | - update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 255 | - update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 254 | + update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 255 | + update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -263,12 +263,12 @@ discard block |
||
| 263 | 263 | { |
| 264 | 264 | $counts = []; |
| 265 | 265 | $lastPostId = 0; |
| 266 | - while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) { |
|
| 267 | - $types = array_keys( array_flip( array_column( $reviews, 'type' ))); |
|
| 268 | - $types = array_unique( array_merge( ['local'], $types )); |
|
| 266 | + while( $reviews = $this->queryReviews( $args, $lastPostId, $limit ) ) { |
|
| 267 | + $types = array_keys( array_flip( array_column( $reviews, 'type' ) ) ); |
|
| 268 | + $types = array_unique( array_merge( ['local'], $types ) ); |
|
| 269 | 269 | foreach( $types as $type ) { |
| 270 | 270 | $type = $this->normalizeType( $type ); |
| 271 | - if( isset( $counts[$type] ))continue; |
|
| 271 | + if( isset($counts[$type]) )continue; |
|
| 272 | 272 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 273 | 273 | } |
| 274 | 274 | foreach( $reviews as $review ) { |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | protected function decreaseRating( array $reviewCounts, $type, $rating ) |
| 289 | 289 | { |
| 290 | - if( isset( $reviewCounts[$type][$rating] )) { |
|
| 290 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
| 291 | 291 | $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
| 292 | 292 | } |
| 293 | 293 | return $reviewCounts; |
@@ -300,10 +300,10 @@ discard block |
||
| 300 | 300 | */ |
| 301 | 301 | protected function increaseRating( array $reviewCounts, $type, $rating ) |
| 302 | 302 | { |
| 303 | - if( !array_key_exists( $type, glsr()->reviewTypes )) { |
|
| 303 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
| 304 | 304 | return $reviewCounts; |
| 305 | 305 | } |
| 306 | - if( !array_key_exists( $type, $reviewCounts )) { |
|
| 306 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
| 307 | 307 | $reviewCounts[$type] = []; |
| 308 | 308 | } |
| 309 | 309 | $reviewCounts = $this->normalize( $reviewCounts ); |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | */ |
| 317 | 317 | protected function normalize( array $reviewCounts ) |
| 318 | 318 | { |
| 319 | - if( empty( $reviewCounts )) { |
|
| 319 | + if( empty($reviewCounts) ) { |
|
| 320 | 320 | $reviewCounts = [[]]; |
| 321 | 321 | } |
| 322 | 322 | foreach( $reviewCounts as &$counts ) { |
| 323 | 323 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 324 | - if( isset( $counts[$index] ))continue; |
|
| 324 | + if( isset($counts[$index]) )continue; |
|
| 325 | 325 | $counts[$index] = 0; |
| 326 | 326 | } |
| 327 | 327 | ksort( $counts ); |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | protected function normalizeType( $type ) |
| 337 | 337 | { |
| 338 | - return empty( $type ) || !is_string( $type ) |
|
| 338 | + return empty($type) || !is_string( $type ) |
|
| 339 | 339 | ? 'local' |
| 340 | 340 | : $type; |
| 341 | 341 | } |
@@ -347,14 +347,14 @@ discard block |
||
| 347 | 347 | */ |
| 348 | 348 | protected function queryReviews( array $args = [], $lastPostId, $limit ) |
| 349 | 349 | { |
| 350 | - $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' )); |
|
| 351 | - if( empty( array_filter( $args ))) { |
|
| 350 | + $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' ) ); |
|
| 351 | + if( empty(array_filter( $args )) ) { |
|
| 352 | 352 | return glsr( SqlQueries::class )->getReviewCounts( $lastPostId, $limit ); |
| 353 | 353 | } |
| 354 | - if( !empty( $args['post_id'] )) { |
|
| 354 | + if( !empty($args['post_id']) ) { |
|
| 355 | 355 | return glsr( SqlQueries::class )->getReviewPostCounts( $args['post_id'], $lastPostId, $limit ); |
| 356 | 356 | } |
| 357 | - if( !empty( $args['term_id'] )) { |
|
| 357 | + if( !empty($args['term_id']) ) { |
|
| 358 | 358 | return glsr( SqlQueries::class )->getReviewTermCounts( $args['term_id'], $lastPostId, $limit ); |
| 359 | 359 | } |
| 360 | 360 | } |
@@ -74,7 +74,9 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function decreasePostCounts( Review $review ) |
| 76 | 76 | { |
| 77 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
| 77 | + if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) { |
|
| 78 | + return; |
|
| 79 | + } |
|
| 78 | 80 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 79 | 81 | $this->setPostCounts( $review->assigned_to, $counts ); |
| 80 | 82 | } |
@@ -85,7 +87,9 @@ discard block |
||
| 85 | 87 | public function decreaseTermCounts( Review $review ) |
| 86 | 88 | { |
| 87 | 89 | foreach( $review->term_ids as $termId ) { |
| 88 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
| 90 | + if( empty( $counts = $this->getTermCounts( $termId ))) { |
|
| 91 | + continue; |
|
| 92 | + } |
|
| 89 | 93 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 90 | 94 | $this->setTermCounts( $termId, $counts ); |
| 91 | 95 | } |
@@ -107,7 +111,9 @@ discard block |
||
| 107 | 111 | 'min' => Rating::MIN_RATING, |
| 108 | 112 | ]); |
| 109 | 113 | foreach( $counts as $index => &$num ) { |
| 110 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 114 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] )) { |
|
| 115 | + continue; |
|
| 116 | + } |
|
| 111 | 117 | $num = 0; |
| 112 | 118 | } |
| 113 | 119 | return $counts; |
@@ -199,7 +205,9 @@ discard block |
||
| 199 | 205 | */ |
| 200 | 206 | public function increasePostCounts( Review $review ) |
| 201 | 207 | { |
| 202 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 208 | + if( !( get_post( $review->assigned_to ) instanceof WP_Post )) { |
|
| 209 | + return; |
|
| 210 | + } |
|
| 203 | 211 | $counts = $this->getPostCounts( $review->assigned_to ); |
| 204 | 212 | $counts = empty( $counts ) |
| 205 | 213 | ? $this->buildPostCounts( $review->assigned_to ) |
@@ -248,7 +256,9 @@ discard block |
||
| 248 | 256 | */ |
| 249 | 257 | public function setTermCounts( $termId, array $reviewCounts ) |
| 250 | 258 | { |
| 251 | - if( !term_exists( $termId ))return; |
|
| 259 | + if( !term_exists( $termId )) { |
|
| 260 | + return; |
|
| 261 | + } |
|
| 252 | 262 | $ratingCounts = $this->flatten( $reviewCounts ); |
| 253 | 263 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 254 | 264 | update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
@@ -268,7 +278,9 @@ discard block |
||
| 268 | 278 | $types = array_unique( array_merge( ['local'], $types )); |
| 269 | 279 | foreach( $types as $type ) { |
| 270 | 280 | $type = $this->normalizeType( $type ); |
| 271 | - if( isset( $counts[$type] ))continue; |
|
| 281 | + if( isset( $counts[$type] )) { |
|
| 282 | + continue; |
|
| 283 | + } |
|
| 272 | 284 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 273 | 285 | } |
| 274 | 286 | foreach( $reviews as $review ) { |
@@ -321,7 +333,9 @@ discard block |
||
| 321 | 333 | } |
| 322 | 334 | foreach( $reviewCounts as &$counts ) { |
| 323 | 335 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 324 | - if( isset( $counts[$index] ))continue; |
|
| 336 | + if( isset( $counts[$index] )) { |
|
| 337 | + continue; |
|
| 338 | + } |
|
| 325 | 339 | $counts[$index] = 0; |
| 326 | 340 | } |
| 327 | 341 | ksort( $counts ); |
@@ -31,25 +31,25 @@ discard block |
||
| 31 | 31 | public function __construct( $input ) |
| 32 | 32 | { |
| 33 | 33 | $this->request = $input; |
| 34 | - $this->ajax_request = isset( $input['_ajax_request'] ); |
|
| 34 | + $this->ajax_request = isset($input['_ajax_request']); |
|
| 35 | 35 | $this->assigned_to = $this->getNumeric( 'assign_to' ); |
| 36 | - $this->author = sanitize_text_field( $this->getUser( 'name' )); |
|
| 36 | + $this->author = sanitize_text_field( $this->getUser( 'name' ) ); |
|
| 37 | 37 | $this->avatar = $this->getAvatar(); |
| 38 | - $this->blacklisted = isset( $input['blacklisted'] ); |
|
| 39 | - $this->category = sanitize_key( $this->get( 'category' )); |
|
| 40 | - $this->content = sanitize_textarea_field( $this->get( 'content' )); |
|
| 38 | + $this->blacklisted = isset($input['blacklisted']); |
|
| 39 | + $this->category = sanitize_key( $this->get( 'category' ) ); |
|
| 40 | + $this->content = sanitize_textarea_field( $this->get( 'content' ) ); |
|
| 41 | 41 | $this->custom = $this->getCustom(); |
| 42 | 42 | $this->date = $this->getDate( 'date' ); |
| 43 | - $this->email = sanitize_email( $this->getUser( 'email' )); |
|
| 44 | - $this->form_id = sanitize_key( $this->get( 'form_id' )); |
|
| 43 | + $this->email = sanitize_email( $this->getUser( 'email' ) ); |
|
| 44 | + $this->form_id = sanitize_key( $this->get( 'form_id' ) ); |
|
| 45 | 45 | $this->ip_address = $this->get( 'ip_address' ); |
| 46 | - $this->post_id = intval( $this->get( '_post_id' )); |
|
| 47 | - $this->rating = intval( $this->get( 'rating' )); |
|
| 46 | + $this->post_id = intval( $this->get( '_post_id' ) ); |
|
| 47 | + $this->rating = intval( $this->get( 'rating' ) ); |
|
| 48 | 48 | $this->referer = $this->get( '_referer' ); |
| 49 | - $this->response = sanitize_textarea_field( $this->get( 'response' )); |
|
| 50 | - $this->terms = !empty( $input['terms'] ); |
|
| 51 | - $this->title = sanitize_text_field( $this->get( 'title' )); |
|
| 52 | - $this->url = esc_url_raw( $this->get( 'url' )); |
|
| 49 | + $this->response = sanitize_textarea_field( $this->get( 'response' ) ); |
|
| 50 | + $this->terms = !empty($input['terms']); |
|
| 51 | + $this->title = sanitize_text_field( $this->get( 'title' ) ); |
|
| 52 | + $this->url = esc_url_raw( $this->get( 'url' ) ); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | protected function get( $key ) |
| 60 | 60 | { |
| 61 | - return isset( $this->request[$key] ) |
|
| 61 | + return isset($this->request[$key]) |
|
| 62 | 62 | ? (string)$this->request[$key] |
| 63 | 63 | : ''; |
| 64 | 64 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | { |
| 71 | 71 | $avatar = $this->get( 'avatar' ); |
| 72 | 72 | return !filter_var( $avatar, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED | FILTER_FLAG_PATH_REQUIRED ) |
| 73 | - ? (string)get_avatar_url( $this->get( 'email' )) |
|
| 73 | + ? (string)get_avatar_url( $this->get( 'email' ) ) |
|
| 74 | 74 | : $avatar; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | ]; |
| 87 | 87 | $custom = $this->request; |
| 88 | 88 | foreach( $unset as $value ) { |
| 89 | - unset( $custom[$value] ); |
|
| 89 | + unset($custom[$value]); |
|
| 90 | 90 | } |
| 91 | 91 | return $custom; |
| 92 | 92 | } |
@@ -97,11 +97,11 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | protected function getDate( $key ) |
| 99 | 99 | { |
| 100 | - $date = strtotime( $this->get( $key )); |
|
| 100 | + $date = strtotime( $this->get( $key ) ); |
|
| 101 | 101 | if( $date === false ) { |
| 102 | 102 | $date = time(); |
| 103 | 103 | } |
| 104 | - return get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $date )); |
|
| 104 | + return get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $date ) ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -111,13 +111,13 @@ discard block |
||
| 111 | 111 | protected function getUser( $key ) |
| 112 | 112 | { |
| 113 | 113 | $value = $this->get( $key ); |
| 114 | - if( empty( $value )) { |
|
| 114 | + if( empty($value) ) { |
|
| 115 | 115 | $user = wp_get_current_user(); |
| 116 | 116 | $userValues = [ |
| 117 | 117 | 'email' => 'user_email', |
| 118 | 118 | 'name' => 'display_name', |
| 119 | 119 | ]; |
| 120 | - if( $user->exists() && array_key_exists( $key, $userValues )) { |
|
| 120 | + if( $user->exists() && array_key_exists( $key, $userValues ) ) { |
|
| 121 | 121 | return $user->{$userValues[$key]}; |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function enqueueAssets() |
| 25 | 25 | { |
| 26 | - $command = new EnqueueAdminAssets([ |
|
| 26 | + $command = new EnqueueAdminAssets( [ |
|
| 27 | 27 | 'pointers' => [[ |
| 28 | 28 | 'content' => __( 'You can pin exceptional reviews so that they are always shown first.', 'site-reviews' ), |
| 29 | 29 | 'id' => 'glsr-pointer-pinned', |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | 'target' => '#misc-pub-pinned', |
| 36 | 36 | 'title' => __( 'Pin Your Reviews', 'site-reviews' ), |
| 37 | 37 | ]], |
| 38 | - ]); |
|
| 38 | + ] ); |
|
| 39 | 39 | $this->execute( $command ); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | { |
| 48 | 48 | $links['settings'] = glsr( Builder::class )->a( __( 'Settings', 'site-reviews' ), [ |
| 49 | 49 | 'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=settings' ), |
| 50 | - ]); |
|
| 50 | + ] ); |
|
| 51 | 51 | return $links; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -58,19 +58,19 @@ discard block |
||
| 58 | 58 | public function filterDashboardGlanceItems( array $items ) |
| 59 | 59 | { |
| 60 | 60 | $postCount = wp_count_posts( Application::POST_TYPE ); |
| 61 | - if( empty( $postCount->publish )) { |
|
| 61 | + if( empty($postCount->publish) ) { |
|
| 62 | 62 | return $items; |
| 63 | 63 | } |
| 64 | 64 | $text = _n( '%s Review', '%s Reviews', $postCount->publish, 'site-reviews' ); |
| 65 | - $text = sprintf( $text, number_format_i18n( $postCount->publish )); |
|
| 65 | + $text = sprintf( $text, number_format_i18n( $postCount->publish ) ); |
|
| 66 | 66 | $items[] = current_user_can( get_post_type_object( Application::POST_TYPE )->cap->edit_posts ) |
| 67 | 67 | ? glsr( Builder::class )->a( $text, [ |
| 68 | 68 | 'class' => 'glsr-review-count', |
| 69 | 69 | 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
| 70 | - ]) |
|
| 70 | + ] ) |
|
| 71 | 71 | : glsr( Builder::class )->span( $text, [ |
| 72 | 72 | 'class' => 'glsr-review-count', |
| 73 | - ]); |
|
| 73 | + ] ); |
|
| 74 | 74 | return $items; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function filterTinymcePlugins( array $plugins ) |
| 82 | 82 | { |
| 83 | - if( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' )) { |
|
| 83 | + if( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) { |
|
| 84 | 84 | $plugins['glsr_shortcode'] = glsr()->url( 'assets/scripts/mce-plugin.js' ); |
| 85 | 85 | } |
| 86 | 86 | return $plugins; |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function registerTinymcePopups() |
| 94 | 94 | { |
| 95 | - $command = new RegisterTinymcePopups([ |
|
| 95 | + $command = new RegisterTinymcePopups( [ |
|
| 96 | 96 | 'site_reviews' => esc_html__( 'Recent Reviews', 'site-reviews' ), |
| 97 | 97 | 'site_reviews_form' => esc_html__( 'Submit a Review', 'site-reviews' ), |
| 98 | 98 | 'site_reviews_summary' => esc_html__( 'Summary of Reviews', 'site-reviews' ), |
| 99 | - ]); |
|
| 99 | + ] ); |
|
| 100 | 100 | $this->execute( $command ); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | public function renderTinymceButton( $editorId ) |
| 109 | 109 | { |
| 110 | 110 | $allowedEditors = apply_filters( 'site-reviews/tinymce/editor-ids', ['content'], $editorId ); |
| 111 | - if( glsr_current_screen()->base != 'post' || !in_array( $editorId, $allowedEditors ))return; |
|
| 111 | + if( glsr_current_screen()->base != 'post' || !in_array( $editorId, $allowedEditors ) )return; |
|
| 112 | 112 | $shortcodes = []; |
| 113 | 113 | foreach( glsr()->mceShortcodes as $shortcode => $values ) { |
| 114 | 114 | $shortcodes[$shortcode] = $values; |
| 115 | 115 | } |
| 116 | - if( empty( $shortcodes ))return; |
|
| 116 | + if( empty($shortcodes) )return; |
|
| 117 | 117 | glsr()->render( 'partials/editor/tinymce', [ |
| 118 | 118 | 'shortcodes' => $shortcodes, |
| 119 | - ]); |
|
| 119 | + ] ); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | public function routerClearConsole() |
| 126 | 126 | { |
| 127 | 127 | glsr( Console::class )->clear(); |
| 128 | - glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' )); |
|
| 128 | + glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' ) ); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public function routerFetchConsole() |
| 135 | 135 | { |
| 136 | - glsr( Notice::class )->addSuccess( __( 'Console reloaded.', 'site-reviews' )); |
|
| 136 | + glsr( Notice::class )->addSuccess( __( 'Console reloaded.', 'site-reviews' ) ); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -143,22 +143,22 @@ discard block |
||
| 143 | 143 | public function routerCountReviews( $showNotice = true ) |
| 144 | 144 | { |
| 145 | 145 | $countManager = glsr( CountsManager::class ); |
| 146 | - $terms = get_terms([ |
|
| 146 | + $terms = get_terms( [ |
|
| 147 | 147 | 'hide_empty' => true, |
| 148 | 148 | 'taxonomy' => Application::TAXONOMY, |
| 149 | - ]); |
|
| 149 | + ] ); |
|
| 150 | 150 | foreach( $terms as $term ) { |
| 151 | - $countManager->setTermCounts( $term->term_id, $countManager->buildTermCounts( $term->term_id )); |
|
| 151 | + $countManager->setTermCounts( $term->term_id, $countManager->buildTermCounts( $term->term_id ) ); |
|
| 152 | 152 | } |
| 153 | 153 | $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' ); |
| 154 | 154 | foreach( $postIds as $postId ) { |
| 155 | - $countManager->setPostCounts( $postId, $countManager->buildPostCounts( $postId )); |
|
| 155 | + $countManager->setPostCounts( $postId, $countManager->buildPostCounts( $postId ) ); |
|
| 156 | 156 | } |
| 157 | 157 | $countManager->setCounts( $countManager->buildCounts() ); |
| 158 | 158 | if( $showNotice ) { |
| 159 | - glsr( Notice::class )->clear()->addSuccess( __( 'Recalculated rating counts.', 'site-reviews' )); |
|
| 159 | + glsr( Notice::class )->clear()->addSuccess( __( 'Recalculated rating counts.', 'site-reviews' ) ); |
|
| 160 | 160 | } |
| 161 | - glsr( OptionManager::class )->set( 'last_review_count', current_time( 'timestamp' )); |
|
| 161 | + glsr( OptionManager::class )->set( 'last_review_count', current_time( 'timestamp' ) ); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -192,17 +192,17 @@ discard block |
||
| 192 | 192 | { |
| 193 | 193 | $file = $_FILES['import-file']; |
| 194 | 194 | if( $file['error'] !== UPLOAD_ERR_OK ) { |
| 195 | - return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] )); |
|
| 195 | + return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] ) ); |
|
| 196 | 196 | } |
| 197 | - if( $file['type'] !== 'application/json' || !glsr( Helper::class )->endsWith( '.json', $file['name'] )) { |
|
| 198 | - return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' )); |
|
| 197 | + if( $file['type'] !== 'application/json' || !glsr( Helper::class )->endsWith( '.json', $file['name'] ) ) { |
|
| 198 | + return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' ) ); |
|
| 199 | 199 | } |
| 200 | 200 | $settings = json_decode( file_get_contents( $file['tmp_name'] ), true ); |
| 201 | - if( empty( $settings )) { |
|
| 202 | - return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' )); |
|
| 201 | + if( empty($settings) ) { |
|
| 202 | + return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' ) ); |
|
| 203 | 203 | } |
| 204 | - glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings )); |
|
| 205 | - glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' )); |
|
| 204 | + glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings ) ); |
|
| 205 | + glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' ) ); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | UPLOAD_ERR_CANT_WRITE => __( 'Failed to write file to disk.', 'site-reviews' ), |
| 221 | 221 | UPLOAD_ERR_EXTENSION => __( 'A PHP extension stopped the file upload.', 'site-reviews' ), |
| 222 | 222 | ]; |
| 223 | - return !isset( $errors[$errorCode] ) |
|
| 223 | + return !isset($errors[$errorCode]) |
|
| 224 | 224 | ? __( 'Unknown upload error.', 'site-reviews' ) |
| 225 | 225 | : $errors[$errorCode]; |
| 226 | 226 | } |
@@ -108,12 +108,16 @@ |
||
| 108 | 108 | public function renderTinymceButton( $editorId ) |
| 109 | 109 | { |
| 110 | 110 | $allowedEditors = apply_filters( 'site-reviews/tinymce/editor-ids', ['content'], $editorId ); |
| 111 | - if( glsr_current_screen()->base != 'post' || !in_array( $editorId, $allowedEditors ))return; |
|
| 111 | + if( glsr_current_screen()->base != 'post' || !in_array( $editorId, $allowedEditors )) { |
|
| 112 | + return; |
|
| 113 | + } |
|
| 112 | 114 | $shortcodes = []; |
| 113 | 115 | foreach( glsr()->mceShortcodes as $shortcode => $values ) { |
| 114 | 116 | $shortcodes[$shortcode] = $values; |
| 115 | 117 | } |
| 116 | - if( empty( $shortcodes ))return; |
|
| 118 | + if( empty( $shortcodes )) { |
|
| 119 | + return; |
|
| 120 | + } |
|
| 117 | 121 | glsr()->render( 'partials/editor/tinymce', [ |
| 118 | 122 | 'shortcodes' => $shortcodes, |
| 119 | 123 | ]); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | public function callbackRegisterSettings( $input ) |
| 19 | 19 | { |
| 20 | - if( !is_array( $input )) { |
|
| 20 | + if( !is_array( $input ) ) { |
|
| 21 | 21 | $input = ['settings' => []]; |
| 22 | 22 | } |
| 23 | 23 | if( key( $input ) == 'settings' ) { |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | $options = $this->sanitizeSubmissions( $input, $options ); |
| 27 | 27 | $options = $this->sanitizeTranslations( $input, $options ); |
| 28 | 28 | if( filter_input( INPUT_POST, 'option_page' ) == Application::ID.'-settings' ) { |
| 29 | - glsr( Notice::class )->addSuccess( __( 'Settings updated.', 'site-reviews' )); |
|
| 29 | + glsr( Notice::class )->addSuccess( __( 'Settings updated.', 'site-reviews' ) ); |
|
| 30 | 30 | } |
| 31 | 31 | return $options; |
| 32 | 32 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | { |
| 42 | 42 | register_setting( Application::ID.'-settings', OptionManager::databaseKey(), [ |
| 43 | 43 | 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
| 44 | - ]); |
|
| 44 | + ] ); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | if( $inputForm['support']['polylang'] == 'yes' ) { |
| 54 | 54 | if( !glsr( Polylang::class )->isActive() ) { |
| 55 | 55 | $options['settings']['general']['support']['polylang'] = 'no'; |
| 56 | - glsr( Notice::class )->addError( __( 'Please install/activate the Polylang plugin to enable integration.', 'site-reviews' )); |
|
| 56 | + glsr( Notice::class )->addError( __( 'Please install/activate the Polylang plugin to enable integration.', 'site-reviews' ) ); |
|
| 57 | 57 | } |
| 58 | 58 | else if( !glsr( Polylang::class )->isSupported() ) { |
| 59 | 59 | $options['settings']['general']['support']['polylang'] = 'no'; |
| 60 | - glsr( Notice::class )->addError( __( 'Please update the Polylang plugin to v2.3.0 or greater to enable integration.', 'site-reviews' )); |
|
| 60 | + glsr( Notice::class )->addError( __( 'Please update the Polylang plugin to v2.3.0 or greater to enable integration.', 'site-reviews' ) ); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | - if( !isset( $inputForm['notifications'] )) { |
|
| 63 | + if( !isset($inputForm['notifications']) ) { |
|
| 64 | 64 | $options['settings']['general']['notifications'] = []; |
| 65 | 65 | } |
| 66 | 66 | if( trim( $inputForm['notification_message'] ) == '' ) { |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | protected function sanitizeSubmissions( array $input, array $options ) |
| 76 | 76 | { |
| 77 | 77 | $inputForm = $input['settings']['submissions']; |
| 78 | - if( !isset( $inputForm['required'] )) { |
|
| 78 | + if( !isset($inputForm['required']) ) { |
|
| 79 | 79 | $options['settings']['submissions']['required'] = []; |
| 80 | 80 | } |
| 81 | 81 | return $options; |
@@ -86,14 +86,14 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | protected function sanitizeTranslations( array $input, array $options ) |
| 88 | 88 | { |
| 89 | - if( isset( $input['settings']['strings'] )) { |
|
| 90 | - $options['settings']['strings'] = array_values( array_filter( $input['settings']['strings'] )); |
|
| 89 | + if( isset($input['settings']['strings']) ) { |
|
| 90 | + $options['settings']['strings'] = array_values( array_filter( $input['settings']['strings'] ) ); |
|
| 91 | 91 | $allowedTags = ['a' => ['class' => [], 'href' => [], 'target' => []]]; |
| 92 | - array_walk( $options['settings']['strings'], function( &$string ) use( $allowedTags ) { |
|
| 93 | - if( isset( $string['s2'] )) { |
|
| 92 | + array_walk( $options['settings']['strings'], function( &$string ) use($allowedTags) { |
|
| 93 | + if( isset($string['s2']) ) { |
|
| 94 | 94 | $string['s2'] = wp_kses( $string['s2'], $allowedTags ); |
| 95 | 95 | } |
| 96 | - if( isset( $string['p2'] )) { |
|
| 96 | + if( isset($string['p2']) ) { |
|
| 97 | 97 | $string['p2'] = wp_kses( $string['p2'], $allowedTags ); |
| 98 | 98 | } |
| 99 | 99 | }); |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | sort( $termIds ); |
| 27 | 27 | sort( $oldTermIds ); |
| 28 | - if( $termIds === $oldTermIds || !$this->isReviewPostId( $postId ))return; |
|
| 29 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 28 | + if( $termIds === $oldTermIds || !$this->isReviewPostId( $postId ) )return; |
|
| 29 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 30 | 30 | $ignoredTerms = array_intersect( $oldTermIds, $termIds ); |
| 31 | - if( $review->term_ids = array_diff( $oldTermIds, $ignoredTerms )) { |
|
| 31 | + if( $review->term_ids = array_diff( $oldTermIds, $ignoredTerms ) ) { |
|
| 32 | 32 | glsr( CountsManager::class )->decreaseTermCounts( $review ); |
| 33 | 33 | } |
| 34 | - if( $review->term_ids = array_diff( $termIds, $ignoredTerms )) { |
|
| 34 | + if( $review->term_ids = array_diff( $termIds, $ignoredTerms ) ) { |
|
| 35 | 35 | glsr( CountsManager::class )->increaseTermCounts( $review ); |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function onAfterChangeStatus( $newStatus, $oldStatus, WP_Post $post ) |
| 46 | 46 | { |
| 47 | - if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ))return; |
|
| 48 | - $review = glsr( ReviewManager::class )->single( get_post( $post->ID )); |
|
| 47 | + if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ) )return; |
|
| 48 | + $review = glsr( ReviewManager::class )->single( get_post( $post->ID ) ); |
|
| 49 | 49 | if( $post->post_status == 'publish' ) { |
| 50 | 50 | glsr( CountsManager::class )->increase( $review ); |
| 51 | 51 | } |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function onBeforeDelete( $postId ) |
| 73 | 73 | { |
| 74 | - if( !$this->isReviewPostId( $postId ))return; |
|
| 75 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 74 | + if( !$this->isReviewPostId( $postId ) )return; |
|
| 75 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 76 | 76 | glsr( CountsManager::class )->decrease( $review ); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | if( !$this->isReviewPostId( $postId ) |
| 90 | 90 | || !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] ) |
| 91 | 91 | )return; |
| 92 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 92 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 93 | 93 | if( $review->$metaKey == $metaValue )return; |
| 94 | 94 | $method = glsr( Helper::class )->buildMethodName( $metaKey, 'onBeforeChange' ); |
| 95 | 95 | call_user_func( [$this, $method], $review, $metaValue ); |
@@ -25,7 +25,9 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | sort( $termIds ); |
| 27 | 27 | sort( $oldTermIds ); |
| 28 | - if( $termIds === $oldTermIds || !$this->isReviewPostId( $postId ))return; |
|
| 28 | + if( $termIds === $oldTermIds || !$this->isReviewPostId( $postId )) { |
|
| 29 | + return; |
|
| 30 | + } |
|
| 29 | 31 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
| 30 | 32 | $ignoredTerms = array_intersect( $oldTermIds, $termIds ); |
| 31 | 33 | if( $review->term_ids = array_diff( $oldTermIds, $ignoredTerms )) { |
@@ -44,7 +46,9 @@ discard block |
||
| 44 | 46 | */ |
| 45 | 47 | public function onAfterChangeStatus( $newStatus, $oldStatus, WP_Post $post ) |
| 46 | 48 | { |
| 47 | - if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ))return; |
|
| 49 | + if( $post->post_type != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] )) { |
|
| 50 | + return; |
|
| 51 | + } |
|
| 48 | 52 | $review = glsr( ReviewManager::class )->single( get_post( $post->ID )); |
| 49 | 53 | if( $post->post_status == 'publish' ) { |
| 50 | 54 | glsr( CountsManager::class )->increase( $review ); |
@@ -60,7 +64,9 @@ discard block |
||
| 60 | 64 | */ |
| 61 | 65 | public function onAfterCreate( Review $review ) |
| 62 | 66 | { |
| 63 | - if( $review->status !== 'publish' )return; |
|
| 67 | + if( $review->status !== 'publish' ) { |
|
| 68 | + return; |
|
| 69 | + } |
|
| 64 | 70 | glsr( CountsManager::class )->increase( $review ); |
| 65 | 71 | } |
| 66 | 72 | |
@@ -71,7 +77,9 @@ discard block |
||
| 71 | 77 | */ |
| 72 | 78 | public function onBeforeDelete( $postId ) |
| 73 | 79 | { |
| 74 | - if( !$this->isReviewPostId( $postId ))return; |
|
| 80 | + if( !$this->isReviewPostId( $postId )) { |
|
| 81 | + return; |
|
| 82 | + } |
|
| 75 | 83 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
| 76 | 84 | glsr( CountsManager::class )->decrease( $review ); |
| 77 | 85 | } |
@@ -88,9 +96,13 @@ discard block |
||
| 88 | 96 | { |
| 89 | 97 | if( !$this->isReviewPostId( $postId ) |
| 90 | 98 | || !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] ) |
| 91 | - )return; |
|
| 99 | + ) { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 92 | 102 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
| 93 | - if( $review->$metaKey == $metaValue )return; |
|
| 103 | + if( $review->$metaKey == $metaValue ) { |
|
| 104 | + return; |
|
| 105 | + } |
|
| 94 | 106 | $method = glsr( Helper::class )->buildMethodName( $metaKey, 'onBeforeChange' ); |
| 95 | 107 | call_user_func( [$this, $method], $review, $metaValue ); |
| 96 | 108 | } |
@@ -13,11 +13,11 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | public function handle( Command $command ) |
| 15 | 15 | { |
| 16 | - $postId = wp_update_post([ |
|
| 16 | + $postId = wp_update_post( [ |
|
| 17 | 17 | 'ID' => $command->id, |
| 18 | 18 | 'post_status' => $command->status, |
| 19 | - ]); |
|
| 20 | - if( is_wp_error( $postId )) { |
|
| 19 | + ] ); |
|
| 20 | + if( is_wp_error( $postId ) ) { |
|
| 21 | 21 | glsr_log()->error( $postId->get_error_message() ); |
| 22 | 22 | return []; |
| 23 | 23 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | 'aria-label' => '“'.esc_attr( $title ).'” ('.__( 'Edit', 'site-reviews' ).')', |
| 40 | 40 | 'class' => 'row-title', |
| 41 | 41 | 'href' => get_edit_post_link( $postId ), |
| 42 | - ]); |
|
| 42 | + ] ); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | protected function getPostState( $postId ) |
| 50 | 50 | { |
| 51 | 51 | ob_start(); |
| 52 | - _post_states( get_post( $postId )); |
|
| 52 | + _post_states( get_post( $postId ) ); |
|
| 53 | 53 | return ob_get_clean(); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -59,13 +59,13 @@ discard block |
||
| 59 | 59 | protected function getStatusLinks() |
| 60 | 60 | { |
| 61 | 61 | global $avail_post_stati; |
| 62 | - require_once( ABSPATH.'wp-admin/includes/class-wp-posts-list-table.php' ); |
|
| 62 | + require_once(ABSPATH.'wp-admin/includes/class-wp-posts-list-table.php'); |
|
| 63 | 63 | $hookName = 'edit-'.Application::POST_TYPE; |
| 64 | 64 | set_current_screen( $hookName ); |
| 65 | 65 | $avail_post_stati = get_available_post_statuses( Application::POST_TYPE ); |
| 66 | 66 | $table = new \WP_Posts_List_Table( ['screen' => $hookName] ); |
| 67 | 67 | $views = apply_filters( 'views_'.$hookName, $table->get_views() ); // uses compat get_views() |
| 68 | - if( empty( $views ))return; |
|
| 68 | + if( empty($views) )return; |
|
| 69 | 69 | foreach( $views as $class => $view ) { |
| 70 | 70 | $views[$class] = "\t<li class='$class'>$view"; |
| 71 | 71 | } |
@@ -65,7 +65,9 @@ |
||
| 65 | 65 | $avail_post_stati = get_available_post_statuses( Application::POST_TYPE ); |
| 66 | 66 | $table = new \WP_Posts_List_Table( ['screen' => $hookName] ); |
| 67 | 67 | $views = apply_filters( 'views_'.$hookName, $table->get_views() ); // uses compat get_views() |
| 68 | - if( empty( $views ))return; |
|
| 68 | + if( empty( $views )) { |
|
| 69 | + return; |
|
| 70 | + } |
|
| 69 | 71 | foreach( $views as $class => $view ) { |
| 70 | 72 | $views[$class] = "\t<li class='$class'>$view"; |
| 71 | 73 | } |
@@ -20,9 +20,9 @@ discard block |
||
| 20 | 20 | * @see https://wordpress.org/plugins/wp-super-cache/ |
| 21 | 21 | */ |
| 22 | 22 | add_action( 'site-reviews/review/created', function( $review, $request ) { |
| 23 | - if( !function_exists( 'wp_cache_post_change' ))return; |
|
| 23 | + if( !function_exists( 'wp_cache_post_change' ) )return; |
|
| 24 | 24 | wp_cache_post_change( $request->post_id ); |
| 25 | - if( empty( $review->assigned_to ) || $review->assigned_to == $request->post_id )return; |
|
| 25 | + if( empty($review->assigned_to) || $review->assigned_to == $request->post_id )return; |
|
| 26 | 26 | wp_cache_post_change( $review->assigned_to ); |
| 27 | 27 | }, 10, 2 ); |
| 28 | 28 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | add_filter( 'sbp_exclude_defer_scripts', function( $scriptHandles ) { |
| 35 | 35 | $scriptHandles[] = 'site-reviews/google-recaptcha'; |
| 36 | - return array_keys( array_flip( $scriptHandles )); |
|
| 36 | + return array_keys( array_flip( $scriptHandles ) ); |
|
| 37 | 37 | }); |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @see https://searchandfilter.com/ |
| 44 | 44 | */ |
| 45 | 45 | add_filter( 'sf_edit_query_args', function( $query ) { |
| 46 | - if( !empty( $query['meta_key'] ) && $query['meta_key'] == '_glsr_ranking' ) { |
|
| 47 | - unset( $query['meta_key'] ); |
|
| 46 | + if( !empty($query['meta_key']) && $query['meta_key'] == '_glsr_ranking' ) { |
|
| 47 | + unset($query['meta_key']); |
|
| 48 | 48 | $query['meta_query'] = [ |
| 49 | 49 | 'relation' => 'OR', |
| 50 | 50 | ['key' => '_glsr_ranking', 'compare' => 'EXISTS'], |
@@ -8,7 +8,9 @@ discard block |
||
| 8 | 8 | * @see https://www.elegantthemes.com/gallery/divi/ |
| 9 | 9 | */ |
| 10 | 10 | add_action( 'site-reviews/customize/divi', function( $instance ) { |
| 11 | - if( $instance->tag != 'label' || $instance->args['type'] != 'checkbox' )return; |
|
| 11 | + if( $instance->tag != 'label' || $instance->args['type'] != 'checkbox' ) { |
|
| 12 | + return; |
|
| 13 | + } |
|
| 12 | 14 | $instance->args['text'] = '<i></i>'.$instance->args['text']; |
| 13 | 15 | }); |
| 14 | 16 | |
@@ -20,9 +22,13 @@ discard block |
||
| 20 | 22 | * @see https://wordpress.org/plugins/wp-super-cache/ |
| 21 | 23 | */ |
| 22 | 24 | add_action( 'site-reviews/review/created', function( $review, $request ) { |
| 23 | - if( !function_exists( 'wp_cache_post_change' ))return; |
|
| 25 | + if( !function_exists( 'wp_cache_post_change' )) { |
|
| 26 | + return; |
|
| 27 | + } |
|
| 24 | 28 | wp_cache_post_change( $request->post_id ); |
| 25 | - if( empty( $review->assigned_to ) || $review->assigned_to == $request->post_id )return; |
|
| 29 | + if( empty( $review->assigned_to ) || $review->assigned_to == $request->post_id ) { |
|
| 30 | + return; |
|
| 31 | + } |
|
| 26 | 32 | wp_cache_post_change( $review->assigned_to ); |
| 27 | 33 | }, 10, 2 ); |
| 28 | 34 | |