@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | |
11 | 11 | class Console |
12 | 12 | { |
13 | - const DEBUG = 0; // Detailed debug information |
|
14 | - const INFO = 1; // Interesting events |
|
15 | - const NOTICE = 2; // Normal but significant events |
|
16 | - const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | - const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | - const CRITICAL = 16; // Critical conditions |
|
19 | - const ALERT = 32; // Action must be taken immediately |
|
13 | + const DEBUG = 0; // Detailed debug information |
|
14 | + const INFO = 1; // Interesting events |
|
15 | + const NOTICE = 2; // Normal but significant events |
|
16 | + const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | + const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | + const CRITICAL = 16; // Critical conditions |
|
19 | + const ALERT = 32; // Action must be taken immediately |
|
20 | 20 | const EMERGENCY = 64; // System is unusable |
21 | 21 | |
22 | 22 | protected $file; |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | |
26 | 26 | public function __construct() |
27 | 27 | { |
28 | - $this->file = glsr()->path('console.log'); |
|
29 | - $this->log = file_exists($this->file) |
|
30 | - ? file_get_contents($this->file) |
|
28 | + $this->file = glsr()->path( 'console.log' ); |
|
29 | + $this->log = file_exists( $this->file ) |
|
30 | + ? file_get_contents( $this->file ) |
|
31 | 31 | : ''; |
32 | 32 | $this->reset(); |
33 | 33 | } |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * @param array $context |
48 | 48 | * @return static |
49 | 49 | */ |
50 | - public function alert($message, array $context = []) |
|
50 | + public function alert( $message, array $context = [] ) |
|
51 | 51 | { |
52 | - return $this->log(static::ALERT, $message, $context); |
|
52 | + return $this->log( static::ALERT, $message, $context ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public function clear() |
59 | 59 | { |
60 | 60 | $this->log = ''; |
61 | - file_put_contents($this->file, $this->log); |
|
61 | + file_put_contents( $this->file, $this->log ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * @param array $context |
69 | 69 | * @return static |
70 | 70 | */ |
71 | - public function critical($message, array $context = []) |
|
71 | + public function critical( $message, array $context = [] ) |
|
72 | 72 | { |
73 | - return $this->log(static::CRITICAL, $message, $context); |
|
73 | + return $this->log( static::CRITICAL, $message, $context ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | * @param array $context |
80 | 80 | * @return static |
81 | 81 | */ |
82 | - public function debug($message, array $context = []) |
|
82 | + public function debug( $message, array $context = [] ) |
|
83 | 83 | { |
84 | - return $this->log(static::DEBUG, $message, $context); |
|
84 | + return $this->log( static::DEBUG, $message, $context ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | * @param array $context |
91 | 91 | * @return static |
92 | 92 | */ |
93 | - public function emergency($message, array $context = []) |
|
93 | + public function emergency( $message, array $context = [] ) |
|
94 | 94 | { |
95 | - return $this->log(static::EMERGENCY, $message, $context); |
|
95 | + return $this->log( static::EMERGENCY, $message, $context ); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param array $context |
102 | 102 | * @return static |
103 | 103 | */ |
104 | - public function error($message, array $context = []) |
|
104 | + public function error( $message, array $context = [] ) |
|
105 | 105 | { |
106 | - return $this->log(static::ERROR, $message, $context); |
|
106 | + return $this->log( static::ERROR, $message, $context ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | public function get() |
113 | 113 | { |
114 | 114 | return empty($this->log) |
115 | - ? __('Console is empty', 'site-reviews') |
|
115 | + ? __( 'Console is empty', 'site-reviews' ) |
|
116 | 116 | : $this->log; |
117 | 117 | } |
118 | 118 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function getLevel() |
123 | 123 | { |
124 | - return intval(apply_filters('site-reviews/console/level', static::INFO)); |
|
124 | + return intval( apply_filters( 'site-reviews/console/level', static::INFO ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function getLevels() |
131 | 131 | { |
132 | - $constants = (new ReflectionClass(__CLASS__))->getConstants(); |
|
133 | - return array_map('strtolower', array_flip($constants)); |
|
132 | + $constants = (new ReflectionClass( __CLASS__ ))->getConstants(); |
|
133 | + return array_map( 'strtolower', array_flip( $constants ) ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,21 +139,21 @@ discard block |
||
139 | 139 | public function humanLevel() |
140 | 140 | { |
141 | 141 | $level = $this->getLevel(); |
142 | - return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level); |
|
142 | + return sprintf( '%s (%d)', strtoupper( Arr::get( $this->getLevels(), $level, 'unknown' ) ), $level ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | 146 | * @param string|null $valueIfEmpty |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - public function humanSize($valueIfEmpty = null) |
|
149 | + public function humanSize( $valueIfEmpty = null ) |
|
150 | 150 | { |
151 | 151 | $bytes = $this->size(); |
152 | - if (empty($bytes) && is_string($valueIfEmpty)) { |
|
152 | + if( empty($bytes) && is_string( $valueIfEmpty ) ) { |
|
153 | 153 | return $valueIfEmpty; |
154 | 154 | } |
155 | - $exponent = floor(log(max($bytes, 1), 1024)); |
|
156 | - return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
155 | + $exponent = floor( log( max( $bytes, 1 ), 1024 ) ); |
|
156 | + return round( $bytes / pow( 1024, $exponent ), 2 ).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * @param array $context |
164 | 164 | * @return static |
165 | 165 | */ |
166 | - public function info($message, array $context = []) |
|
166 | + public function info( $message, array $context = [] ) |
|
167 | 167 | { |
168 | - return $this->log(static::INFO, $message, $context); |
|
168 | + return $this->log( static::INFO, $message, $context ); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -175,19 +175,19 @@ discard block |
||
175 | 175 | * @param string $backtraceLine |
176 | 176 | * @return static |
177 | 177 | */ |
178 | - public function log($level, $message, $context = [], $backtraceLine = '') |
|
178 | + public function log( $level, $message, $context = [], $backtraceLine = '' ) |
|
179 | 179 | { |
180 | - if (empty($backtraceLine)) { |
|
180 | + if( empty($backtraceLine) ) { |
|
181 | 181 | $backtraceLine = $this->getBacktraceLine(); |
182 | 182 | } |
183 | - if ($this->canLogEntry($level, $backtraceLine)) { |
|
184 | - $levelName = Arr::get($this->getLevels(), $level); |
|
185 | - $context = Arr::consolidateArray($context); |
|
186 | - $backtraceLine = $this->normalizeBacktraceLine($backtraceLine); |
|
187 | - $message = $this->interpolate($message, $context); |
|
188 | - $entry = $this->buildLogEntry($levelName, $message, $backtraceLine); |
|
189 | - file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX); |
|
190 | - apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed |
|
183 | + if( $this->canLogEntry( $level, $backtraceLine ) ) { |
|
184 | + $levelName = Arr::get( $this->getLevels(), $level ); |
|
185 | + $context = Arr::consolidateArray( $context ); |
|
186 | + $backtraceLine = $this->normalizeBacktraceLine( $backtraceLine ); |
|
187 | + $message = $this->interpolate( $message, $context ); |
|
188 | + $entry = $this->buildLogEntry( $levelName, $message, $backtraceLine ); |
|
189 | + file_put_contents( $this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX ); |
|
190 | + apply_filters( 'console', $message, $levelName, $backtraceLine ); // Show in Blackbar plugin if installed |
|
191 | 191 | $this->reset(); |
192 | 192 | } |
193 | 193 | return $this; |
@@ -198,17 +198,17 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function logOnce() |
200 | 200 | { |
201 | - $once = Arr::consolidateArray(glsr()->{$this->logOnceKey}); |
|
201 | + $once = Arr::consolidateArray( glsr()->{$this->logOnceKey}); |
|
202 | 202 | $levels = $this->getLevels(); |
203 | - foreach ($once as $entry) { |
|
204 | - $levelName = Arr::get($entry, 'level'); |
|
205 | - if (!in_array($levelName, $levels)) { |
|
203 | + foreach( $once as $entry ) { |
|
204 | + $levelName = Arr::get( $entry, 'level' ); |
|
205 | + if( !in_array( $levelName, $levels ) ) { |
|
206 | 206 | continue; |
207 | 207 | } |
208 | - $level = Arr::get(array_flip($levels), $levelName); |
|
209 | - $message = Arr::get($entry, 'message'); |
|
210 | - $backtraceLine = Arr::get($entry, 'backtrace'); |
|
211 | - $this->log($level, $message, [], $backtraceLine); |
|
208 | + $level = Arr::get( array_flip( $levels ), $levelName ); |
|
209 | + $message = Arr::get( $entry, 'message' ); |
|
210 | + $backtraceLine = Arr::get( $entry, 'backtrace' ); |
|
211 | + $this->log( $level, $message, [], $backtraceLine ); |
|
212 | 212 | } |
213 | 213 | glsr()->{$this->logOnceKey} = []; |
214 | 214 | } |
@@ -219,9 +219,9 @@ discard block |
||
219 | 219 | * @param array $context |
220 | 220 | * @return static |
221 | 221 | */ |
222 | - public function notice($message, array $context = []) |
|
222 | + public function notice( $message, array $context = [] ) |
|
223 | 223 | { |
224 | - return $this->log(static::NOTICE, $message, $context); |
|
224 | + return $this->log( static::NOTICE, $message, $context ); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -230,21 +230,21 @@ discard block |
||
230 | 230 | * @param mixed $data |
231 | 231 | * @return void |
232 | 232 | */ |
233 | - public function once($levelName, $handle, $data) |
|
233 | + public function once( $levelName, $handle, $data ) |
|
234 | 234 | { |
235 | - $once = Arr::consolidateArray(glsr()->{$this->logOnceKey}); |
|
236 | - $filtered = array_filter($once, function ($entry) use ($levelName, $handle) { |
|
237 | - return Arr::get($entry, 'level') == $levelName |
|
238 | - && Arr::get($entry, 'handle') == $handle; |
|
235 | + $once = Arr::consolidateArray( glsr()->{$this->logOnceKey}); |
|
236 | + $filtered = array_filter( $once, function( $entry ) use ($levelName, $handle) { |
|
237 | + return Arr::get( $entry, 'level' ) == $levelName |
|
238 | + && Arr::get( $entry, 'handle' ) == $handle; |
|
239 | 239 | }); |
240 | - if (!empty($filtered)) { |
|
240 | + if( !empty($filtered) ) { |
|
241 | 241 | return; |
242 | 242 | } |
243 | 243 | $once[] = [ |
244 | - 'backtrace' => $this->getBacktraceLineFromData($data), |
|
244 | + 'backtrace' => $this->getBacktraceLineFromData( $data ), |
|
245 | 245 | 'handle' => $handle, |
246 | 246 | 'level' => $levelName, |
247 | - 'message' => '[RECURRING] '.$this->getMessageFromData($data), |
|
247 | + 'message' => '[RECURRING] '.$this->getMessageFromData( $data ), |
|
248 | 248 | ]; |
249 | 249 | glsr()->{$this->logOnceKey} = $once; |
250 | 250 | } |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function size() |
256 | 256 | { |
257 | - return file_exists($this->file) |
|
258 | - ? filesize($this->file) |
|
257 | + return file_exists( $this->file ) |
|
258 | + ? filesize( $this->file ) |
|
259 | 259 | : 0; |
260 | 260 | } |
261 | 261 | |
@@ -266,9 +266,9 @@ discard block |
||
266 | 266 | * @param array $context |
267 | 267 | * @return static |
268 | 268 | */ |
269 | - public function warning($message, array $context = []) |
|
269 | + public function warning( $message, array $context = [] ) |
|
270 | 270 | { |
271 | - return $this->log(static::WARNING, $message, $context); |
|
271 | + return $this->log( static::WARNING, $message, $context ); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * @param int $index |
277 | 277 | * @return string |
278 | 278 | */ |
279 | - protected function buildBacktraceLine($backtrace, $index) |
|
279 | + protected function buildBacktraceLine( $backtrace, $index ) |
|
280 | 280 | { |
281 | - return sprintf('%s:%s', |
|
282 | - Arr::get($backtrace, $index.'.file'), // realpath |
|
283 | - Arr::get($backtrace, $index.'.line') |
|
281 | + return sprintf( '%s:%s', |
|
282 | + Arr::get( $backtrace, $index.'.file' ), // realpath |
|
283 | + Arr::get( $backtrace, $index.'.line' ) |
|
284 | 284 | ); |
285 | 285 | } |
286 | 286 | |
@@ -290,11 +290,11 @@ discard block |
||
290 | 290 | * @param string $backtraceLine |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - protected function buildLogEntry($levelName, $message, $backtraceLine = '') |
|
293 | + protected function buildLogEntry( $levelName, $message, $backtraceLine = '' ) |
|
294 | 294 | { |
295 | - return sprintf('[%s] %s [%s] %s', |
|
296 | - current_time('mysql'), |
|
297 | - strtoupper($levelName), |
|
295 | + return sprintf( '[%s] %s [%s] %s', |
|
296 | + current_time( 'mysql' ), |
|
297 | + strtoupper( $levelName ), |
|
298 | 298 | $backtraceLine, |
299 | 299 | $message |
300 | 300 | ); |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | * @param int $level |
305 | 305 | * @return bool |
306 | 306 | */ |
307 | - protected function canLogEntry($level, $backtraceLine) |
|
307 | + protected function canLogEntry( $level, $backtraceLine ) |
|
308 | 308 | { |
309 | - $levelExists = array_key_exists($level, $this->getLevels()); |
|
310 | - if (!Str::contains($backtraceLine, glsr()->path())) { |
|
309 | + $levelExists = array_key_exists( $level, $this->getLevels() ); |
|
310 | + if( !Str::contains( $backtraceLine, glsr()->path() ) ) { |
|
311 | 311 | return $levelExists; // ignore level restriction if triggered outside of the plugin |
312 | 312 | } |
313 | 313 | return $levelExists && $level >= $this->getLevel(); |
@@ -318,17 +318,17 @@ discard block |
||
318 | 318 | */ |
319 | 319 | protected function getBacktraceLine() |
320 | 320 | { |
321 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6); |
|
322 | - $search = array_search('glsr_log', glsr_array_column($backtrace, 'function')); |
|
323 | - if (false !== $search) { |
|
324 | - return $this->buildBacktraceLine($backtrace, (int) $search); |
|
321 | + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 6 ); |
|
322 | + $search = array_search( 'glsr_log', glsr_array_column( $backtrace, 'function' ) ); |
|
323 | + if( false !== $search ) { |
|
324 | + return $this->buildBacktraceLine( $backtrace, (int)$search ); |
|
325 | 325 | } |
326 | - $search = array_search('log', glsr_array_column($backtrace, 'function')); |
|
327 | - if (false !== $search) { |
|
328 | - $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function') |
|
326 | + $search = array_search( 'log', glsr_array_column( $backtrace, 'function' ) ); |
|
327 | + if( false !== $search ) { |
|
328 | + $index = '{closure}' == Arr::get( $backtrace, ($search + 2).'.function' ) |
|
329 | 329 | ? $search + 4 |
330 | 330 | : $search + 1; |
331 | - return $this->buildBacktraceLine($backtrace, $index); |
|
331 | + return $this->buildBacktraceLine( $backtrace, $index ); |
|
332 | 332 | } |
333 | 333 | return 'Unknown'; |
334 | 334 | } |
@@ -337,23 +337,23 @@ discard block |
||
337 | 337 | * @param mixed $data |
338 | 338 | * @return string |
339 | 339 | */ |
340 | - protected function getBacktraceLineFromData($data) |
|
340 | + protected function getBacktraceLineFromData( $data ) |
|
341 | 341 | { |
342 | 342 | $backtrace = $data instanceof Throwable |
343 | 343 | ? $data->getTrace() |
344 | - : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
345 | - return $this->buildBacktraceLine($backtrace, 0); |
|
344 | + : debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1 ); |
|
345 | + return $this->buildBacktraceLine( $backtrace, 0 ); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
349 | 349 | * @param mixed $data |
350 | 350 | * @return string |
351 | 351 | */ |
352 | - protected function getMessageFromData($data) |
|
352 | + protected function getMessageFromData( $data ) |
|
353 | 353 | { |
354 | 354 | return $data instanceof Throwable |
355 | - ? $this->normalizeThrowableMessage($data->getMessage()) |
|
356 | - : print_r($data, 1); |
|
355 | + ? $this->normalizeThrowableMessage( $data->getMessage() ) |
|
356 | + : print_r( $data, 1 ); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -362,53 +362,53 @@ discard block |
||
362 | 362 | * @param array $context |
363 | 363 | * @return string |
364 | 364 | */ |
365 | - protected function interpolate($message, $context = []) |
|
365 | + protected function interpolate( $message, $context = [] ) |
|
366 | 366 | { |
367 | - if ($this->isObjectOrArray($message) || !is_array($context)) { |
|
368 | - return print_r($message, true); |
|
367 | + if( $this->isObjectOrArray( $message ) || !is_array( $context ) ) { |
|
368 | + return print_r( $message, true ); |
|
369 | 369 | } |
370 | 370 | $replace = []; |
371 | - foreach ($context as $key => $value) { |
|
372 | - $replace['{'.$key.'}'] = $this->normalizeValue($value); |
|
371 | + foreach( $context as $key => $value ) { |
|
372 | + $replace['{'.$key.'}'] = $this->normalizeValue( $value ); |
|
373 | 373 | } |
374 | - return strtr($message, $replace); |
|
374 | + return strtr( $message, $replace ); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
378 | 378 | * @param mixed $value |
379 | 379 | * @return bool |
380 | 380 | */ |
381 | - protected function isObjectOrArray($value) |
|
381 | + protected function isObjectOrArray( $value ) |
|
382 | 382 | { |
383 | - return is_object($value) || is_array($value); |
|
383 | + return is_object( $value ) || is_array( $value ); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
387 | 387 | * @param string $backtraceLine |
388 | 388 | * @return string |
389 | 389 | */ |
390 | - protected function normalizeBacktraceLine($backtraceLine) |
|
390 | + protected function normalizeBacktraceLine( $backtraceLine ) |
|
391 | 391 | { |
392 | 392 | $search = [ |
393 | - glsr()->path('plugin/'), |
|
394 | - glsr()->path('plugin/', false), |
|
395 | - trailingslashit(glsr()->path()), |
|
396 | - trailingslashit(glsr()->path('', false)), |
|
393 | + glsr()->path( 'plugin/' ), |
|
394 | + glsr()->path( 'plugin/', false ), |
|
395 | + trailingslashit( glsr()->path() ), |
|
396 | + trailingslashit( glsr()->path( '', false ) ), |
|
397 | 397 | WP_CONTENT_DIR, |
398 | 398 | ABSPATH, |
399 | 399 | ]; |
400 | - return str_replace(array_unique($search), '', $backtraceLine); |
|
400 | + return str_replace( array_unique( $search ), '', $backtraceLine ); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
404 | 404 | * @param string $message |
405 | 405 | * @return string |
406 | 406 | */ |
407 | - protected function normalizeThrowableMessage($message) |
|
407 | + protected function normalizeThrowableMessage( $message ) |
|
408 | 408 | { |
409 | - $calledIn = strpos($message, ', called in'); |
|
409 | + $calledIn = strpos( $message, ', called in' ); |
|
410 | 410 | return false !== $calledIn |
411 | - ? substr($message, 0, $calledIn) |
|
411 | + ? substr( $message, 0, $calledIn ) |
|
412 | 412 | : $message; |
413 | 413 | } |
414 | 414 | |
@@ -416,14 +416,14 @@ discard block |
||
416 | 416 | * @param mixed $value |
417 | 417 | * @return string |
418 | 418 | */ |
419 | - protected function normalizeValue($value) |
|
419 | + protected function normalizeValue( $value ) |
|
420 | 420 | { |
421 | - if ($value instanceof DateTime) { |
|
422 | - $value = $value->format('Y-m-d H:i:s'); |
|
423 | - } elseif ($this->isObjectOrArray($value)) { |
|
424 | - $value = json_encode($value); |
|
421 | + if( $value instanceof DateTime ) { |
|
422 | + $value = $value->format( 'Y-m-d H:i:s' ); |
|
423 | + } elseif( $this->isObjectOrArray( $value ) ) { |
|
424 | + $value = json_encode( $value ); |
|
425 | 425 | } |
426 | - return (string) $value; |
|
426 | + return (string)$value; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | */ |
432 | 432 | protected function reset() |
433 | 433 | { |
434 | - if ($this->size() <= pow(1024, 2) / 8) { |
|
434 | + if( $this->size() <= pow( 1024, 2 ) / 8 ) { |
|
435 | 435 | return; |
436 | 436 | } |
437 | 437 | $this->clear(); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | $this->file, |
440 | 440 | $this->buildLogEntry( |
441 | 441 | static::NOTICE, |
442 | - __('Console was automatically cleared (128 KB maximum size)', 'site-reviews') |
|
442 | + __( 'Console was automatically cleared (128 KB maximum size)', 'site-reviews' ) |
|
443 | 443 | ) |
444 | 444 | ); |
445 | 445 | } |
@@ -1,136 +1,136 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -defined('WPINC') || die; |
|
3 | +defined( 'WPINC' ) || die; |
|
4 | 4 | |
5 | -if (apply_filters('site-reviews/support/deprecated/v4', true)) { |
|
5 | +if( apply_filters( 'site-reviews/support/deprecated/v4', true ) ) { |
|
6 | 6 | // Unprotected review meta has been deprecated |
7 | - add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) { |
|
8 | - $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults()); |
|
9 | - if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) { |
|
7 | + add_filter( 'get_post_metadata', function( $data, $postId, $metaKey, $single ) { |
|
8 | + $metaKeys = array_keys( glsr( 'Defaults\CreateReviewDefaults' )->defaults() ); |
|
9 | + if( !in_array( $metaKey, $metaKeys ) || glsr()->post_type != get_post_type( $postId ) ) { |
|
10 | 10 | return $data; |
11 | 11 | } |
12 | 12 | glsr()->deprecated[] = sprintf( |
13 | 13 | 'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.', |
14 | 14 | $metaKey |
15 | 15 | ); |
16 | - return get_post_meta($postId, '_'.$metaKey, $single); |
|
17 | - }, 10, 4); |
|
16 | + return get_post_meta( $postId, '_'.$metaKey, $single ); |
|
17 | + }, 10, 4 ); |
|
18 | 18 | |
19 | 19 | // Modules/Html/Template.php |
20 | - add_filter('site-reviews/interpolate/reviews', function ($context, $template) { |
|
20 | + add_filter( 'site-reviews/interpolate/reviews', function( $context, $template ) { |
|
21 | 21 | $search = '{{ navigation }}'; |
22 | - if (false !== strpos($template, $search)) { |
|
22 | + if( false !== strpos( $template, $search ) ) { |
|
23 | 23 | $context['navigation'] = $context['pagination']; |
24 | 24 | glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.'; |
25 | 25 | } |
26 | 26 | return $context; |
27 | - }, 10, 2); |
|
27 | + }, 10, 2 ); |
|
28 | 28 | |
29 | 29 | // Database/ReviewManager.php |
30 | - add_action('site-reviews/review/created', function ($review) { |
|
31 | - if (has_action('site-reviews/local/review/create')) { |
|
30 | + add_action( 'site-reviews/review/created', function( $review ) { |
|
31 | + if( has_action( 'site-reviews/local/review/create' ) ) { |
|
32 | 32 | glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.'; |
33 | - do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID); |
|
33 | + do_action( 'site-reviews/local/review/create', (array)get_post( $review->ID ), (array)$review, $review->ID ); |
|
34 | 34 | } |
35 | - }, 9); |
|
35 | + }, 9 ); |
|
36 | 36 | |
37 | 37 | // Handlers/CreateReview.php |
38 | - add_action('site-reviews/review/submitted', function ($review) { |
|
39 | - if (has_action('site-reviews/local/review/submitted')) { |
|
38 | + add_action( 'site-reviews/review/submitted', function( $review ) { |
|
39 | + if( has_action( 'site-reviews/local/review/submitted' ) ) { |
|
40 | 40 | glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.'; |
41 | - do_action('site-reviews/local/review/submitted', null, $review); |
|
41 | + do_action( 'site-reviews/local/review/submitted', null, $review ); |
|
42 | 42 | } |
43 | - if (has_filter('site-reviews/local/review/submitted/message')) { |
|
43 | + if( has_filter( 'site-reviews/local/review/submitted/message' ) ) { |
|
44 | 44 | glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.'; |
45 | 45 | } |
46 | - }, 9); |
|
46 | + }, 9 ); |
|
47 | 47 | |
48 | 48 | // Database/ReviewManager.php |
49 | - add_filter('site-reviews/create/review-values', function ($values, $command) { |
|
50 | - if (has_filter('site-reviews/local/review')) { |
|
49 | + add_filter( 'site-reviews/create/review-values', function( $values, $command ) { |
|
50 | + if( has_filter( 'site-reviews/local/review' ) ) { |
|
51 | 51 | glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.'; |
52 | - return apply_filters('site-reviews/local/review', $values, $command); |
|
52 | + return apply_filters( 'site-reviews/local/review', $values, $command ); |
|
53 | 53 | } |
54 | 54 | return $values; |
55 | - }, 9, 2); |
|
55 | + }, 9, 2 ); |
|
56 | 56 | |
57 | 57 | // Handlers/EnqueuePublicAssets.php |
58 | - add_filter('site-reviews/enqueue/public/localize', function ($variables) { |
|
59 | - if (has_filter('site-reviews/enqueue/localize')) { |
|
58 | + add_filter( 'site-reviews/enqueue/public/localize', function( $variables ) { |
|
59 | + if( has_filter( 'site-reviews/enqueue/localize' ) ) { |
|
60 | 60 | glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.'; |
61 | - return apply_filters('site-reviews/enqueue/localize', $variables); |
|
61 | + return apply_filters( 'site-reviews/enqueue/localize', $variables ); |
|
62 | 62 | } |
63 | 63 | return $variables; |
64 | - }, 9); |
|
64 | + }, 9 ); |
|
65 | 65 | |
66 | 66 | // Modules/Rating.php |
67 | - add_filter('site-reviews/rating/average', function ($average) { |
|
68 | - if (has_filter('site-reviews/average/rating')) { |
|
67 | + add_filter( 'site-reviews/rating/average', function( $average ) { |
|
68 | + if( has_filter( 'site-reviews/average/rating' ) ) { |
|
69 | 69 | glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.'; |
70 | 70 | } |
71 | 71 | return $average; |
72 | - }, 9); |
|
72 | + }, 9 ); |
|
73 | 73 | |
74 | 74 | // Modules/Rating.php |
75 | - add_filter('site-reviews/rating/ranking', function ($ranking) { |
|
76 | - if (has_filter('site-reviews/bayesian/ranking')) { |
|
75 | + add_filter( 'site-reviews/rating/ranking', function( $ranking ) { |
|
76 | + if( has_filter( 'site-reviews/bayesian/ranking' ) ) { |
|
77 | 77 | glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.'; |
78 | 78 | } |
79 | 79 | return $ranking; |
80 | - }, 9); |
|
80 | + }, 9 ); |
|
81 | 81 | |
82 | 82 | // Modules/Html/Partials/SiteReviews.php |
83 | - add_filter('site-reviews/review/build/after', function ($renderedFields) { |
|
84 | - if (has_filter('site-reviews/reviews/review/text')) { |
|
83 | + add_filter( 'site-reviews/review/build/after', function( $renderedFields ) { |
|
84 | + if( has_filter( 'site-reviews/reviews/review/text' ) ) { |
|
85 | 85 | glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
86 | 86 | } |
87 | - if (has_filter('site-reviews/reviews/review/title')) { |
|
87 | + if( has_filter( 'site-reviews/reviews/review/title' ) ) { |
|
88 | 88 | glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
89 | 89 | } |
90 | 90 | return $renderedFields; |
91 | - }, 9); |
|
91 | + }, 9 ); |
|
92 | 92 | |
93 | 93 | // Modules/Html/Partials/SiteReviews.php |
94 | - add_filter('site-reviews/review/build/before', function ($review) { |
|
95 | - if (has_filter('site-reviews/rendered/review')) { |
|
94 | + add_filter( 'site-reviews/review/build/before', function( $review ) { |
|
95 | + if( has_filter( 'site-reviews/rendered/review' ) ) { |
|
96 | 96 | glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.'; |
97 | 97 | } |
98 | - if (has_filter('site-reviews/rendered/review/meta/order')) { |
|
98 | + if( has_filter( 'site-reviews/rendered/review/meta/order' ) ) { |
|
99 | 99 | glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
100 | 100 | } |
101 | - if (has_filter('site-reviews/rendered/review/order')) { |
|
101 | + if( has_filter( 'site-reviews/rendered/review/order' ) ) { |
|
102 | 102 | glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
103 | 103 | } |
104 | - if (has_filter('site-reviews/rendered/review-form/login-register')) { |
|
104 | + if( has_filter( 'site-reviews/rendered/review-form/login-register' ) ) { |
|
105 | 105 | glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).'; |
106 | 106 | } |
107 | - if (has_filter('site-reviews/reviews/navigation_links')) { |
|
107 | + if( has_filter( 'site-reviews/reviews/navigation_links' ) ) { |
|
108 | 108 | glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).'; |
109 | 109 | } |
110 | 110 | return $review; |
111 | - }, 9); |
|
111 | + }, 9 ); |
|
112 | 112 | |
113 | - add_filter('site-reviews/validate/custom', function ($result, $request) { |
|
114 | - if (has_filter('site-reviews/validate/review/submission')) { |
|
115 | - glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.'); |
|
116 | - return apply_filters('site-reviews/validate/review/submission', $result, $request); |
|
113 | + add_filter( 'site-reviews/validate/custom', function( $result, $request ) { |
|
114 | + if( has_filter( 'site-reviews/validate/review/submission' ) ) { |
|
115 | + glsr_log()->warning( 'The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.' ); |
|
116 | + return apply_filters( 'site-reviews/validate/review/submission', $result, $request ); |
|
117 | 117 | } |
118 | 118 | return $result; |
119 | - }, 9, 2); |
|
119 | + }, 9, 2 ); |
|
120 | 120 | |
121 | - add_filter('site-reviews/views/file', function ($file, $view, $data) { |
|
122 | - if (has_filter('site-reviews/addon/views/file')) { |
|
121 | + add_filter( 'site-reviews/views/file', function( $file, $view, $data ) { |
|
122 | + if( has_filter( 'site-reviews/addon/views/file' ) ) { |
|
123 | 123 | glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.'; |
124 | - $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data); |
|
124 | + $file = apply_filters( 'site-reviews/addon/views/file', $file, $view, $data ); |
|
125 | 125 | } |
126 | 126 | return $file; |
127 | - }, 9, 3); |
|
127 | + }, 9, 3 ); |
|
128 | 128 | } |
129 | 129 | |
130 | -add_action('wp_footer', function () { |
|
131 | - $notices = array_keys(array_flip(glsr()->deprecated)); |
|
132 | - natsort($notices); |
|
133 | - foreach ($notices as $notice) { |
|
134 | - glsr_log()->warning($notice); |
|
130 | +add_action( 'wp_footer', function() { |
|
131 | + $notices = array_keys( array_flip( glsr()->deprecated ) ); |
|
132 | + natsort( $notices ); |
|
133 | + foreach( $notices as $notice ) { |
|
134 | + glsr_log()->warning( $notice ); |
|
135 | 135 | } |
136 | 136 | }); |
@@ -30,21 +30,21 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @return array |
32 | 32 | */ |
33 | - public function build(array $args = []) |
|
33 | + public function build( array $args = [] ) |
|
34 | 34 | { |
35 | 35 | $this->args = $args; |
36 | - $schema = $this->buildSummary($args); |
|
36 | + $schema = $this->buildSummary( $args ); |
|
37 | 37 | $reviews = []; |
38 | - foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
38 | + foreach( glsr( ReviewManager::class )->get( $this->args ) as $review ) { |
|
39 | 39 | // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
40 | 40 | // @see https://developers.google.com/search/docs/data-types/review |
41 | - if ('local' != $review->review_type) { |
|
41 | + if( 'local' != $review->review_type ) { |
|
42 | 42 | continue; |
43 | 43 | } |
44 | - $reviews[] = $this->buildReview($review); |
|
44 | + $reviews[] = $this->buildReview( $review ); |
|
45 | 45 | } |
46 | - if (!empty($reviews)) { |
|
47 | - array_walk($reviews, function (&$review) { |
|
46 | + if( !empty($reviews) ) { |
|
47 | + array_walk( $reviews, function( &$review ) { |
|
48 | 48 | unset($review['@context']); |
49 | 49 | unset($review['itemReviewed']); |
50 | 50 | }); |
@@ -57,27 +57,27 @@ discard block |
||
57 | 57 | * @param array|null $args |
58 | 58 | * @return array |
59 | 59 | */ |
60 | - public function buildSummary($args = null) |
|
60 | + public function buildSummary( $args = null ) |
|
61 | 61 | { |
62 | - if (is_array($args)) { |
|
62 | + if( is_array( $args ) ) { |
|
63 | 63 | $this->args = $args; |
64 | 64 | } |
65 | - $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
66 | - $count = array_sum($this->getRatingCounts()); |
|
67 | - $schema = method_exists($this, $buildSummary) |
|
65 | + $buildSummary = Helper::buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' ); |
|
66 | + $count = array_sum( $this->getRatingCounts() ); |
|
67 | + $schema = method_exists( $this, $buildSummary ) |
|
68 | 68 | ? $this->$buildSummary() |
69 | 69 | : $this->buildSummaryForCustom(); |
70 | - if (!empty($count)) { |
|
70 | + if( !empty($count) ) { |
|
71 | 71 | $schema->aggregateRating( |
72 | - $this->getSchemaType('AggregateRating') |
|
73 | - ->ratingValue($this->getRatingValue()) |
|
74 | - ->reviewCount($count) |
|
75 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
76 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
72 | + $this->getSchemaType( 'AggregateRating' ) |
|
73 | + ->ratingValue( $this->getRatingValue() ) |
|
74 | + ->reviewCount( $count ) |
|
75 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
76 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
77 | 77 | ); |
78 | 78 | } |
79 | 79 | $schema = $schema->toArray(); |
80 | - return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
80 | + return apply_filters( 'site-reviews/schema/'.$schema['@type'], $schema, $args ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -85,64 +85,64 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function render() |
87 | 87 | { |
88 | - if (empty(glsr()->schemas)) { |
|
88 | + if( empty(glsr()->schemas) ) { |
|
89 | 89 | return; |
90 | 90 | } |
91 | - printf('<script type="application/ld+json">%s</script>', json_encode( |
|
92 | - apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
91 | + printf( '<script type="application/ld+json">%s</script>', json_encode( |
|
92 | + apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
|
93 | 93 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
94 | - )); |
|
94 | + ) ); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | 98 | * @return void |
99 | 99 | */ |
100 | - public function store(array $schema) |
|
100 | + public function store( array $schema ) |
|
101 | 101 | { |
102 | 102 | $schemas = glsr()->schemas; |
103 | 103 | $schemas[] = $schema; |
104 | - glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
104 | + glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @param Review $review |
109 | 109 | * @return array |
110 | 110 | */ |
111 | - protected function buildReview($review) |
|
111 | + protected function buildReview( $review ) |
|
112 | 112 | { |
113 | - $schema = $this->getSchemaType('Review') |
|
114 | - ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
115 | - $schema->name($review->title); |
|
113 | + $schema = $this->getSchemaType( 'Review' ) |
|
114 | + ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use ($review) { |
|
115 | + $schema->name( $review->title ); |
|
116 | 116 | }) |
117 | - ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
118 | - $schema->reviewBody($review->content); |
|
117 | + ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use ($review) { |
|
118 | + $schema->reviewBody( $review->content ); |
|
119 | 119 | }) |
120 | - ->datePublished((new DateTime($review->date))) |
|
121 | - ->author($this->getSchemaType('Person')->name($review->author)) |
|
122 | - ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
123 | - if (!empty($review->rating)) { |
|
120 | + ->datePublished( (new DateTime( $review->date )) ) |
|
121 | + ->author( $this->getSchemaType( 'Person' )->name( $review->author ) ) |
|
122 | + ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) ); |
|
123 | + if( !empty($review->rating) ) { |
|
124 | 124 | $schema->reviewRating( |
125 | - $this->getSchemaType('Rating') |
|
126 | - ->ratingValue($review->rating) |
|
127 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
128 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
125 | + $this->getSchemaType( 'Rating' ) |
|
126 | + ->ratingValue( $review->rating ) |
|
127 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
128 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
129 | 129 | ); |
130 | 130 | } |
131 | - return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
131 | + return apply_filters( 'site-reviews/schema/review', $schema->toArray(), $review, $this->args ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | 135 | * @param mixed $schema |
136 | 136 | * @return mixed |
137 | 137 | */ |
138 | - protected function buildSchemaValues($schema, array $values = []) |
|
138 | + protected function buildSchemaValues( $schema, array $values = [] ) |
|
139 | 139 | { |
140 | - foreach ($values as $value) { |
|
141 | - $option = $this->getSchemaOptionValue($value); |
|
142 | - if (empty($option)) { |
|
140 | + foreach( $values as $value ) { |
|
141 | + $option = $this->getSchemaOptionValue( $value ); |
|
142 | + if( empty($option) ) { |
|
143 | 143 | continue; |
144 | 144 | } |
145 | - $schema->$value($option); |
|
145 | + $schema->$value( $option ); |
|
146 | 146 | } |
147 | 147 | return $schema; |
148 | 148 | } |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | */ |
153 | 153 | protected function buildSummaryForCustom() |
154 | 154 | { |
155 | - return $this->buildSchemaValues($this->getSchemaType(), [ |
|
155 | + return $this->buildSchemaValues( $this->getSchemaType(), [ |
|
156 | 156 | 'description', 'image', 'name', 'url', |
157 | - ]); |
|
157 | + ] ); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | */ |
163 | 163 | protected function buildSummaryForLocalBusiness() |
164 | 164 | { |
165 | - return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
165 | + return $this->buildSchemaValues( $this->buildSummaryForCustom(), [ |
|
166 | 166 | 'address', 'priceRange', 'telephone', |
167 | - ]); |
|
167 | + ] ); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | */ |
173 | 173 | protected function buildSummaryForProduct() |
174 | 174 | { |
175 | - $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
176 | - $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
175 | + $offerType = $this->getSchemaOption( 'offerType', 'AggregateOffer' ); |
|
176 | + $offers = $this->buildSchemaValues( $this->getSchemaType( $offerType ), [ |
|
177 | 177 | 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
178 | - ]); |
|
178 | + ] ); |
|
179 | 179 | return $this->buildSummaryForCustom() |
180 | - ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
181 | - $schema->offers($offers); |
|
180 | + ->doIf( !empty($offers->getProperties()), function( $schema ) use ($offers) { |
|
181 | + $schema->offers( $offers ); |
|
182 | 182 | }) |
183 | - ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
183 | + ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ).'#product' ); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | */ |
189 | 189 | protected function getRatingCounts() |
190 | 190 | { |
191 | - if (!isset($this->ratingCounts)) { |
|
192 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
191 | + if( !isset($this->ratingCounts) ) { |
|
192 | + $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $this->args ); |
|
193 | 193 | } |
194 | 194 | return $this->ratingCounts; |
195 | 195 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | protected function getRatingValue() |
201 | 201 | { |
202 | - return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
202 | + return glsr( Rating::class )->getAverage( $this->getRatingCounts() ); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -207,15 +207,15 @@ discard block |
||
207 | 207 | * @param string $fallback |
208 | 208 | * @return string |
209 | 209 | */ |
210 | - protected function getSchemaOption($option, $fallback) |
|
210 | + protected function getSchemaOption( $option, $fallback ) |
|
211 | 211 | { |
212 | - $option = strtolower($option); |
|
213 | - if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
212 | + $option = strtolower( $option ); |
|
213 | + if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) { |
|
214 | 214 | return $schemaOption; |
215 | 215 | } |
216 | - $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
217 | - if (is_array($setting)) { |
|
218 | - return $this->getSchemaOptionDefault($setting, $fallback); |
|
216 | + $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option ); |
|
217 | + if( is_array( $setting ) ) { |
|
218 | + return $this->getSchemaOptionDefault( $setting, $fallback ); |
|
219 | 219 | } |
220 | 220 | return !empty($setting) |
221 | 221 | ? $setting |
@@ -226,12 +226,12 @@ discard block |
||
226 | 226 | * @param string $fallback |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - protected function getSchemaOptionDefault(array $setting, $fallback) |
|
229 | + protected function getSchemaOptionDefault( array $setting, $fallback ) |
|
230 | 230 | { |
231 | - $setting = wp_parse_args($setting, [ |
|
231 | + $setting = wp_parse_args( $setting, [ |
|
232 | 232 | 'custom' => '', |
233 | 233 | 'default' => $fallback, |
234 | - ]); |
|
234 | + ] ); |
|
235 | 235 | return 'custom' != $setting['default'] |
236 | 236 | ? $setting['default'] |
237 | 237 | : $setting['custom']; |
@@ -242,21 +242,21 @@ discard block |
||
242 | 242 | * @param string $fallback |
243 | 243 | * @return void|string |
244 | 244 | */ |
245 | - protected function getSchemaOptionValue($option, $fallback = 'post') |
|
245 | + protected function getSchemaOptionValue( $option, $fallback = 'post' ) |
|
246 | 246 | { |
247 | - if (array_key_exists($option, $this->keyValues)) { |
|
247 | + if( array_key_exists( $option, $this->keyValues ) ) { |
|
248 | 248 | return $this->keyValues[$option]; |
249 | 249 | } |
250 | - $value = $this->getSchemaOption($option, $fallback); |
|
251 | - if ($value != $fallback) { |
|
252 | - return $this->setAndGetKeyValue($option, $value); |
|
250 | + $value = $this->getSchemaOption( $option, $fallback ); |
|
251 | + if( $value != $fallback ) { |
|
252 | + return $this->setAndGetKeyValue( $option, $value ); |
|
253 | 253 | } |
254 | - if (!is_single() && !is_page()) { |
|
254 | + if( !is_single() && !is_page() ) { |
|
255 | 255 | return; |
256 | 256 | } |
257 | - $method = Helper::buildMethodName($option, 'getThing'); |
|
258 | - if (method_exists($this, $method)) { |
|
259 | - return $this->setAndGetKeyValue($option, $this->$method()); |
|
257 | + $method = Helper::buildMethodName( $option, 'getThing' ); |
|
258 | + if( method_exists( $this, $method ) ) { |
|
259 | + return $this->setAndGetKeyValue( $option, $this->$method() ); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
@@ -264,15 +264,15 @@ discard block |
||
264 | 264 | * @param string|null $type |
265 | 265 | * @return mixed |
266 | 266 | */ |
267 | - protected function getSchemaType($type = null) |
|
267 | + protected function getSchemaType( $type = null ) |
|
268 | 268 | { |
269 | - if (!is_string($type)) { |
|
270 | - $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
269 | + if( !is_string( $type ) ) { |
|
270 | + $type = $this->getSchemaOption( 'type', 'LocalBusiness' ); |
|
271 | 271 | } |
272 | - $className = Helper::buildClassName($type, 'Modules\Schema'); |
|
273 | - return class_exists($className) |
|
272 | + $className = Helper::buildClassName( $type, 'Modules\Schema' ); |
|
273 | + return class_exists( $className ) |
|
274 | 274 | ? new $className() |
275 | - : new UnknownType($type); |
|
275 | + : new UnknownType( $type ); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -281,19 +281,19 @@ discard block |
||
281 | 281 | protected function getThingDescription() |
282 | 282 | { |
283 | 283 | $post = get_post(); |
284 | - $text = Arr::get($post, 'post_excerpt'); |
|
285 | - if (empty($text)) { |
|
286 | - $text = Arr::get($post, 'post_content'); |
|
284 | + $text = Arr::get( $post, 'post_excerpt' ); |
|
285 | + if( empty($text) ) { |
|
286 | + $text = Arr::get( $post, 'post_content' ); |
|
287 | 287 | } |
288 | - if (function_exists('excerpt_remove_blocks')) { |
|
289 | - $text = excerpt_remove_blocks($text); |
|
288 | + if( function_exists( 'excerpt_remove_blocks' ) ) { |
|
289 | + $text = excerpt_remove_blocks( $text ); |
|
290 | 290 | } |
291 | - $text = strip_shortcodes($text); |
|
292 | - $text = wpautop($text); |
|
293 | - $text = wptexturize($text); |
|
294 | - $text = wp_strip_all_tags($text); |
|
295 | - $text = str_replace(']]>', ']]>', $text); |
|
296 | - return wp_trim_words($text, apply_filters('excerpt_length', 55)); |
|
291 | + $text = strip_shortcodes( $text ); |
|
292 | + $text = wpautop( $text ); |
|
293 | + $text = wptexturize( $text ); |
|
294 | + $text = wp_strip_all_tags( $text ); |
|
295 | + $text = str_replace( ']]>', ']]>', $text ); |
|
296 | + return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) ); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | */ |
302 | 302 | protected function getThingImage() |
303 | 303 | { |
304 | - return (string) get_the_post_thumbnail_url(null, 'large'); |
|
304 | + return (string)get_the_post_thumbnail_url( null, 'large' ); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | */ |
318 | 318 | protected function getThingUrl() |
319 | 319 | { |
320 | - return (string) get_the_permalink(); |
|
320 | + return (string)get_the_permalink(); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @param string $value |
326 | 326 | * @return string |
327 | 327 | */ |
328 | - protected function setAndGetKeyValue($option, $value) |
|
328 | + protected function setAndGetKeyValue( $option, $value ) |
|
329 | 329 | { |
330 | 330 | $this->keyValues[$option] = $value; |
331 | 331 | return $value; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function enqueueAssets() |
28 | 28 | { |
29 | - if (apply_filters('site-reviews/assets/css', true)) { |
|
29 | + if( apply_filters( 'site-reviews/assets/css', true ) ) { |
|
30 | 30 | wp_enqueue_style( |
31 | 31 | Application::ID, |
32 | 32 | $this->getStylesheet(), |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | glsr()->version |
35 | 35 | ); |
36 | 36 | } |
37 | - if (apply_filters('site-reviews/assets/js', true)) { |
|
38 | - $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
37 | + if( apply_filters( 'site-reviews/assets/js', true ) ) { |
|
38 | + $dependencies = apply_filters( 'site-reviews/assets/polyfill', true ) |
|
39 | 39 | ? [Application::ID.'/polyfill'] |
40 | 40 | : []; |
41 | - $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
41 | + $dependencies = apply_filters( 'site-reviews/enqueue/public/dependencies', $dependencies ); |
|
42 | 42 | wp_enqueue_script( |
43 | 43 | Application::ID, |
44 | - glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
44 | + glsr()->url( 'assets/scripts/'.Application::ID.'.js' ), |
|
45 | 45 | $dependencies, |
46 | 46 | glsr()->version, |
47 | 47 | true |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function enqueuePolyfillService() |
56 | 56 | { |
57 | - if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
57 | + if( !apply_filters( 'site-reviews/assets/polyfill', true ) ) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | - wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
60 | + wp_enqueue_script( Application::ID.'/polyfill', add_query_arg( [ |
|
61 | 61 | 'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
62 | 62 | 'flags' => 'gated', |
63 | - ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
63 | + ], 'https://polyfill.io/v3/polyfill.min.js' ) ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | // wpforms-recaptcha |
72 | 72 | // google-recaptcha |
73 | 73 | // nf-google-recaptcha |
74 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
74 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | - $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
78 | - wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
77 | + $language = apply_filters( 'site-reviews/recaptcha/language', get_locale() ); |
|
78 | + wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg( [ |
|
79 | 79 | 'hl' => $language, |
80 | 80 | 'render' => 'explicit', |
81 | - ], 'https://www.google.com/recaptcha/api.js')); |
|
81 | + ], 'https://www.google.com/recaptcha/api.js' ) ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | $variables = [ |
90 | 90 | 'action' => Application::PREFIX.'action', |
91 | 91 | 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
92 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
92 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
93 | 93 | 'nameprefix' => Application::ID, |
94 | - 'validationconfig' => glsr(Style::class)->validation, |
|
95 | - 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
94 | + 'validationconfig' => glsr( Style::class )->validation, |
|
95 | + 'validationstrings' => glsr( ValidationStringsDefaults::class )->defaults(), |
|
96 | 96 | ]; |
97 | - $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
98 | - wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
97 | + $variables = apply_filters( 'site-reviews/enqueue/public/localize', $variables ); |
|
98 | + wp_add_inline_script( Application::ID, $this->buildInlineScript( $variables ), 'before' ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,35 +103,35 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function inlineStyles() |
105 | 105 | { |
106 | - $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
107 | - if (!apply_filters('site-reviews/assets/css', true)) { |
|
106 | + $inlineStylesheetPath = glsr()->path( 'assets/styles/inline-styles.css' ); |
|
107 | + if( !apply_filters( 'site-reviews/assets/css', true ) ) { |
|
108 | 108 | return; |
109 | 109 | } |
110 | - if (!file_exists($inlineStylesheetPath)) { |
|
111 | - glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
110 | + if( !file_exists( $inlineStylesheetPath ) ) { |
|
111 | + glsr_log()->error( 'Inline stylesheet is missing: '.$inlineStylesheetPath ); |
|
112 | 112 | return; |
113 | 113 | } |
114 | - $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
114 | + $inlineStylesheetValues = glsr()->config( 'inline-styles' ); |
|
115 | 115 | $stylesheet = str_replace( |
116 | - array_keys($inlineStylesheetValues), |
|
117 | - array_values($inlineStylesheetValues), |
|
118 | - file_get_contents($inlineStylesheetPath) |
|
116 | + array_keys( $inlineStylesheetValues ), |
|
117 | + array_values( $inlineStylesheetValues ), |
|
118 | + file_get_contents( $inlineStylesheetPath ) |
|
119 | 119 | ); |
120 | - wp_add_inline_style(Application::ID, $stylesheet); |
|
120 | + wp_add_inline_style( Application::ID, $stylesheet ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | 124 | * @return string |
125 | 125 | */ |
126 | - protected function buildInlineScript(array $variables) |
|
126 | + protected function buildInlineScript( array $variables ) |
|
127 | 127 | { |
128 | 128 | $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
129 | - foreach ($variables as $key => $value) { |
|
130 | - $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
129 | + foreach( $variables as $key => $value ) { |
|
130 | + $script .= sprintf( 'GLSR.%s=%s;', $key, json_encode( $value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ); |
|
131 | 131 | } |
132 | 132 | $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
133 | - $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
134 | - return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
133 | + $optimizedScript = preg_replace( $pattern, '$1$2', $script ); |
|
134 | + return apply_filters( 'site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables ); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | protected function getFixedSelectorsForPagination() |
141 | 141 | { |
142 | 142 | $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
143 | - return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
143 | + return apply_filters( 'site-reviews/enqueue/public/localize/ajax-pagination', $selectors ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | */ |
149 | 149 | protected function getStylesheet() |
150 | 150 | { |
151 | - $currentStyle = glsr(Style::class)->style; |
|
152 | - return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
153 | - ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
154 | - : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
151 | + $currentStyle = glsr( Style::class )->style; |
|
152 | + return file_exists( glsr()->path( 'assets/styles/custom/'.$currentStyle.'.css' ) ) |
|
153 | + ? glsr()->url( 'assets/styles/custom/'.$currentStyle.'.css' ) |
|
154 | + : glsr()->url( 'assets/styles/'.Application::ID.'.css' ); |
|
155 | 155 | } |
156 | 156 | } |
@@ -19,23 +19,23 @@ discard block |
||
19 | 19 | public function run() |
20 | 20 | { |
21 | 21 | $filenames = []; |
22 | - $iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader'); |
|
23 | - foreach ($iterator as $fileinfo) { |
|
24 | - if ($fileinfo->isFile()) { |
|
22 | + $iterator = new DirectoryIterator( dirname( __FILE__ ).'/Upgrader' ); |
|
23 | + foreach( $iterator as $fileinfo ) { |
|
24 | + if( $fileinfo->isFile() ) { |
|
25 | 25 | $filenames[] = $fileinfo->getFilename(); |
26 | 26 | } |
27 | 27 | } |
28 | - natsort($filenames); |
|
28 | + natsort( $filenames ); |
|
29 | 29 | $this->currentVersion = $this->currentVersion(); |
30 | - array_walk($filenames, function ($file) { |
|
31 | - $className = str_replace('.php', '', $file); |
|
32 | - $upgradeFromVersion = str_replace(['Upgrade_', '_'], ['', '.'], $className); |
|
33 | - $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
34 | - if (version_compare($this->currentVersion, $upgradeFromVersion.$suffix, '>=')) { |
|
30 | + array_walk( $filenames, function( $file ) { |
|
31 | + $className = str_replace( '.php', '', $file ); |
|
32 | + $upgradeFromVersion = str_replace( ['Upgrade_', '_'], ['', '.'], $className ); |
|
33 | + $suffix = preg_replace( '/[\d.]+(.+)?/', '${1}', glsr()->version ); // allow alpha/beta versions |
|
34 | + if( version_compare( $this->currentVersion, $upgradeFromVersion.$suffix, '>=' ) ) { |
|
35 | 35 | return; |
36 | 36 | } |
37 | - glsr('Modules\\Upgrader\\'.$className); |
|
38 | - glsr_log()->notice('Completed Upgrade for v'.$upgradeFromVersion.$suffix); |
|
37 | + glsr( 'Modules\\Upgrader\\'.$className ); |
|
38 | + glsr_log()->notice( 'Completed Upgrade for v'.$upgradeFromVersion.$suffix ); |
|
39 | 39 | }); |
40 | 40 | $this->finish(); |
41 | 41 | } |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function finish() |
47 | 47 | { |
48 | - if ($this->currentVersion !== glsr()->version) { |
|
48 | + if( $this->currentVersion !== glsr()->version ) { |
|
49 | 49 | $this->setReviewCounts(); |
50 | - $this->updateVersionFrom($this->currentVersion); |
|
51 | - } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
50 | + $this->updateVersionFrom( $this->currentVersion ); |
|
51 | + } elseif( !glsr( OptionManager::class )->get( 'last_review_count', false ) ) { |
|
52 | 52 | $this->setReviewCounts(); |
53 | 53 | } |
54 | 54 | } |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | { |
61 | 61 | $fallback = '0.0.0'; |
62 | 62 | $majorVersions = [4, 3, 2]; |
63 | - foreach ($majorVersions as $majorVersion) { |
|
64 | - $settings = get_option(OptionManager::databaseKey($majorVersion)); |
|
65 | - $version = Arr::get($settings, 'version', $fallback); |
|
66 | - if (version_compare($version, $fallback, '>')) { |
|
63 | + foreach( $majorVersions as $majorVersion ) { |
|
64 | + $settings = get_option( OptionManager::databaseKey( $majorVersion ) ); |
|
65 | + $version = Arr::get( $settings, 'version', $fallback ); |
|
66 | + if( version_compare( $version, $fallback, '>' ) ) { |
|
67 | 67 | return $version; |
68 | 68 | } |
69 | 69 | } |
@@ -75,16 +75,16 @@ discard block |
||
75 | 75 | */ |
76 | 76 | protected function setReviewCounts() |
77 | 77 | { |
78 | - add_action('admin_init', 'glsr_calculate_ratings'); |
|
78 | + add_action( 'admin_init', 'glsr_calculate_ratings' ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @param string $previousVersion |
83 | 83 | * @return void |
84 | 84 | */ |
85 | - protected function updateVersionFrom($previousVersion) |
|
85 | + protected function updateVersionFrom( $previousVersion ) |
|
86 | 86 | { |
87 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
88 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
87 | + glsr( OptionManager::class )->set( 'version', glsr()->version ); |
|
88 | + glsr( OptionManager::class )->set( 'version_upgraded_from', $previousVersion ); |
|
89 | 89 | } |
90 | 90 | } |
@@ -14,17 +14,17 @@ discard block |
||
14 | 14 | * @return array |
15 | 15 | * @callback register_setting |
16 | 16 | */ |
17 | - public function callbackRegisterSettings($input) |
|
17 | + public function callbackRegisterSettings( $input ) |
|
18 | 18 | { |
19 | - $settings = Arr::consolidateArray($input); |
|
20 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
21 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
22 | - $options = $this->sanitizeGeneral($input, $options); |
|
23 | - $options = $this->sanitizeSubmissions($input, $options); |
|
24 | - $options = $this->sanitizeTranslations($input, $options); |
|
25 | - $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
26 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
27 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
19 | + $settings = Arr::consolidateArray( $input ); |
|
20 | + if( 1 === count( $settings ) && array_key_exists( 'settings', $settings ) ) { |
|
21 | + $options = array_replace_recursive( glsr( OptionManager::class )->all(), $input ); |
|
22 | + $options = $this->sanitizeGeneral( $input, $options ); |
|
23 | + $options = $this->sanitizeSubmissions( $input, $options ); |
|
24 | + $options = $this->sanitizeTranslations( $input, $options ); |
|
25 | + $options = apply_filters( 'site-reviews/settings/callback', $options, $settings ); |
|
26 | + if( filter_input( INPUT_POST, 'option_page' ) == Application::ID.'-settings' ) { |
|
27 | + glsr( Notice::class )->addSuccess( __( 'Settings updated.', 'site-reviews' ) ); |
|
28 | 28 | } |
29 | 29 | return $options; |
30 | 30 | } |
@@ -37,63 +37,63 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function registerSettings() |
39 | 39 | { |
40 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
40 | + register_setting( Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
41 | 41 | 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
42 | - ]); |
|
42 | + ] ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @return array |
47 | 47 | */ |
48 | - protected function sanitizeGeneral(array $input, array $options) |
|
48 | + protected function sanitizeGeneral( array $input, array $options ) |
|
49 | 49 | { |
50 | 50 | $key = 'settings.general'; |
51 | - $inputForm = Arr::get($input, $key); |
|
52 | - if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
53 | - $options = Arr::set($options, $key.'.multilingual', ''); |
|
51 | + $inputForm = Arr::get( $input, $key ); |
|
52 | + if( !$this->hasMultilingualIntegration( Arr::get( $inputForm, 'multilingual' ) ) ) { |
|
53 | + $options = Arr::set( $options, $key.'.multilingual', '' ); |
|
54 | 54 | } |
55 | - if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
56 | - $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
57 | - $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
55 | + if( '' == trim( Arr::get( $inputForm, 'notification_message' ) ) ) { |
|
56 | + $defaultValue = Arr::get( glsr()->defaults, $key.'.notification_message' ); |
|
57 | + $options = Arr::set( $options, $key.'.notification_message', $defaultValue ); |
|
58 | 58 | } |
59 | - $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
60 | - $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
59 | + $defaultValue = Arr::get( $inputForm, 'notifications', [] ); |
|
60 | + $options = Arr::set( $options, $key.'.notifications', $defaultValue ); |
|
61 | 61 | return $options; |
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @return array |
66 | 66 | */ |
67 | - protected function sanitizeSubmissions(array $input, array $options) |
|
67 | + protected function sanitizeSubmissions( array $input, array $options ) |
|
68 | 68 | { |
69 | 69 | $key = 'settings.submissions'; |
70 | - $inputForm = Arr::get($input, $key); |
|
70 | + $inputForm = Arr::get( $input, $key ); |
|
71 | 71 | $defaultValue = isset($inputForm['required']) |
72 | 72 | ? $inputForm['required'] |
73 | 73 | : []; |
74 | - $options = Arr::set($options, $key.'.required', $defaultValue); |
|
74 | + $options = Arr::set( $options, $key.'.required', $defaultValue ); |
|
75 | 75 | return $options; |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @return array |
80 | 80 | */ |
81 | - protected function sanitizeTranslations(array $input, array $options) |
|
81 | + protected function sanitizeTranslations( array $input, array $options ) |
|
82 | 82 | { |
83 | 83 | $key = 'settings.strings'; |
84 | - $inputForm = Arr::consolidateArray(Arr::get($input, $key)); |
|
85 | - if (!empty($inputForm)) { |
|
86 | - $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
84 | + $inputForm = Arr::consolidateArray( Arr::get( $input, $key ) ); |
|
85 | + if( !empty($inputForm) ) { |
|
86 | + $options = Arr::set( $options, $key, array_values( array_filter( $inputForm ) ) ); |
|
87 | 87 | $allowedTags = [ |
88 | 88 | 'a' => ['class' => [], 'href' => [], 'target' => []], |
89 | 89 | 'span' => ['class' => []], |
90 | 90 | ]; |
91 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
92 | - if (isset($string['s2'])) { |
|
93 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
91 | + array_walk( $options['settings']['strings'], function( &$string ) use ($allowedTags) { |
|
92 | + if( isset($string['s2']) ) { |
|
93 | + $string['s2'] = wp_kses( $string['s2'], $allowedTags ); |
|
94 | 94 | } |
95 | - if (isset($string['p2'])) { |
|
96 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
95 | + if( isset($string['p2']) ) { |
|
96 | + $string['p2'] = wp_kses( $string['p2'], $allowedTags ); |
|
97 | 97 | } |
98 | 98 | }); |
99 | 99 | } |
@@ -103,24 +103,24 @@ discard block |
||
103 | 103 | /** |
104 | 104 | * @return bool |
105 | 105 | */ |
106 | - protected function hasMultilingualIntegration($integration) |
|
106 | + protected function hasMultilingualIntegration( $integration ) |
|
107 | 107 | { |
108 | - if (!in_array($integration, ['polylang', 'wpml'])) { |
|
108 | + if( !in_array( $integration, ['polylang', 'wpml'] ) ) { |
|
109 | 109 | return false; |
110 | 110 | } |
111 | - $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration); |
|
112 | - if (!glsr($integrationClass)->isActive()) { |
|
113 | - glsr(Notice::class)->addError(sprintf( |
|
114 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
115 | - constant($integrationClass.'::PLUGIN_NAME') |
|
116 | - )); |
|
111 | + $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst( $integration ); |
|
112 | + if( !glsr( $integrationClass )->isActive() ) { |
|
113 | + glsr( Notice::class )->addError( sprintf( |
|
114 | + __( 'Please install/activate the %s plugin to enable integration.', 'site-reviews' ), |
|
115 | + constant( $integrationClass.'::PLUGIN_NAME' ) |
|
116 | + ) ); |
|
117 | 117 | return false; |
118 | - } elseif (!glsr($integrationClass)->isSupported()) { |
|
119 | - glsr(Notice::class)->addError(sprintf( |
|
120 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
121 | - constant($integrationClass.'::PLUGIN_NAME'), |
|
122 | - constant($integrationClass.'::SUPPORTED_VERSION') |
|
123 | - )); |
|
118 | + } elseif( !glsr( $integrationClass )->isSupported() ) { |
|
119 | + glsr( Notice::class )->addError( sprintf( |
|
120 | + __( 'Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews' ), |
|
121 | + constant( $integrationClass.'::PLUGIN_NAME' ), |
|
122 | + constant( $integrationClass.'::SUPPORTED_VERSION' ) |
|
123 | + ) ); |
|
124 | 124 | return false; |
125 | 125 | } |
126 | 126 | return true; |