@@ -73,7 +73,7 @@ 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 ) )break; |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | return $this->errors; |
@@ -88,14 +88,14 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function validateAttribute( $attribute, $rule ) |
90 | 90 | { |
91 | - list( $rule, $parameters ) = $this->parseRule( $rule ); |
|
91 | + list($rule, $parameters) = $this->parseRule( $rule ); |
|
92 | 92 | if( $rule == '' )return; |
93 | 93 | $value = $this->getValue( $attribute ); |
94 | 94 | $this->validateRequired( $attribute, $value ) || in_array( $rule, $this->implicitRules ); |
95 | - if( !method_exists( $this, $method = 'validate'.$rule )) { |
|
95 | + if( !method_exists( $this, $method = 'validate'.$rule ) ) { |
|
96 | 96 | throw new BadMethodCallException( "Method [$method] does not exist." ); |
97 | 97 | } |
98 | - if( !$this->$method( $attribute, $value, $parameters )) { |
|
98 | + if( !$this->$method( $attribute, $value, $parameters ) ) { |
|
99 | 99 | $this->addFailure( $attribute, $rule, $parameters ); |
100 | 100 | } |
101 | 101 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | { |
111 | 111 | $message = $this->getMessage( $attribute, $rule, $parameters ); |
112 | 112 | $this->errors[$attribute]['errors'][] = $message; |
113 | - if( !isset( $this->errors[$attribute]['value'] )) { |
|
113 | + if( !isset($this->errors[$attribute]['value']) ) { |
|
114 | 114 | $this->errors[$attribute]['value'] = $this->getValue( $attribute ); |
115 | 115 | } |
116 | 116 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | */ |
148 | 148 | protected function getMessage( $attribute, $rule, array $parameters ) |
149 | 149 | { |
150 | - if( in_array( $rule, $this->sizeRules )) { |
|
150 | + if( in_array( $rule, $this->sizeRules ) ) { |
|
151 | 151 | return $this->getSizeMessage( $attribute, $rule, $parameters ); |
152 | 152 | } |
153 | 153 | $lowerRule = glsr( Helper::class )->snakeCase( $rule ); |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | */ |
163 | 163 | protected function getRule( $attribute, $rules ) |
164 | 164 | { |
165 | - if( !array_key_exists( $attribute, $this->rules ))return; |
|
166 | - $rules = (array) $rules; |
|
165 | + if( !array_key_exists( $attribute, $this->rules ) )return; |
|
166 | + $rules = (array)$rules; |
|
167 | 167 | foreach( $this->rules[$attribute] as $rule ) { |
168 | - list( $rule, $parameters ) = $this->parseRule( $rule ); |
|
169 | - if( in_array( $rule, $rules )) { |
|
168 | + list($rule, $parameters) = $this->parseRule( $rule ); |
|
169 | + if( in_array( $rule, $rules ) ) { |
|
170 | 170 | return [$rule, $parameters]; |
171 | 171 | } |
172 | 172 | } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | if( is_numeric( $value ) && $hasNumeric ) { |
185 | 185 | return $value; |
186 | 186 | } |
187 | - elseif( is_array( $value )) { |
|
187 | + elseif( is_array( $value ) ) { |
|
188 | 188 | return count( $value ); |
189 | 189 | } |
190 | 190 | return mb_strlen( $value ); |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | */ |
212 | 212 | protected function getValue( $attribute ) |
213 | 213 | { |
214 | - if( isset( $this->data[$attribute] )) { |
|
214 | + if( isset($this->data[$attribute]) ) { |
|
215 | 215 | return $this->data[$attribute]; |
216 | 216 | } |
217 | 217 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | */ |
225 | 225 | protected function hasRule( $attribute, $rules ) |
226 | 226 | { |
227 | - return !is_null( $this->getRule( $attribute, $rules )); |
|
227 | + return !is_null( $this->getRule( $attribute, $rules ) ); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -264,11 +264,11 @@ discard block |
||
264 | 264 | $parameters = []; |
265 | 265 | // example: {rule}:{parameters} |
266 | 266 | if( strpos( $rule, ':' ) !== false ) { |
267 | - list( $rule, $parameter ) = explode( ':', $rule, 2 ); |
|
267 | + list($rule, $parameter) = explode( ':', $rule, 2 ); |
|
268 | 268 | // example: {parameter1,parameter2,...} |
269 | 269 | $parameters = $this->parseParameters( $rule, $parameter ); |
270 | 270 | } |
271 | - $rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule ))); |
|
271 | + $rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule ) ) ); |
|
272 | 272 | $rule = str_replace( ' ', '', $rule ); |
273 | 273 | return [$rule, $parameters]; |
274 | 274 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | protected function shouldStopValidating( $attribute ) |
297 | 297 | { |
298 | 298 | return $this->hasRule( $attribute, $this->implicitRules ) |
299 | - && isset( $this->failedRules[$attribute] ) |
|
299 | + && isset($this->failedRules[$attribute]) |
|
300 | 300 | && array_intersect( array_keys( $this->failedRules[$attribute] ), $this->implicitRules ); |
301 | 301 | } |
302 | 302 | |
@@ -321,12 +321,12 @@ discard block |
||
321 | 321 | 'regex' => _x( 'The :attribute format is invalid.', ':attribute is a placeholder and should not be translated.', 'site-reviews' ), |
322 | 322 | 'required' => _x( 'The :attribute field is required.', ':attribute is a placeholder and should not be translated.', 'site-reviews' ), |
323 | 323 | ]; |
324 | - $message = isset( $strings[$key] ) |
|
324 | + $message = isset($strings[$key]) |
|
325 | 325 | ? $strings[$key] |
326 | 326 | : false; |
327 | 327 | if( !$message )return; |
328 | 328 | $message = str_replace( ':attribute', $attribute, $message ); |
329 | - if( method_exists( $this, $replacer = 'replace'.$rule )) { |
|
329 | + if( method_exists( $this, $replacer = 'replace'.$rule ) ) { |
|
330 | 330 | $message = $this->$replacer( $message, $parameters ); |
331 | 331 | } |
332 | 332 | return $message; |
@@ -31,7 +31,7 @@ |
||
31 | 31 | $diff = time() - strtotime( $date ); |
32 | 32 | foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
33 | 33 | if( $diff > $timePeriod[0] )continue; |
34 | - $unit = intval( floor( $diff / $timePeriod[1] )); |
|
34 | + $unit = intval( floor( $diff / $timePeriod[1] ) ); |
|
35 | 35 | $relativeDates = [ |
36 | 36 | _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
37 | 37 | _n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ), |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | |
34 | 34 | public function __construct() |
35 | 35 | { |
36 | - if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE )) { |
|
37 | - $cookie = explode( '||', stripslashes( $cookieId )); |
|
36 | + if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE ) ) { |
|
37 | + $cookie = explode( '||', stripslashes( $cookieId ) ); |
|
38 | 38 | $this->sessionId = preg_replace( '/[^A-Za-z0-9_]/', '', $cookie[0] ); |
39 | 39 | $this->expiryTimestamp = absint( $cookie[1] ); |
40 | 40 | $this->expiryTimestampReset = absint( $cookie[2] ); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | public function deleteExpiredSessions( $limit = 1000 ) |
79 | 79 | { |
80 | 80 | global $wpdb; |
81 | - if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ))) { |
|
81 | + if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ) ) ) { |
|
82 | 82 | $wpdb->query( |
83 | 83 | "DELETE FROM {$wpdb->options} WHERE option_name IN ('{$expiredSessions}')" |
84 | 84 | ); |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | public function get( $key, $fallback = '', $unset = false ) |
95 | 95 | { |
96 | 96 | $key = sanitize_key( $key ); |
97 | - $value = isset( $this->sessionData[$key] ) |
|
97 | + $value = isset($this->sessionData[$key]) |
|
98 | 98 | ? maybe_unserialize( $this->sessionData[$key] ) |
99 | 99 | : $fallback; |
100 | - if( isset( $this->sessionData[$key] ) && $unset ) { |
|
101 | - unset( $this->sessionData[$key] ); |
|
100 | + if( isset($this->sessionData[$key]) && $unset ) { |
|
101 | + unset($this->sessionData[$key]); |
|
102 | 102 | $this->updateSession(); |
103 | 103 | } |
104 | 104 | return $value; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | protected function deleteSession() |
133 | 133 | { |
134 | 134 | delete_option( $this->getSessionId() ); |
135 | - delete_option( $this->getSessionId( 'expires' )); |
|
135 | + delete_option( $this->getSessionId( 'expires' ) ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function generateSessionId() |
142 | 142 | { |
143 | - return md5(( new PasswordHash( 8, false ))->get_random_bytes( 32 )); |
|
143 | + return md5( (new PasswordHash( 8, false ))->get_random_bytes( 32 ) ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -152,13 +152,13 @@ discard block |
||
152 | 152 | global $wpdb; |
153 | 153 | $expiredSessions = []; |
154 | 154 | $sessions = $wpdb->get_results( |
155 | - "SELECT option_name AS name, option_value AS expiration " . |
|
156 | - "FROM {$wpdb->options} " . |
|
157 | - "WHERE option_name LIKE '".static::SESSION_COOKIE."_expires_%' " . |
|
158 | - "ORDER BY option_value ASC " . |
|
155 | + "SELECT option_name AS name, option_value AS expiration ". |
|
156 | + "FROM {$wpdb->options} ". |
|
157 | + "WHERE option_name LIKE '".static::SESSION_COOKIE."_expires_%' ". |
|
158 | + "ORDER BY option_value ASC ". |
|
159 | 159 | "LIMIT 0, ".absint( $limit ) |
160 | 160 | ); |
161 | - if( !empty( $sessions )) { |
|
161 | + if( !empty($sessions) ) { |
|
162 | 162 | $now = time(); |
163 | 163 | foreach( $sessions as $session ) { |
164 | 164 | if( $now <= $session->expiration )continue; |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | */ |
176 | 176 | protected function getSessionId( $separator = '' ) |
177 | 177 | { |
178 | - return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] )); |
|
178 | + return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] ) ); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | { |
207 | 207 | if( headers_sent() )return; |
208 | 208 | $cookie = $this->sessionId.'||'.$this->expiryTimestamp.'||'.$this->expiryTimestampReset; |
209 | - $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ))); |
|
209 | + $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ) ) ); |
|
210 | 210 | setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath ); |
211 | 211 | } |
212 | 212 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | */ |
225 | 225 | protected function updateSession() |
226 | 226 | { |
227 | - if( false === get_option( $this->getSessionId() )) { |
|
227 | + if( false === get_option( $this->getSessionId() ) ) { |
|
228 | 228 | $this->createSession(); |
229 | 229 | } |
230 | 230 | else { |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | natsort( $routines ); |
17 | 17 | array_walk( $routines, function( $routine ) { |
18 | 18 | $version = str_replace( strtolower( __CLASS__ ).'_', '', $routine ); |
19 | - if( version_compare( glsr()->version, $version, '>=' ))return; |
|
19 | + if( version_compare( glsr()->version, $version, '>=' ) )return; |
|
20 | 20 | call_user_func( [$this, $routine] ); |
21 | 21 | }); |
22 | 22 | $this->updateVersion(); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | public function updateVersion() |
29 | 29 | { |
30 | 30 | $currentVersion = glsr( OptionManager::class )->get( 'version' ); |
31 | - if( version_compare( $currentVersion, glsr()->version, '<' )) { |
|
31 | + if( version_compare( $currentVersion, glsr()->version, '<' ) ) { |
|
32 | 32 | glsr( OptionManager::class )->set( 'version', glsr()->version ); |
33 | 33 | } |
34 | 34 | if( $currentVersion != glsr()->version ) { |
@@ -57,7 +57,7 @@ |
||
57 | 57 | */ |
58 | 58 | protected function isReviewEditable() |
59 | 59 | { |
60 | - $postId = intval( filter_input( INPUT_GET, 'post' )); |
|
60 | + $postId = intval( filter_input( INPUT_GET, 'post' ) ); |
|
61 | 61 | return $postId > 0 |
62 | 62 | && get_post_meta( $postId, 'review_type', true ) == 'local' |
63 | 63 | && $this->isReviewEditor(); |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | $vars[] = Application::PAGED_QUERY_VAR; |
45 | 45 | // dirty hack to fix a form submission with a field that has "name" as name |
46 | 46 | if( filter_input( INPUT_POST, 'action' ) == 'submit-review' |
47 | - && !is_null( filter_input( INPUT_POST, 'gotcha' ))) { |
|
47 | + && !is_null( filter_input( INPUT_POST, 'gotcha' ) ) ) { |
|
48 | 48 | $index = array_search( 'name', $vars, true ); |
49 | 49 | if( false !== $index ) { |
50 | - unset( $vars[$index] ); |
|
50 | + unset($vars[$index]); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | return $vars; |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | public function routerCreateReview( array $request ) |
60 | 60 | { |
61 | 61 | $validated = glsr( ValidateReview::class )->validate( $request ); |
62 | - if( !empty( $validated->error )) { |
|
62 | + if( !empty($validated->error) ) { |
|
63 | 63 | return $validated->request; |
64 | 64 | } |
65 | 65 | if( $validated->recaptchaIsUnset )return; |
66 | - return $this->execute( new CreateReview( $validated->request )); |
|
66 | + return $this->execute( new CreateReview( $validated->request ) ); |
|
67 | 67 | } |
68 | 68 | } |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function validateRequest( array $request ) |
57 | 57 | { |
58 | - if( !$this->isRequestValid( $request )) { |
|
58 | + if( !$this->isRequestValid( $request ) ) { |
|
59 | 59 | $this->error = __( 'Please fix the submission errors.', 'site-reviews' ); |
60 | 60 | return $request; |
61 | 61 | } |
62 | - if( empty( $request['title'] )) { |
|
62 | + if( empty($request['title']) ) { |
|
63 | 63 | $request['title'] = __( 'No Title', 'site-reviews' ); |
64 | 64 | } |
65 | 65 | return array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request ); |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | $rules = array_intersect_key( |
74 | 74 | apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES ), |
75 | 75 | array_flip( array_merge( |
76 | - ['rating','terms'], |
|
76 | + ['rating', 'terms'], |
|
77 | 77 | glsr( OptionManager::class )->get( 'settings.submissions.required', [] ) |
78 | - )) |
|
78 | + ) ) |
|
79 | 79 | ); |
80 | - $excluded = isset( $request['excluded'] ) |
|
80 | + $excluded = isset($request['excluded']) |
|
81 | 81 | ? json_decode( $request['excluded'] ) |
82 | 82 | : []; |
83 | - return array_diff_key( $rules, array_flip( $excluded )); |
|
83 | + return array_diff_key( $rules, array_flip( $excluded ) ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -93,14 +93,14 @@ discard block |
||
93 | 93 | return true; |
94 | 94 | } |
95 | 95 | $recaptchaResponse = filter_input( INPUT_POST, 'g-recaptcha-response' ); |
96 | - if( empty( $recaptchaResponse )) { |
|
96 | + if( empty($recaptchaResponse) ) { |
|
97 | 97 | return null; //if response is empty we need to return null |
98 | 98 | } |
99 | 99 | if( $integration == 'custom' ) { |
100 | 100 | return $this->isRecaptchaValid( $recaptchaResponse ); |
101 | 101 | } |
102 | 102 | if( $integration == 'invisible-recaptcha' ) { |
103 | - return boolval( apply_filters( 'google_invre_is_valid_request_filter', true )); |
|
103 | + return boolval( apply_filters( 'google_invre_is_valid_request_filter', true ) ); |
|
104 | 104 | } |
105 | 105 | return false; |
106 | 106 | } |
@@ -110,17 +110,17 @@ discard block |
||
110 | 110 | */ |
111 | 111 | protected function isRecaptchaValid( $recaptchaResponse ) |
112 | 112 | { |
113 | - $endpoint = add_query_arg([ |
|
113 | + $endpoint = add_query_arg( [ |
|
114 | 114 | 'remoteip' => glsr( Helper::class )->getIpAddress(), |
115 | 115 | 'response' => $recaptchaResponse, |
116 | 116 | 'secret' => glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.secret' ), |
117 | 117 | ], 'https://www.google.com/recaptcha/api/siteverify' ); |
118 | - if( is_wp_error( $response = wp_remote_get( $endpoint ))) { |
|
118 | + if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) { |
|
119 | 119 | glsr_log()->error( $response->get_error_message() ); |
120 | 120 | return false; |
121 | 121 | } |
122 | - $response = json_decode( wp_remote_retrieve_body( $response )); |
|
123 | - if( !empty( $response->success )) { |
|
122 | + $response = json_decode( wp_remote_retrieve_body( $response ) ); |
|
123 | + if( !empty($response->success) ) { |
|
124 | 124 | return boolval( $response->success ); |
125 | 125 | } |
126 | 126 | $errorCodes = [ |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | { |
144 | 144 | $rules = $this->getValidationRules( $request ); |
145 | 145 | $errors = glsr( Validator::class )->validate( $request, $rules ); |
146 | - if( empty( $errors )) { |
|
146 | + if( empty($errors) ) { |
|
147 | 147 | return true; |
148 | 148 | } |
149 | 149 | $this->setSessionValues( 'errors', $errors ); |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | protected function setSessionValues( $type, $value, $loggedMessage = '' ) |
161 | 161 | { |
162 | 162 | glsr( Session::class )->set( $this->form_id.$type, $value ); |
163 | - if( !empty( $loggedMessage )) { |
|
163 | + if( !empty($loggedMessage) ) { |
|
164 | 164 | glsr_log()->warning( $loggedMessage ); |
165 | 165 | glsr_log()->warning( $this->request ); |
166 | 166 | } |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | */ |
172 | 172 | protected function validateAkismet() |
173 | 173 | { |
174 | - if( !empty( $this->error ))return; |
|
175 | - if( !glsr( Akismet::class )->isSpam( $this->request ))return; |
|
174 | + if( !empty($this->error) )return; |
|
175 | + if( !glsr( Akismet::class )->isSpam( $this->request ) )return; |
|
176 | 176 | $this->setSessionValues( 'errors', [], 'Akismet caught a spam submission:' ); |
177 | 177 | $this->error = __( 'Your review cannot be submitted at this time. Please try again later.', 'site-reviews' ); |
178 | 178 | } |
@@ -182,8 +182,8 @@ discard block |
||
182 | 182 | */ |
183 | 183 | protected function validateBlacklist() |
184 | 184 | { |
185 | - if( !empty( $this->error ))return; |
|
186 | - if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return; |
|
185 | + if( !empty($this->error) )return; |
|
186 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) )return; |
|
187 | 187 | $blacklistAction = glsr( OptionManager::class )->get( 'settings.submissions.blacklist.action' ); |
188 | 188 | if( $blacklistAction == 'unapprove' ) { |
189 | 189 | $this->request['blacklisted'] = true; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | protected function validateCustom() |
201 | 201 | { |
202 | - if( !empty( $this->error ))return; |
|
202 | + if( !empty($this->error) )return; |
|
203 | 203 | $validated = apply_filters( 'site-reviews/validate/review/submission', true, $this->request ); |
204 | 204 | if( $validated === true )return; |
205 | 205 | $this->setSessionValues( 'errors', [] ); |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | */ |
215 | 215 | protected function validateHoneyPot() |
216 | 216 | { |
217 | - if( !empty( $this->error ))return; |
|
218 | - if( empty( $this->request['gotcha'] ))return; |
|
217 | + if( !empty($this->error) )return; |
|
218 | + if( empty($this->request['gotcha']) )return; |
|
219 | 219 | $this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' ); |
220 | 220 | $this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
221 | 221 | } |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | */ |
226 | 226 | protected function validateRecaptcha() |
227 | 227 | { |
228 | - if( !empty( $this->error ))return; |
|
228 | + if( !empty($this->error) )return; |
|
229 | 229 | $isValid = $this->isRecaptchaResponseValid(); |
230 | - if( is_null( $isValid )) { |
|
230 | + if( is_null( $isValid ) ) { |
|
231 | 231 | $this->setSessionValues( 'recaptcha', true ); |
232 | 232 | $this->recaptchaIsUnset = true; |
233 | 233 | } |
@@ -12,14 +12,14 @@ discard block |
||
12 | 12 | */ |
13 | 13 | public function isBlacklisted( CreateReview $review ) |
14 | 14 | { |
15 | - $target = implode( "\n", array_filter([ |
|
15 | + $target = implode( "\n", array_filter( [ |
|
16 | 16 | $review->author, |
17 | 17 | $review->content, |
18 | 18 | $review->email, |
19 | 19 | $review->ipAddress, |
20 | 20 | $review->title, |
21 | - ])); |
|
22 | - return (bool) apply_filters( 'site-reviews/blacklist/is-blacklisted', |
|
21 | + ] ) ); |
|
22 | + return (bool)apply_filters( 'site-reviews/blacklist/is-blacklisted', |
|
23 | 23 | $this->check( $target ), |
24 | 24 | $review |
25 | 25 | ); |
@@ -31,16 +31,16 @@ discard block |
||
31 | 31 | */ |
32 | 32 | protected function check( $target ) |
33 | 33 | { |
34 | - $blacklist = trim( glsr( OptionManager::class )->get( 'settings.submissions.blacklist.entries' )); |
|
35 | - if( empty( $blacklist )) { |
|
34 | + $blacklist = trim( glsr( OptionManager::class )->get( 'settings.submissions.blacklist.entries' ) ); |
|
35 | + if( empty($blacklist) ) { |
|
36 | 36 | return false; |
37 | 37 | } |
38 | 38 | $lines = explode( "\n", $blacklist ); |
39 | - foreach( (array) $lines as $line ) { |
|
39 | + foreach( (array)$lines as $line ) { |
|
40 | 40 | $line = trim( $line ); |
41 | - if( empty( $line ) || 256 < strlen( $line ))continue; |
|
42 | - $pattern = sprintf( '#%s#i', preg_quote( $line, '#' )); |
|
43 | - if( preg_match( $pattern, $target )) { |
|
41 | + if( empty($line) || 256 < strlen( $line ) )continue; |
|
42 | + $pattern = sprintf( '#%s#i', preg_quote( $line, '#' ) ); |
|
43 | + if( preg_match( $pattern, $target ) ) { |
|
44 | 44 | return true; |
45 | 45 | } |
46 | 46 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | protected function createWebhookNotification( Command $command, array $args ) |
64 | 64 | { |
65 | 65 | $fields = []; |
66 | - $fields[] = ['title' => str_repeat( ':star:', (int) $command->rating )]; |
|
66 | + $fields[] = ['title' => str_repeat( ':star:', (int)$command->rating )]; |
|
67 | 67 | if( $command->title ) { |
68 | 68 | $fields[] = ['title' => $command->title]; |
69 | 69 | } |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | if( $command->author ) { |
77 | 77 | $fields[] = ['value' => trim( $command->author.$command->email.' - '.$command->ipAddress )]; |
78 | 78 | } |
79 | - $fields[] = ['value' => sprintf( '<%s|%s>', $args['notification_link'], __( 'View Review', 'site-reviews' ))]; |
|
80 | - return json_encode([ |
|
79 | + $fields[] = ['value' => sprintf( '<%s|%s>', $args['notification_link'], __( 'View Review', 'site-reviews' ) )]; |
|
80 | + return json_encode( [ |
|
81 | 81 | 'icon_url' => glsr()->url.'assets/img/icon.png', |
82 | 82 | 'username' => glsr()->name, |
83 | 83 | 'attachments' => [[ |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | 'fallback' => $this->createEmailNotification( $command, $args )->read( 'plaintext' ), |
87 | 87 | 'fields' => $fields, |
88 | 88 | ]], |
89 | - ]); |
|
89 | + ] ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | protected function sendNotification( $post_id, Command $command ) |
116 | 116 | { |
117 | 117 | $notificationType = glsr( OptionManager::class )->get( 'settings.general.notification' ); |
118 | - if( !in_array( $notificationType, ['default','custom','webhook'] ))return; |
|
119 | - $assignedToTitle = get_the_title( (int) $command->assignedTo ); |
|
118 | + if( !in_array( $notificationType, ['default', 'custom', 'webhook'] ) )return; |
|
119 | + $assignedToTitle = get_the_title( (int)$command->assignedTo ); |
|
120 | 120 | $notificationSubject = _nx( |
121 | 121 | 'New %s-star review', |
122 | 122 | 'New %s-star review of: %s', |
123 | - (int) empty( $assignedToTitle ), |
|
123 | + (int)empty($assignedToTitle), |
|
124 | 124 | 'The text is different depending on whether or not the review has been assigned to a post.', |
125 | 125 | 'site-reviews' |
126 | 126 | ); |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | sprintf( $notificationSubject, $command->rating, $assignedToTitle ) |
130 | 130 | ); |
131 | 131 | $args = [ |
132 | - 'notification_link' => esc_url( admin_url( sprintf( 'post.php?post=%s&action=edit', $post_id ))), |
|
132 | + 'notification_link' => esc_url( admin_url( sprintf( 'post.php?post=%s&action=edit', $post_id ) ) ), |
|
133 | 133 | 'notification_title' => $notificationTitle, |
134 | 134 | 'notification_type' => $notificationType, |
135 | 135 | ]; |
@@ -147,14 +147,14 @@ discard block |
||
147 | 147 | $args['recipient'] = $args['notification_type'] === 'default' |
148 | 148 | ? get_option( 'admin_email' ) |
149 | 149 | : glsr( OptionManager::class )->get( 'settings.general.notification_email' ); |
150 | - $result = !empty( $args['recipient'] ) |
|
150 | + $result = !empty($args['recipient']) |
|
151 | 151 | ? $this->createEmailNotification( $command, $args )->send() |
152 | 152 | : false; |
153 | - if( !is_bool( $result )) { |
|
154 | - glsr_log()->error( __( 'Email notification was not sent: missing email, subject, or message.', 'site-reviews' )); |
|
153 | + if( !is_bool( $result ) ) { |
|
154 | + glsr_log()->error( __( 'Email notification was not sent: missing email, subject, or message.', 'site-reviews' ) ); |
|
155 | 155 | } |
156 | 156 | if( $result === false ) { |
157 | - glsr_log()->error( __( 'Email notification was not sent: wp_mail() failed.', 'site-reviews' )); |
|
157 | + glsr_log()->error( __( 'Email notification was not sent: wp_mail() failed.', 'site-reviews' ) ); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | protected function sendWebhookNotification( Command $command, array $args ) |
165 | 165 | { |
166 | - if( !( $endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' )))return; |
|
166 | + if( !($endpoint = glsr( OptionManager::class )->get( 'settings.general.webhook_url' )) )return; |
|
167 | 167 | $notification = $this->createWebhookNotification( $command, $args ); |
168 | 168 | $result = wp_remote_post( $endpoint, [ |
169 | 169 | 'method' => 'POST', |
@@ -174,8 +174,8 @@ discard block |
||
174 | 174 | 'sslverify' => false, |
175 | 175 | 'headers' => ['Content-Type' => 'application/json'], |
176 | 176 | 'body' => apply_filters( 'site-reviews/webhook/notification', $notification, $command ), |
177 | - ]); |
|
178 | - if( is_wp_error( $result )) { |
|
177 | + ] ); |
|
178 | + if( is_wp_error( $result ) ) { |
|
179 | 179 | glsr_log()->error( $result->get_error_message() ); |
180 | 180 | } |
181 | 181 | } |