@@ -15,9 +15,13 @@ |
||
| 15 | 15 | ]; |
| 16 | 16 | foreach( $namespaces as $prefix => $baseDir ) { |
| 17 | 17 | $len = strlen( $prefix ); |
| 18 | - if( strncmp( $prefix, $className, $len ) !== 0 )continue; |
|
| 18 | + if( strncmp( $prefix, $className, $len ) !== 0 ) { |
|
| 19 | + continue; |
|
| 20 | + } |
|
| 19 | 21 | $file = $baseDir.str_replace( '\\', '/', substr( $className, $len )).'.php'; |
| 20 | - if( !file_exists( $file ))continue; |
|
| 22 | + if( !file_exists( $file )) { |
|
| 23 | + continue; |
|
| 24 | + } |
|
| 21 | 25 | require $file; |
| 22 | 26 | break; |
| 23 | 27 | } |
@@ -64,7 +64,9 @@ discard block |
||
| 64 | 64 | public function getAssignedToPost( $post, $assignedTo = '' ) |
| 65 | 65 | { |
| 66 | 66 | $post = get_post( $post ); |
| 67 | - if( !( $post instanceof WP_Post ))return; |
|
| 67 | + if( !( $post instanceof WP_Post )) { |
|
| 68 | + return; |
|
| 69 | + } |
|
| 68 | 70 | if( empty( $assignedTo )) { |
| 69 | 71 | $assignedTo = get_post_meta( $post->ID, 'assigned_to', true ); |
| 70 | 72 | } |
@@ -82,7 +84,9 @@ discard block |
||
| 82 | 84 | */ |
| 83 | 85 | public function getReview( $post ) |
| 84 | 86 | { |
| 85 | - if( !( $post instanceof WP_Post ) || $post->post_type != Application::POST_TYPE )return; |
|
| 87 | + if( !( $post instanceof WP_Post ) || $post->post_type != Application::POST_TYPE ) { |
|
| 88 | + return; |
|
| 89 | + } |
|
| 86 | 90 | $review = $this->getReviewMeta( $post->ID ); |
| 87 | 91 | $modified = $this->isReviewModified( $post, $review ); |
| 88 | 92 | $review->content = $post->post_content; |
@@ -256,7 +260,9 @@ discard block |
||
| 256 | 260 | $termIds = array_map( 'trim', explode( ',', $termIds )); |
| 257 | 261 | foreach( $termIds as $termId ) { |
| 258 | 262 | $term = term_exists( $termId, Application::TAXONOMY ); |
| 259 | - if( !isset( $term['term_id'] ))continue; |
|
| 263 | + if( !isset( $term['term_id'] )) { |
|
| 264 | + continue; |
|
| 265 | + } |
|
| 260 | 266 | $terms[] = intval( $term['term_id'] ); |
| 261 | 267 | } |
| 262 | 268 | return $terms; |
@@ -269,7 +275,9 @@ discard block |
||
| 269 | 275 | public function revertReview( $postId ) |
| 270 | 276 | { |
| 271 | 277 | $post = get_post( $postId ); |
| 272 | - if( !( $post instanceof WP_Post ) || $post->post_type != Application::POST_TYPE )return; |
|
| 278 | + if( !( $post instanceof WP_Post ) || $post->post_type != Application::POST_TYPE ) { |
|
| 279 | + return; |
|
| 280 | + } |
|
| 273 | 281 | delete_post_meta( $post->ID, '_edit_last' ); |
| 274 | 282 | $result = wp_update_post([ |
| 275 | 283 | 'ID' => $post->ID, |
@@ -304,7 +312,9 @@ discard block |
||
| 304 | 312 | add_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2 ); |
| 305 | 313 | $search = new WP_Query( $args ); |
| 306 | 314 | remove_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500 ); |
| 307 | - if( !$search->have_posts() )return; |
|
| 315 | + if( !$search->have_posts() ) { |
|
| 316 | + return; |
|
| 317 | + } |
|
| 308 | 318 | $results = ''; |
| 309 | 319 | while( $search->have_posts() ) { |
| 310 | 320 | $search->the_post(); |
@@ -331,7 +341,9 @@ discard block |
||
| 331 | 341 | update_post_meta( $postId, $metaKey, $metaValue ); |
| 332 | 342 | } |
| 333 | 343 | $terms = $this->normalizeTerms( $termIds ); |
| 334 | - if( empty( $terms ))return; |
|
| 344 | + if( empty( $terms )) { |
|
| 345 | + return; |
|
| 346 | + } |
|
| 335 | 347 | $result = wp_set_object_terms( $postId, $terms, Application::TAXONOMY ); |
| 336 | 348 | if( is_wp_error( $result )) { |
| 337 | 349 | glsr_log()->error( $result->get_error_message() ); |
@@ -50,7 +50,9 @@ |
||
| 50 | 50 | public function routerSubmitReview( array $request ) |
| 51 | 51 | { |
| 52 | 52 | $validated = glsr( ValidateReview::class )->validate( $request ); |
| 53 | - if( !empty( $validated->error ) || $validated->recaptchaIsUnset )return; |
|
| 53 | + if( !empty( $validated->error ) || $validated->recaptchaIsUnset ) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 54 | 56 | $this->execute( new CreateReview( $validated->request )); |
| 55 | 57 | } |
| 56 | 58 | } |
@@ -19,7 +19,9 @@ |
||
| 19 | 19 | public function build( array $args = [] ) |
| 20 | 20 | { |
| 21 | 21 | $this->errors = $args['errors']; |
| 22 | - if( empty( $args['message'] ))return; |
|
| 22 | + if( empty( $args['message'] )) { |
|
| 23 | + return; |
|
| 24 | + } |
|
| 23 | 25 | return glsr( Builder::class )->div( wpautop( $args['message'] ), [ |
| 24 | 26 | 'class' => $this->getClass(), |
| 25 | 27 | ]); |
@@ -152,7 +152,9 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | protected function normalizeFieldErrors( Field &$field ) |
| 154 | 154 | { |
| 155 | - if( !array_key_exists( $field->field['path'], $this->errors ))return; |
|
| 155 | + if( !array_key_exists( $field->field['path'], $this->errors )) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 156 | 158 | $field->field['errors'] = $this->errors[$field->field['path']]; |
| 157 | 159 | } |
| 158 | 160 | |
@@ -161,7 +163,9 @@ discard block |
||
| 161 | 163 | */ |
| 162 | 164 | protected function normalizeFieldRequired( Field &$field ) |
| 163 | 165 | { |
| 164 | - if( !in_array( $field->field['path'], $this->required ))return; |
|
| 166 | + if( !in_array( $field->field['path'], $this->required )) { |
|
| 167 | + return; |
|
| 168 | + } |
|
| 165 | 169 | $field->field['required'] = true; |
| 166 | 170 | } |
| 167 | 171 | |
@@ -183,7 +187,9 @@ discard block |
||
| 183 | 187 | */ |
| 184 | 188 | protected function normalizeFieldValue( Field &$field ) |
| 185 | 189 | { |
| 186 | - if( !array_key_exists( $field->field['path'], $this->values ))return; |
|
| 190 | + if( !array_key_exists( $field->field['path'], $this->values )) { |
|
| 191 | + return; |
|
| 192 | + } |
|
| 187 | 193 | if( in_array( $field->field['type'], ['radio', 'checkbox'] )) { |
| 188 | 194 | $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
| 189 | 195 | } |
@@ -43,7 +43,9 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function build() |
| 45 | 45 | { |
| 46 | - if( !$this->field['is_valid'] )return; |
|
| 46 | + if( !$this->field['is_valid'] ) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 47 | 49 | if( $this->field['is_raw'] ) { |
| 48 | 50 | return glsr( Builder::class )->{$this->field['type']}( $this->field ); |
| 49 | 51 | } |
@@ -143,7 +145,9 @@ discard block |
||
| 143 | 145 | */ |
| 144 | 146 | protected function getFieldErrors() |
| 145 | 147 | { |
| 146 | - if( empty( $this->field['errors'] ) || !is_array( $this->field['errors'] ))return; |
|
| 148 | + if( empty( $this->field['errors'] ) || !is_array( $this->field['errors'] )) { |
|
| 149 | + return; |
|
| 150 | + } |
|
| 147 | 151 | $errors = array_reduce( $this->field['errors'], function( $carry, $error ) { |
| 148 | 152 | return $carry.glsr( Builder::class )->span( $error, ['class' => 'glsr-field-error'] ); |
| 149 | 153 | }); |
@@ -170,7 +174,9 @@ discard block |
||
| 170 | 174 | 'name', 'type', |
| 171 | 175 | ]; |
| 172 | 176 | foreach( $requiredValues as $value ) { |
| 173 | - if( isset( $this->field[$value] ))continue; |
|
| 177 | + if( isset( $this->field[$value] )) { |
|
| 178 | + continue; |
|
| 179 | + } |
|
| 174 | 180 | $missingValues[] = $value; |
| 175 | 181 | $this->field['is_valid'] = false; |
| 176 | 182 | } |
@@ -187,7 +193,9 @@ discard block |
||
| 187 | 193 | */ |
| 188 | 194 | protected function normalize() |
| 189 | 195 | { |
| 190 | - if( !$this->isFieldValid() )return; |
|
| 196 | + if( !$this->isFieldValid() ) { |
|
| 197 | + return; |
|
| 198 | + } |
|
| 191 | 199 | $this->field['path'] = $this->field['name']; |
| 192 | 200 | $className = glsr( Helper::class )->buildClassName( $this->field['type'], __NAMESPACE__.'\Fields' ); |
| 193 | 201 | if( class_exists( $className )) { |
@@ -205,7 +213,9 @@ discard block |
||
| 205 | 213 | */ |
| 206 | 214 | protected function normalizeFieldId() |
| 207 | 215 | { |
| 208 | - if( isset( $this->field['id'] ) || $this->field['is_raw'] )return; |
|
| 216 | + if( isset( $this->field['id'] ) || $this->field['is_raw'] ) { |
|
| 217 | + return; |
|
| 218 | + } |
|
| 209 | 219 | $this->field['id'] = glsr( Helper::class )->convertPathToId( |
| 210 | 220 | $this->field['path'], |
| 211 | 221 | $this->getFieldPrefix() |
@@ -73,7 +73,9 @@ discard block |
||
| 73 | 73 | foreach( $this->rules as $attribute => $rules ) { |
| 74 | 74 | foreach( $rules as $rule ) { |
| 75 | 75 | $this->validateAttribute( $attribute, $rule ); |
| 76 | - if( $this->shouldStopValidating( $attribute ))break; |
|
| 76 | + if( $this->shouldStopValidating( $attribute )) { |
|
| 77 | + break; |
|
| 78 | + } |
|
| 77 | 79 | } |
| 78 | 80 | } |
| 79 | 81 | return $this->errors; |
@@ -89,7 +91,9 @@ discard block |
||
| 89 | 91 | public function validateAttribute( $attribute, $rule ) |
| 90 | 92 | { |
| 91 | 93 | list( $rule, $parameters ) = $this->parseRule( $rule ); |
| 92 | - if( $rule == '' )return; |
|
| 94 | + if( $rule == '' ) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 93 | 97 | $value = $this->getValue( $attribute ); |
| 94 | 98 | if( !method_exists( $this, $method = 'validate'.$rule )) { |
| 95 | 99 | throw new BadMethodCallException( "Method [$method] does not exist." ); |
@@ -158,7 +162,9 @@ discard block |
||
| 158 | 162 | */ |
| 159 | 163 | protected function getRule( $attribute, $rules ) |
| 160 | 164 | { |
| 161 | - if( !array_key_exists( $attribute, $this->rules ))return; |
|
| 165 | + if( !array_key_exists( $attribute, $this->rules )) { |
|
| 166 | + return; |
|
| 167 | + } |
|
| 162 | 168 | $rules = (array) $rules; |
| 163 | 169 | foreach( $this->rules[$attribute] as $rule ) { |
| 164 | 170 | list( $rule, $parameters ) = $this->parseRule( $rule ); |
@@ -318,7 +324,9 @@ discard block |
||
| 318 | 324 | $message = isset( $strings[$key] ) |
| 319 | 325 | ? $strings[$key] |
| 320 | 326 | : false; |
| 321 | - if( !$message )return; |
|
| 327 | + if( !$message ) { |
|
| 328 | + return; |
|
| 329 | + } |
|
| 322 | 330 | if( method_exists( $this, $method = 'replace'.$rule )) { |
| 323 | 331 | $message = $this->$method( $message, $parameters ); |
| 324 | 332 | } |
@@ -102,7 +102,9 @@ discard block |
||
| 102 | 102 | protected function sendNotification( $postId ) |
| 103 | 103 | { |
| 104 | 104 | $notificationType = glsr( OptionManager::class )->get( 'settings.general.notification' ); |
| 105 | - if( !in_array( $notificationType, ['default','custom','webhook'] ))return; |
|
| 105 | + if( !in_array( $notificationType, ['default','custom','webhook'] )) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 106 | 108 | $assignedToTitle = get_the_title( (int)$this->command->assigned_to ); |
| 107 | 109 | $notificationSubject = _nx( |
| 108 | 110 | 'New %s-star review', |
@@ -150,7 +152,9 @@ discard block |
||
| 150 | 152 | */ |
| 151 | 153 | protected function sendWebhookNotification( array $args ) |
| 152 | 154 | { |
| 153 | - if( !( $endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' )))return; |
|
| 155 | + if( !( $endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' ))) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 154 | 158 | $notification = $this->createWebhookNotification( $args ); |
| 155 | 159 | $result = wp_remote_post( $endpoint, [ |
| 156 | 160 | 'blocking' => false, |
@@ -193,8 +193,12 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | protected function validateAkismet() |
| 195 | 195 | { |
| 196 | - if( !empty( $this->error ))return; |
|
| 197 | - if( !glsr( Akismet::class )->isSpam( $this->request ))return; |
|
| 196 | + if( !empty( $this->error )) { |
|
| 197 | + return; |
|
| 198 | + } |
|
| 199 | + if( !glsr( Akismet::class )->isSpam( $this->request )) { |
|
| 200 | + return; |
|
| 201 | + } |
|
| 198 | 202 | $this->setSessionValues( 'errors', [], 'Akismet caught a spam submission:' ); |
| 199 | 203 | $this->error = __( 'Your review cannot be submitted at this time. Please try again later.', 'site-reviews' ); |
| 200 | 204 | } |
@@ -204,8 +208,12 @@ discard block |
||
| 204 | 208 | */ |
| 205 | 209 | protected function validateBlacklist() |
| 206 | 210 | { |
| 207 | - if( !empty( $this->error ))return; |
|
| 208 | - if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return; |
|
| 211 | + if( !empty( $this->error )) { |
|
| 212 | + return; |
|
| 213 | + } |
|
| 214 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request )) { |
|
| 215 | + return; |
|
| 216 | + } |
|
| 209 | 217 | $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
| 210 | 218 | if( $blacklistAction == 'reject' ) { |
| 211 | 219 | $this->setSessionValues( 'errors', [], 'Blacklisted submission detected:' ); |
@@ -220,9 +228,13 @@ discard block |
||
| 220 | 228 | */ |
| 221 | 229 | protected function validateCustom() |
| 222 | 230 | { |
| 223 | - if( !empty( $this->error ))return; |
|
| 231 | + if( !empty( $this->error )) { |
|
| 232 | + return; |
|
| 233 | + } |
|
| 224 | 234 | $validated = apply_filters( 'site-reviews/validate/review/submission', true, $this->request ); |
| 225 | - if( $validated === true )return; |
|
| 235 | + if( $validated === true ) { |
|
| 236 | + return; |
|
| 237 | + } |
|
| 226 | 238 | $this->setSessionValues( 'errors', [] ); |
| 227 | 239 | $this->setSessionValues( 'values', $this->request ); |
| 228 | 240 | $this->error = is_string( $validated ) |
@@ -235,8 +247,12 @@ discard block |
||
| 235 | 247 | */ |
| 236 | 248 | protected function validateHoneyPot() |
| 237 | 249 | { |
| 238 | - if( !empty( $this->error ))return; |
|
| 239 | - if( empty( $this->request['gotcha'] ))return; |
|
| 250 | + if( !empty( $this->error )) { |
|
| 251 | + return; |
|
| 252 | + } |
|
| 253 | + if( empty( $this->request['gotcha'] )) { |
|
| 254 | + return; |
|
| 255 | + } |
|
| 240 | 256 | $this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' ); |
| 241 | 257 | $this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
| 242 | 258 | } |
@@ -246,7 +262,9 @@ discard block |
||
| 246 | 262 | */ |
| 247 | 263 | protected function validateRecaptcha() |
| 248 | 264 | { |
| 249 | - if( !empty( $this->error ))return; |
|
| 265 | + if( !empty( $this->error )) { |
|
| 266 | + return; |
|
| 267 | + } |
|
| 250 | 268 | $isValid = $this->isRecaptchaResponseValid(); |
| 251 | 269 | if( is_null( $isValid )) { |
| 252 | 270 | $this->setSessionValues( 'recaptcha', true ); |