@@ -54,7 +54,9 @@ discard block |
||
54 | 54 | { |
55 | 55 | $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
56 | 56 | foreach( $postTypeColumns as $key => &$value ) { |
57 | - if( !array_key_exists( $key, $columns ) || !empty( $value ))continue; |
|
57 | + if( !array_key_exists( $key, $columns ) || !empty( $value )) { |
|
58 | + continue; |
|
59 | + } |
|
58 | 60 | $value = $columns[$key]; |
59 | 61 | } |
60 | 62 | if( count( glsr( Database::class )->getReviewsMeta( 'review_type' )) < 2 ) { |
@@ -92,7 +94,8 @@ discard block |
||
92 | 94 | * @return array |
93 | 95 | * @filter display_post_states |
94 | 96 | */ |
95 | - public function filterPostStates( array $postStates, WP_Post $post ) { |
|
97 | + public function filterPostStates( array $postStates, WP_Post $post ) |
|
98 | + { |
|
96 | 99 | if( $post->post_type == Application::POST_TYPE |
97 | 100 | && array_key_exists( 'pending', $postStates )) { |
98 | 101 | $postStates['pending'] = __( 'Unapproved', 'site-reviews' ); |
@@ -137,7 +140,9 @@ discard block |
||
137 | 140 | $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
138 | 141 | unset( $postTypeColumns['cb'] ); |
139 | 142 | foreach( $postTypeColumns as $key => $value ) { |
140 | - if( glsr( Helper::class )->startsWith( 'taxonomy', $key ))continue; |
|
143 | + if( glsr( Helper::class )->startsWith( 'taxonomy', $key )) { |
|
144 | + continue; |
|
145 | + } |
|
141 | 146 | $columns[$key] = $key; |
142 | 147 | } |
143 | 148 | return $columns; |
@@ -161,7 +166,9 @@ discard block |
||
161 | 166 | 'Pending' => __( 'Unapproved', 'site-reviews' ), |
162 | 167 | ]; |
163 | 168 | foreach( $strings as $search => $replace ) { |
164 | - if( strpos( $single, $search ) === false )continue; |
|
169 | + if( strpos( $single, $search ) === false ) { |
|
170 | + continue; |
|
171 | + } |
|
165 | 172 | $translation = $this->getTranslation([ |
166 | 173 | 'number' => $number, |
167 | 174 | 'plural' => str_replace( $search, $replace, $plural ), |
@@ -213,7 +220,9 @@ discard block |
||
213 | 220 | */ |
214 | 221 | public function saveBulkEditFields( $postId ) |
215 | 222 | { |
216 | - if( !current_user_can( 'edit_posts' ))return; |
|
223 | + if( !current_user_can( 'edit_posts' )) { |
|
224 | + return; |
|
225 | + } |
|
217 | 226 | $assignedTo = filter_input( INPUT_GET, 'assigned_to' ); |
218 | 227 | if( $assignedTo && get_post( $assignedTo )) { |
219 | 228 | update_post_meta( $postId, 'assigned_to', $assignedTo ); |
@@ -226,7 +235,9 @@ discard block |
||
226 | 235 | */ |
227 | 236 | public function setQueryForColumn( WP_Query $query ) |
228 | 237 | { |
229 | - if( !$this->hasPermission( $query ))return; |
|
238 | + if( !$this->hasPermission( $query )) { |
|
239 | + return; |
|
240 | + } |
|
230 | 241 | $this->setMetaQuery( $query, [ |
231 | 242 | 'rating', 'review_type', |
232 | 243 | ]); |
@@ -298,7 +309,9 @@ discard block |
||
298 | 309 | protected function setMetaQuery( WP_Query $query, array $metaKeys ) |
299 | 310 | { |
300 | 311 | foreach( $metaKeys as $key ) { |
301 | - if( !( $value = filter_input( INPUT_GET, $key )))continue; |
|
312 | + if( !( $value = filter_input( INPUT_GET, $key ))) { |
|
313 | + continue; |
|
314 | + } |
|
302 | 315 | $metaQuery = (array)$query->get( 'meta_query' ); |
303 | 316 | $metaQuery[] = [ |
304 | 317 | 'key' => $key, |
@@ -4,7 +4,8 @@ discard block |
||
4 | 4 | /** |
5 | 5 | * @return mixed |
6 | 6 | */ |
7 | -function glsr( $alias = null ) { |
|
7 | +function glsr( $alias = null ) |
|
8 | +{ |
|
8 | 9 | $app = \GeminiLabs\SiteReviews\Application::load(); |
9 | 10 | return !empty( $alias ) |
10 | 11 | ? $app->make( $alias ) |
@@ -14,7 +15,8 @@ discard block |
||
14 | 15 | /** |
15 | 16 | * @return \WP_Screen|object |
16 | 17 | */ |
17 | -function glsr_current_screen() { |
|
18 | +function glsr_current_screen() |
|
19 | +{ |
|
18 | 20 | if( function_exists( 'get_current_screen' )) { |
19 | 21 | $screen = get_current_screen(); |
20 | 22 | } |
@@ -26,7 +28,8 @@ discard block |
||
26 | 28 | /** |
27 | 29 | * @return \GeminiLabs\SiteReviews\Database |
28 | 30 | */ |
29 | -function glsr_db() { |
|
31 | +function glsr_db() |
|
32 | +{ |
|
30 | 33 | return glsr( 'Database' ); |
31 | 34 | } |
32 | 35 | |
@@ -34,7 +37,8 @@ discard block |
||
34 | 37 | * @param mixed ...$vars |
35 | 38 | * @return void |
36 | 39 | */ |
37 | -function glsr_debug( ...$vars ) { |
|
40 | +function glsr_debug( ...$vars ) |
|
41 | +{ |
|
38 | 42 | if( count( $vars ) == 1 ) { |
39 | 43 | $value = htmlspecialchars( print_r( $vars[0], true ), ENT_QUOTES, 'UTF-8' ); |
40 | 44 | printf( '<div class="glsr-debug"><pre>%s</pre></div>', $value ); |
@@ -51,7 +55,8 @@ discard block |
||
51 | 55 | /** |
52 | 56 | * @return \GeminiLabs\SiteReviews\Modules\Console |
53 | 57 | */ |
54 | -function glsr_log() { |
|
58 | +function glsr_log() |
|
59 | +{ |
|
55 | 60 | $args = func_get_args(); |
56 | 61 | $context = isset( $args[1] ) |
57 | 62 | ? $args[1] |
@@ -67,14 +72,16 @@ discard block |
||
67 | 72 | * @param mixed $fallback |
68 | 73 | * @return string|array |
69 | 74 | */ |
70 | -function glsr_get_option( $path = '', $fallback = '' ) { |
|
75 | +function glsr_get_option( $path = '', $fallback = '' ) |
|
76 | +{ |
|
71 | 77 | return glsr( 'Database\OptionManager' )->get( 'settings.'.$path, $fallback ); |
72 | 78 | } |
73 | 79 | |
74 | 80 | /** |
75 | 81 | * @return array |
76 | 82 | */ |
77 | -function glsr_get_options() { |
|
83 | +function glsr_get_options() |
|
84 | +{ |
|
78 | 85 | return glsr( 'Database\OptionManager' )->get( 'settings' ); |
79 | 86 | } |
80 | 87 | |
@@ -82,7 +89,8 @@ discard block |
||
82 | 89 | * @param int $post_id |
83 | 90 | * @return void|\GeminiLabs\SiteReviews\Review |
84 | 91 | */ |
85 | -function glsr_get_review( $post_id ) { |
|
92 | +function glsr_get_review( $post_id ) |
|
93 | +{ |
|
86 | 94 | $post = get_post( $post_id ); |
87 | 95 | if( $post instanceof WP_Post ) { |
88 | 96 | return glsr( 'Database\ReviewManager' )->single( $post ); |
@@ -93,6 +101,7 @@ discard block |
||
93 | 101 | * @return array |
94 | 102 | * @todo document change of $reviews->reviews to $reviews->results |
95 | 103 | */ |
96 | -function glsr_get_reviews( array $args = array() ) { |
|
104 | +function glsr_get_reviews( array $args = array() ) |
|
105 | +{ |
|
97 | 106 | return glsr( 'Database\ReviewManager' )->get( $args ); |
98 | 107 | } |
@@ -90,7 +90,9 @@ |
||
90 | 90 | { |
91 | 91 | $total = array_sum( $ratingCounts ); |
92 | 92 | foreach( $ratingCounts as $index => $count ) { |
93 | - if( empty( $count ))continue; |
|
93 | + if( empty( $count )) { |
|
94 | + continue; |
|
95 | + } |
|
94 | 96 | $ratingCounts[$index] = $count / $total * 100; |
95 | 97 | } |
96 | 98 | return $this->getRoundedPercentages( $ratingCounts ); |
@@ -36,7 +36,9 @@ discard block |
||
36 | 36 | // get rating counts |
37 | 37 | $this->ratingCounts = [0,0,0,0,0,0]; |
38 | 38 | |
39 | - if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ))return; |
|
39 | + if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' )) { |
|
40 | + return; |
|
41 | + } |
|
40 | 42 | $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts ); |
41 | 43 | $this->generateSchema(); |
42 | 44 | return glsr( Template::class )->build( 'templates/reviews-summary', [ |
@@ -56,7 +58,9 @@ discard block |
||
56 | 58 | */ |
57 | 59 | protected function buildPercentage() |
58 | 60 | { |
59 | - if( $this->isHidden( 'bars' ))return; |
|
61 | + if( $this->isHidden( 'bars' )) { |
|
62 | + return; |
|
63 | + } |
|
60 | 64 | $range = range( Rating::MAX_RATING, 1 ); |
61 | 65 | $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts )); |
62 | 66 | $bars = array_reduce( $range, function( $carry, $level ) use( $percentages ) { |
@@ -106,7 +110,9 @@ discard block |
||
106 | 110 | */ |
107 | 111 | protected function buildRating() |
108 | 112 | { |
109 | - if( $this->isHidden( 'rating' ))return; |
|
113 | + if( $this->isHidden( 'rating' )) { |
|
114 | + return; |
|
115 | + } |
|
110 | 116 | return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' ); |
111 | 117 | } |
112 | 118 | |
@@ -115,7 +121,9 @@ discard block |
||
115 | 121 | */ |
116 | 122 | protected function buildStars() |
117 | 123 | { |
118 | - if( $this->isHidden( 'stars' ))return; |
|
124 | + if( $this->isHidden( 'stars' )) { |
|
125 | + return; |
|
126 | + } |
|
119 | 127 | $stars = glsr( Partial::class )->build( 'star-rating', [ |
120 | 128 | 'rating' => $this->averageRating, |
121 | 129 | ]); |
@@ -127,7 +135,9 @@ discard block |
||
127 | 135 | */ |
128 | 136 | protected function buildText() |
129 | 137 | { |
130 | - if( $this->isHidden( 'summary' ))return; |
|
138 | + if( $this->isHidden( 'summary' )) { |
|
139 | + return; |
|
140 | + } |
|
131 | 141 | $count = array_sum( $this->ratingCounts ); |
132 | 142 | if( empty( $this->args['text'] )) { |
133 | 143 | // @todo document this change |
@@ -152,7 +162,9 @@ discard block |
||
152 | 162 | */ |
153 | 163 | protected function generateSchema() |
154 | 164 | { |
155 | - if( !wp_validate_boolean( $this->args['schema'] ))return; |
|
165 | + if( !wp_validate_boolean( $this->args['schema'] )) { |
|
166 | + return; |
|
167 | + } |
|
156 | 168 | glsr( Schema::class )->store( |
157 | 169 | glsr( Schema::class )->buildSummary( $this->args ) |
158 | 170 | ); |
@@ -16,9 +16,13 @@ discard block |
||
16 | 16 | { |
17 | 17 | $queries = []; |
18 | 18 | foreach( $keys as $key ) { |
19 | - if( !array_key_exists( $key, $values ))continue; |
|
19 | + if( !array_key_exists( $key, $values )) { |
|
20 | + continue; |
|
21 | + } |
|
20 | 22 | $methodName = glsr( Helper::class )->buildMethodName( $key, __FUNCTION__ ); |
21 | - if( !method_exists( $this, $methodName ))continue; |
|
23 | + if( !method_exists( $this, $methodName )) { |
|
24 | + continue; |
|
25 | + } |
|
22 | 26 | $query = call_user_func( [$this, $methodName], $values[$key] ); |
23 | 27 | if( is_array( $query )) { |
24 | 28 | $queries[] = $query; |
@@ -35,7 +39,9 @@ discard block |
||
35 | 39 | $string = ''; |
36 | 40 | $values = array_filter( $values ); |
37 | 41 | foreach( $conditions as $key => $value ) { |
38 | - if( !isset( $values[$key] ))continue; |
|
42 | + if( !isset( $values[$key] )) { |
|
43 | + continue; |
|
44 | + } |
|
39 | 45 | $values[$key] = implode( ',', (array)$values[$key] ); |
40 | 46 | $string .= strpos( $value, '%s' ) !== false |
41 | 47 | ? sprintf( $value, strval( $values[$key] )) |
@@ -109,7 +115,9 @@ discard block |
||
109 | 115 | */ |
110 | 116 | protected function buildQueryAssignedTo( $value ) |
111 | 117 | { |
112 | - if( empty( $value ))return; |
|
118 | + if( empty( $value )) { |
|
119 | + return; |
|
120 | + } |
|
113 | 121 | return [ |
114 | 122 | 'compare' => 'IN', |
115 | 123 | 'key' => 'assigned_to', |
@@ -123,7 +131,9 @@ discard block |
||
123 | 131 | */ |
124 | 132 | protected function buildQueryCategory( $value ) |
125 | 133 | { |
126 | - if( empty( $value ))return; |
|
134 | + if( empty( $value )) { |
|
135 | + return; |
|
136 | + } |
|
127 | 137 | return [ |
128 | 138 | 'field' => 'term_id', |
129 | 139 | 'taxonomy' => Application::TAXONOMY, |
@@ -137,7 +147,9 @@ discard block |
||
137 | 147 | */ |
138 | 148 | protected function buildQueryRating( $value ) |
139 | 149 | { |
140 | - if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 )))return; |
|
150 | + if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 ))) { |
|
151 | + return; |
|
152 | + } |
|
141 | 153 | return [ |
142 | 154 | 'compare' => '>=', |
143 | 155 | 'key' => 'rating', |
@@ -151,7 +163,9 @@ discard block |
||
151 | 163 | */ |
152 | 164 | protected function buildQueryType( $value ) |
153 | 165 | { |
154 | - if( in_array( $value, ['','all'] ))return; |
|
166 | + if( in_array( $value, ['','all'] )) { |
|
167 | + return; |
|
168 | + } |
|
155 | 169 | return [ |
156 | 170 | 'key' => 'review_type', |
157 | 171 | 'value' => $value, |
@@ -18,7 +18,9 @@ discard block |
||
18 | 18 | while( $reviews = glsr( SqlQueries::class )->getReviewRatings( $args, $greaterThanId, $limit )) { |
19 | 19 | $types = array_keys( array_flip( array_column( $reviews, 'type' ))); |
20 | 20 | foreach( $types as $type ) { |
21 | - if( isset( $counts[$type] ))continue; |
|
21 | + if( isset( $counts[$type] )) { |
|
22 | + continue; |
|
23 | + } |
|
22 | 24 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
23 | 25 | } |
24 | 26 | foreach( $reviews as $review ) { |
@@ -77,7 +79,9 @@ discard block |
||
77 | 79 | array_walk( $counts, function( &$ratings ) use( $args ) { |
78 | 80 | $ratings[0] = 0; |
79 | 81 | foreach( $ratings as $index => &$num ) { |
80 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
82 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] )) { |
|
83 | + continue; |
|
84 | + } |
|
81 | 85 | $num = 0; |
82 | 86 | } |
83 | 87 | }); |
@@ -99,7 +103,9 @@ discard block |
||
99 | 103 | { |
100 | 104 | foreach( $reviewCounts as $type => &$counts ) { |
101 | 105 | foreach( range( 0, Rating::MAX_RATING ) as $rating ) { |
102 | - if( isset( $counts[$rating] ))continue; |
|
106 | + if( isset( $counts[$rating] )) { |
|
107 | + continue; |
|
108 | + } |
|
103 | 109 | $counts[$rating] = 0; |
104 | 110 | } |
105 | 111 | ksort( $counts ); |
@@ -23,7 +23,9 @@ discard block |
||
23 | 23 | if( empty( $assignedTo )) { |
24 | 24 | $assignedTo = get_post_meta( $postId, 'assigned_to', true ); |
25 | 25 | } |
26 | - if( empty( $assignedTo ))return; |
|
26 | + if( empty( $assignedTo )) { |
|
27 | + return; |
|
28 | + } |
|
27 | 29 | $assignedPost = get_post( $assignedTo ); |
28 | 30 | if( $assignedPost instanceof WP_Post && $assignedPost->ID != $postId ) { |
29 | 31 | return $assignedPost; |
@@ -112,7 +114,9 @@ discard block |
||
112 | 114 | add_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2 ); |
113 | 115 | $search = new WP_Query( $args ); |
114 | 116 | remove_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500 ); |
115 | - if( !$search->have_posts() )return; |
|
117 | + if( !$search->have_posts() ) { |
|
118 | + return; |
|
119 | + } |
|
116 | 120 | $results = ''; |
117 | 121 | while( $search->have_posts() ) { |
118 | 122 | $search->the_post(); |
@@ -21,7 +21,9 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function onBeforeDeleteReview( $postId ) |
23 | 23 | { |
24 | - if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE )return; |
|
24 | + if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE ) { |
|
25 | + return; |
|
26 | + } |
|
25 | 27 | $review = get_post( $postId ); |
26 | 28 | $review->post_status = 'deleted'; // change post_status first! |
27 | 29 | $this->updateAssignedToPost( $review ); |
@@ -37,7 +39,9 @@ discard block |
||
37 | 39 | public function onBeforeUpdateReview( WP_Post $review, $metaKey, $newValue ) |
38 | 40 | { |
39 | 41 | $previousValue = get_post_meta( $review->ID, $metaKey, true ); |
40 | - if( $previousValue == $newValue )return; |
|
42 | + if( $previousValue == $newValue ) { |
|
43 | + return; |
|
44 | + } |
|
41 | 45 | $this->decreaseReviewCount( $review ); |
42 | 46 | $this->increaseReviewCount( $review, [$metaKey => $newValue] ); |
43 | 47 | } |
@@ -50,7 +54,9 @@ discard block |
||
50 | 54 | */ |
51 | 55 | public function onCreateReview( $postData, $meta, $postId ) |
52 | 56 | { |
53 | - if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE )return; |
|
57 | + if( get_post_field( 'post_type', $postId ) !== Application::POST_TYPE ) { |
|
58 | + return; |
|
59 | + } |
|
54 | 60 | $review = get_post( $postId ); |
55 | 61 | $this->updateAssignedToPost( $review ); |
56 | 62 | $this->increaseReviewCount( $review ); |
@@ -86,7 +92,9 @@ discard block |
||
86 | 92 | */ |
87 | 93 | public function saveAssignedToMetabox( $postId ) |
88 | 94 | { |
89 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' ))return; |
|
95 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-assigned-to' ), 'assigned_to' )) { |
|
96 | + return; |
|
97 | + } |
|
90 | 98 | $assignedTo = glsr( Helper::class )->filterInput( 'assigned_to' ); |
91 | 99 | $assignedTo || $assignedTo = ''; |
92 | 100 | if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) { |
@@ -101,7 +109,9 @@ discard block |
||
101 | 109 | */ |
102 | 110 | public function saveResponseMetabox( $postId ) |
103 | 111 | { |
104 | - if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' ))return; |
|
112 | + if( !wp_verify_nonce( glsr( Helper::class )->filterInput( '_nonce-response' ), 'response' )) { |
|
113 | + return; |
|
114 | + } |
|
105 | 115 | $response = glsr( Helper::class )->filterInput( 'response' ); |
106 | 116 | $response || $response = ''; |
107 | 117 | update_post_meta( $postId, 'response', trim( wp_kses( $response, [ |
@@ -146,7 +156,9 @@ discard block |
||
146 | 156 | protected function setReviewCounts( WP_Post $review, array $counts ) |
147 | 157 | { |
148 | 158 | $type = strval( get_post_meta( $review->ID, 'review_type', true )); |
149 | - if( !array_key_exists( $type, glsr()->reviewTypes ))return; |
|
159 | + if( !array_key_exists( $type, glsr()->reviewTypes )) { |
|
160 | + return; |
|
161 | + } |
|
150 | 162 | glsr( OptionManager::class )->set( 'counts.'.$type, $counts ); |
151 | 163 | } |
152 | 164 | |
@@ -197,9 +209,13 @@ discard block |
||
197 | 209 | */ |
198 | 210 | protected function updateAssignedToPost( WP_Post $review ) |
199 | 211 | { |
200 | - if( !( $postId = $this->getAssignedToPostId( $review->ID )))return; |
|
212 | + if( !( $postId = $this->getAssignedToPostId( $review->ID ))) { |
|
213 | + return; |
|
214 | + } |
|
201 | 215 | $reviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID )); |
202 | - if( empty( $reviewIds ))return; |
|
216 | + if( empty( $reviewIds )) { |
|
217 | + return; |
|
218 | + } |
|
203 | 219 | $this->updateReviewIdOfPost( $postId, $review, $reviewIds ); |
204 | 220 | $updatedReviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID )); |
205 | 221 | if( empty( $updatedReviewIds )) { |