@@ -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 false|\GeminiLabs\SiteReviews\Review |
16 | 17 | */ |
17 | -function glsr_create_review( array $reviewValues = [] ) { |
|
18 | +function glsr_create_review( array $reviewValues = [] ) |
|
19 | +{ |
|
18 | 20 | if( empty( $reviewValues )) { |
19 | 21 | return false; |
20 | 22 | } |
@@ -25,7 +27,8 @@ discard block |
||
25 | 27 | /** |
26 | 28 | * @return \WP_Screen|object |
27 | 29 | */ |
28 | -function glsr_current_screen() { |
|
30 | +function glsr_current_screen() |
|
31 | +{ |
|
29 | 32 | if( function_exists( 'get_current_screen' )) { |
30 | 33 | $screen = get_current_screen(); |
31 | 34 | } |
@@ -38,7 +41,8 @@ discard block |
||
38 | 41 | * @param mixed ...$vars |
39 | 42 | * @return void |
40 | 43 | */ |
41 | -function glsr_debug( ...$vars ) { |
|
44 | +function glsr_debug( ...$vars ) |
|
45 | +{ |
|
42 | 46 | if( count( $vars ) == 1 ) { |
43 | 47 | $value = htmlspecialchars( print_r( $vars[0], true ), ENT_QUOTES, 'UTF-8' ); |
44 | 48 | printf( '<div class="glsr-debug"><pre>%s</pre></div>', $value ); |
@@ -57,14 +61,16 @@ discard block |
||
57 | 61 | * @param mixed $fallback |
58 | 62 | * @return string|array |
59 | 63 | */ |
60 | -function glsr_get_option( $path = '', $fallback = '' ) { |
|
64 | +function glsr_get_option( $path = '', $fallback = '' ) |
|
65 | +{ |
|
61 | 66 | return glsr( 'Database\OptionManager' )->get( 'settings.'.$path, $fallback ); |
62 | 67 | } |
63 | 68 | |
64 | 69 | /** |
65 | 70 | * @return array |
66 | 71 | */ |
67 | -function glsr_get_options() { |
|
72 | +function glsr_get_options() |
|
73 | +{ |
|
68 | 74 | return glsr( 'Database\OptionManager' )->get( 'settings' ); |
69 | 75 | } |
70 | 76 | |
@@ -72,7 +78,8 @@ discard block |
||
72 | 78 | * @param int $post_id |
73 | 79 | * @return void|\GeminiLabs\SiteReviews\Review |
74 | 80 | */ |
75 | -function glsr_get_review( $post_id ) { |
|
81 | +function glsr_get_review( $post_id ) |
|
82 | +{ |
|
76 | 83 | $post = get_post( $post_id ); |
77 | 84 | if( $post instanceof WP_Post ) { |
78 | 85 | return glsr( 'Database\ReviewManager' )->single( $post ); |
@@ -83,14 +90,16 @@ discard block |
||
83 | 90 | * @return array |
84 | 91 | * @todo document change of $reviews->reviews to $reviews->results |
85 | 92 | */ |
86 | -function glsr_get_reviews( array $args = array() ) { |
|
93 | +function glsr_get_reviews( array $args = array() ) |
|
94 | +{ |
|
87 | 95 | return glsr( 'Database\ReviewManager' )->get( $args ); |
88 | 96 | } |
89 | 97 | |
90 | 98 | /** |
91 | 99 | * @return \GeminiLabs\SiteReviews\Modules\Console |
92 | 100 | */ |
93 | -function glsr_log() { |
|
101 | +function glsr_log() |
|
102 | +{ |
|
94 | 103 | $args = func_get_args(); |
95 | 104 | $context = isset( $args[1] ) |
96 | 105 | ? $args[1] |
@@ -175,8 +175,12 @@ discard block |
||
175 | 175 | */ |
176 | 176 | protected function validateAkismet() |
177 | 177 | { |
178 | - if( !empty( $this->error ))return; |
|
179 | - if( !glsr( Akismet::class )->isSpam( $this->request ))return; |
|
178 | + if( !empty( $this->error )) { |
|
179 | + return; |
|
180 | + } |
|
181 | + if( !glsr( Akismet::class )->isSpam( $this->request )) { |
|
182 | + return; |
|
183 | + } |
|
180 | 184 | $this->setSessionValues( 'errors', [], 'Akismet caught a spam submission:' ); |
181 | 185 | $this->error = __( 'Your review cannot be submitted at this time. Please try again later.', 'site-reviews' ); |
182 | 186 | } |
@@ -186,8 +190,12 @@ discard block |
||
186 | 190 | */ |
187 | 191 | protected function validateBlacklist() |
188 | 192 | { |
189 | - if( !empty( $this->error ))return; |
|
190 | - if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return; |
|
193 | + if( !empty( $this->error )) { |
|
194 | + return; |
|
195 | + } |
|
196 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request )) { |
|
197 | + return; |
|
198 | + } |
|
191 | 199 | $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
192 | 200 | if( $blacklistAction == 'reject' ) { |
193 | 201 | $this->setSessionValues( 'errors', [], 'Blacklisted submission detected:' ); |
@@ -202,9 +210,13 @@ discard block |
||
202 | 210 | */ |
203 | 211 | protected function validateCustom() |
204 | 212 | { |
205 | - if( !empty( $this->error ))return; |
|
213 | + if( !empty( $this->error )) { |
|
214 | + return; |
|
215 | + } |
|
206 | 216 | $validated = apply_filters( 'site-reviews/validate/custom', true, $this->request ); |
207 | - if( $validated === true )return; |
|
217 | + if( $validated === true ) { |
|
218 | + return; |
|
219 | + } |
|
208 | 220 | $this->setSessionValues( 'errors', [] ); |
209 | 221 | $this->setSessionValues( 'values', $this->request ); |
210 | 222 | $this->error = is_string( $validated ) |
@@ -217,8 +229,12 @@ discard block |
||
217 | 229 | */ |
218 | 230 | protected function validateHoneyPot() |
219 | 231 | { |
220 | - if( !empty( $this->error ))return; |
|
221 | - if( empty( $this->request['gotcha'] ))return; |
|
232 | + if( !empty( $this->error )) { |
|
233 | + return; |
|
234 | + } |
|
235 | + if( empty( $this->request['gotcha'] )) { |
|
236 | + return; |
|
237 | + } |
|
222 | 238 | $this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' ); |
223 | 239 | $this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
224 | 240 | } |
@@ -228,9 +244,13 @@ discard block |
||
228 | 244 | */ |
229 | 245 | protected function validateRecaptcha() |
230 | 246 | { |
231 | - if( !empty( $this->error ))return; |
|
247 | + if( !empty( $this->error )) { |
|
248 | + return; |
|
249 | + } |
|
232 | 250 | $status = $this->getRecaptchaStatus(); |
233 | - if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ))return; |
|
251 | + if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] )) { |
|
252 | + return; |
|
253 | + } |
|
234 | 254 | if( $status == static::RECAPTCHA_EMPTY ) { |
235 | 255 | $this->setSessionValues( 'recaptcha', 'unset' ); |
236 | 256 | $this->recaptchaIsUnset = true; |
@@ -85,7 +85,9 @@ discard block |
||
85 | 85 | */ |
86 | 86 | protected function buildRecaptcha() |
87 | 87 | { |
88 | - if( !glsr( OptionManager::class )->isRecaptchaEnabled() )return; |
|
88 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
89 | + return; |
|
90 | + } |
|
89 | 91 | return glsr( Builder::class )->div([ |
90 | 92 | 'class' => 'glsr-recaptcha-holder', |
91 | 93 | 'data-badge' => glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.position' ), |
@@ -161,7 +163,9 @@ discard block |
||
161 | 163 | */ |
162 | 164 | protected function getRegisterText() |
163 | 165 | { |
164 | - if( !get_option( 'users_can_register' ) || glsr( OptionManager::class )->get( 'settings.general.require.login' ) != 'yes' )return; |
|
166 | + if( !get_option( 'users_can_register' ) || glsr( OptionManager::class )->get( 'settings.general.require.login' ) != 'yes' ) { |
|
167 | + return; |
|
168 | + } |
|
165 | 169 | $registerLink = glsr( Builder::class )->a([ |
166 | 170 | 'href' => wp_registration_url(), |
167 | 171 | 'text' => __( 'register', 'site-reviews' ), |
@@ -233,7 +237,9 @@ discard block |
||
233 | 237 | */ |
234 | 238 | protected function normalizeFieldErrors( Field &$field ) |
235 | 239 | { |
236 | - if( !array_key_exists( $field->field['path'], $this->errors ))return; |
|
240 | + if( !array_key_exists( $field->field['path'], $this->errors )) { |
|
241 | + return; |
|
242 | + } |
|
237 | 243 | $field->field['errors'] = $this->errors[$field->field['path']]; |
238 | 244 | } |
239 | 245 | |
@@ -242,7 +248,9 @@ discard block |
||
242 | 248 | */ |
243 | 249 | protected function normalizeFieldRequired( Field &$field ) |
244 | 250 | { |
245 | - if( !in_array( $field->field['path'], $this->required ))return; |
|
251 | + if( !in_array( $field->field['path'], $this->required )) { |
|
252 | + return; |
|
253 | + } |
|
246 | 254 | $field->field['required'] = true; |
247 | 255 | } |
248 | 256 | |
@@ -253,7 +261,9 @@ discard block |
||
253 | 261 | { |
254 | 262 | $normalizedFields = []; |
255 | 263 | foreach( $fields as $field ) { |
256 | - if( in_array( $field->field['path'], $this->args['hide'] ))continue; |
|
264 | + if( in_array( $field->field['path'], $this->args['hide'] )) { |
|
265 | + continue; |
|
266 | + } |
|
257 | 267 | $field->field['is_public'] = true; |
258 | 268 | $this->normalizeFieldClass( $field ); |
259 | 269 | $this->normalizeFieldErrors( $field ); |
@@ -269,7 +279,9 @@ discard block |
||
269 | 279 | */ |
270 | 280 | protected function normalizeFieldValue( Field &$field ) |
271 | 281 | { |
272 | - if( !array_key_exists( $field->field['path'], $this->values ))return; |
|
282 | + if( !array_key_exists( $field->field['path'], $this->values )) { |
|
283 | + return; |
|
284 | + } |
|
273 | 285 | if( in_array( $field->field['type'], ['radio', 'checkbox'] )) { |
274 | 286 | $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
275 | 287 | } |