@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $this->validateBlacklist(); |
| 68 | 68 | $this->validateAkismet(); |
| 69 | 69 | $this->validateRecaptcha(); |
| 70 | - if( !empty( $this->error )) { |
|
| 70 | + if( !empty($this->error) ) { |
|
| 71 | 71 | $this->setSessionValues( 'message', $this->error ); |
| 72 | 72 | } |
| 73 | 73 | return $this; |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
| 92 | 92 | return static::RECAPTCHA_DISABLED; |
| 93 | 93 | } |
| 94 | - if( empty( $this->request['_recaptcha-token'] )) { |
|
| 95 | - return $this->request['_counter'] < intval( apply_filters( 'site-reviews/recaptcha/timeout', 5 )) |
|
| 94 | + if( empty($this->request['_recaptcha-token']) ) { |
|
| 95 | + return $this->request['_counter'] < intval( apply_filters( 'site-reviews/recaptcha/timeout', 5 ) ) |
|
| 96 | 96 | ? static::RECAPTCHA_EMPTY |
| 97 | 97 | : static::RECAPTCHA_FAILED; |
| 98 | 98 | } |
@@ -104,17 +104,17 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | protected function getRecaptchaTokenStatus() |
| 106 | 106 | { |
| 107 | - $endpoint = add_query_arg([ |
|
| 107 | + $endpoint = add_query_arg( [ |
|
| 108 | 108 | 'remoteip' => glsr( Helper::class )->getIpAddress(), |
| 109 | 109 | 'response' => $this->request['_recaptcha-token'], |
| 110 | 110 | 'secret' => $this->getOption( 'settings.submissions.recaptcha.secret' ), |
| 111 | 111 | ], static::RECAPTCHA_ENDPOINT ); |
| 112 | - if( is_wp_error( $response = wp_remote_get( $endpoint ))) { |
|
| 112 | + if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) { |
|
| 113 | 113 | glsr_log()->error( $response->get_error_message() ); |
| 114 | 114 | return static::RECAPTCHA_FAILED; |
| 115 | 115 | } |
| 116 | - $response = json_decode( wp_remote_retrieve_body( $response )); |
|
| 117 | - if( !empty( $response->success )) { |
|
| 116 | + $response = json_decode( wp_remote_retrieve_body( $response ) ); |
|
| 117 | + if( !empty($response->success) ) { |
|
| 118 | 118 | return boolval( $response->success ) |
| 119 | 119 | ? static::RECAPTCHA_VALID |
| 120 | 120 | : static::RECAPTCHA_INVALID; |
@@ -132,12 +132,12 @@ discard block |
||
| 132 | 132 | { |
| 133 | 133 | $rules = array_intersect_key( |
| 134 | 134 | apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES, $request ), |
| 135 | - array_flip( $this->getOption( 'settings.submissions.required', [] )) |
|
| 135 | + array_flip( $this->getOption( 'settings.submissions.required', [] ) ) |
|
| 136 | 136 | ); |
| 137 | - $excluded = isset( $request['excluded'] ) |
|
| 137 | + $excluded = isset($request['excluded']) |
|
| 138 | 138 | ? explode( ',', $request['excluded'] ) |
| 139 | 139 | : []; |
| 140 | - return array_diff_key( $rules, array_flip( $excluded )); |
|
| 140 | + return array_diff_key( $rules, array_flip( $excluded ) ); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | { |
| 148 | 148 | $rules = $this->getValidationRules( $request ); |
| 149 | 149 | $errors = glsr( Validator::class )->validate( $request, $rules ); |
| 150 | - if( empty( $errors )) { |
|
| 150 | + if( empty($errors) ) { |
|
| 151 | 151 | return true; |
| 152 | 152 | } |
| 153 | 153 | $this->setSessionValues( 'errors', $errors ); |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | protected function setSessionValues( $type, $value, $loggedMessage = '' ) |
| 165 | 165 | { |
| 166 | 166 | glsr( Session::class )->set( $this->form_id.$type, $value ); |
| 167 | - if( !empty( $loggedMessage )) { |
|
| 167 | + if( !empty($loggedMessage) ) { |
|
| 168 | 168 | glsr_log()->warning( $loggedMessage ); |
| 169 | 169 | glsr_log()->warning( $this->request ); |
| 170 | 170 | } |
@@ -175,8 +175,8 @@ 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) )return; |
|
| 179 | + if( !glsr( Akismet::class )->isSpam( $this->request ) )return; |
|
| 180 | 180 | $this->setSessionValues( 'errors', [], 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' ); |
| 181 | 181 | $this->error = __( 'This review has been flagged as possible spam and cannot be submitted.', 'site-reviews' ); |
| 182 | 182 | } |
@@ -186,8 +186,8 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | protected function validateBlacklist() |
| 188 | 188 | { |
| 189 | - if( !empty( $this->error ))return; |
|
| 190 | - if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return; |
|
| 189 | + if( !empty($this->error) )return; |
|
| 190 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) )return; |
|
| 191 | 191 | $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
| 192 | 192 | if( $blacklistAction == 'reject' ) { |
| 193 | 193 | $this->setSessionValues( 'errors', [], 'Blacklisted submission detected:' ); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | protected function validateCustom() |
| 204 | 204 | { |
| 205 | - if( !empty( $this->error ))return; |
|
| 205 | + if( !empty($this->error) )return; |
|
| 206 | 206 | $validated = apply_filters( 'site-reviews/validate/custom', true, $this->request ); |
| 207 | 207 | if( $validated === true )return; |
| 208 | 208 | $this->setSessionValues( 'errors', [] ); |
@@ -217,8 +217,8 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | protected function validateHoneyPot() |
| 219 | 219 | { |
| 220 | - if( !empty( $this->error ))return; |
|
| 221 | - if( empty( $this->request['gotcha'] ))return; |
|
| 220 | + if( !empty($this->error) )return; |
|
| 221 | + if( empty($this->request['gotcha']) )return; |
|
| 222 | 222 | $this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' ); |
| 223 | 223 | $this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
| 224 | 224 | } |
@@ -228,9 +228,9 @@ discard block |
||
| 228 | 228 | */ |
| 229 | 229 | protected function validateRecaptcha() |
| 230 | 230 | { |
| 231 | - if( !empty( $this->error ))return; |
|
| 231 | + if( !empty($this->error) )return; |
|
| 232 | 232 | $status = $this->getRecaptchaStatus(); |
| 233 | - if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ))return; |
|
| 233 | + if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ) )return; |
|
| 234 | 234 | if( $status == static::RECAPTCHA_EMPTY ) { |
| 235 | 235 | $this->setSessionValues( 'recaptcha', 'unset' ); |
| 236 | 236 | $this->recaptchaIsUnset = true; |
@@ -250,11 +250,11 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | protected function validateRequest( array $request ) |
| 252 | 252 | { |
| 253 | - if( !$this->isRequestValid( $request )) { |
|
| 253 | + if( !$this->isRequestValid( $request ) ) { |
|
| 254 | 254 | $this->error = __( 'Please fix the submission errors.', 'site-reviews' ); |
| 255 | 255 | return $request; |
| 256 | 256 | } |
| 257 | - if( empty( $request['title'] )) { |
|
| 257 | + if( empty($request['title']) ) { |
|
| 258 | 258 | $request['title'] = __( 'No Title', 'site-reviews' ); |
| 259 | 259 | } |
| 260 | 260 | return array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request ); |
@@ -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 (consider adding the IP address to the blacklist):' ); |
| 181 | 185 | $this->error = __( 'This review has been flagged as possible spam and cannot be submitted.', '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; |