@@ -6,5 +6,5 @@ |
||
6 | 6 | $baseDir = dirname($vendorDir); |
7 | 7 | |
8 | 8 | return array( |
9 | - 'Wordlift\\Modules\\Include_Exclude\\' => array($baseDir . '/includes'), |
|
9 | + 'Wordlift\\Modules\\Include_Exclude\\' => array($baseDir.'/includes'), |
|
10 | 10 | ); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getPrefixes() |
115 | 115 | { |
116 | - if (!empty($this->prefixesPsr0)) { |
|
116 | + if ( ! empty($this->prefixesPsr0)) { |
|
117 | 117 | return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); |
118 | 118 | } |
119 | 119 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function add($prefix, $paths, $prepend = false) |
185 | 185 | { |
186 | - if (!$prefix) { |
|
186 | + if ( ! $prefix) { |
|
187 | 187 | if ($prepend) { |
188 | 188 | $this->fallbackDirsPsr0 = array_merge( |
189 | 189 | (array) $paths, |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | } |
201 | 201 | |
202 | 202 | $first = $prefix[0]; |
203 | - if (!isset($this->prefixesPsr0[$first][$prefix])) { |
|
203 | + if ( ! isset($this->prefixesPsr0[$first][$prefix])) { |
|
204 | 204 | $this->prefixesPsr0[$first][$prefix] = (array) $paths; |
205 | 205 | |
206 | 206 | return; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | */ |
233 | 233 | public function addPsr4($prefix, $paths, $prepend = false) |
234 | 234 | { |
235 | - if (!$prefix) { |
|
235 | + if ( ! $prefix) { |
|
236 | 236 | // Register directories for the root namespace. |
237 | 237 | if ($prepend) { |
238 | 238 | $this->fallbackDirsPsr4 = array_merge( |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | (array) $paths |
246 | 246 | ); |
247 | 247 | } |
248 | - } elseif (!isset($this->prefixDirsPsr4[$prefix])) { |
|
248 | + } elseif ( ! isset($this->prefixDirsPsr4[$prefix])) { |
|
249 | 249 | // Register directories for a new namespace. |
250 | 250 | $length = strlen($prefix); |
251 | 251 | if ('\\' !== $prefix[$length - 1]) { |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public function set($prefix, $paths) |
281 | 281 | { |
282 | - if (!$prefix) { |
|
282 | + if ( ! $prefix) { |
|
283 | 283 | $this->fallbackDirsPsr0 = (array) $paths; |
284 | 284 | } else { |
285 | 285 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | */ |
300 | 300 | public function setPsr4($prefix, $paths) |
301 | 301 | { |
302 | - if (!$prefix) { |
|
302 | + if ( ! $prefix) { |
|
303 | 303 | $this->fallbackDirsPsr4 = (array) $paths; |
304 | 304 | } else { |
305 | 305 | $length = strlen($prefix); |
@@ -493,18 +493,18 @@ discard block |
||
493 | 493 | private function findFileWithExtension($class, $ext) |
494 | 494 | { |
495 | 495 | // PSR-4 lookup |
496 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
496 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
497 | 497 | |
498 | 498 | $first = $class[0]; |
499 | 499 | if (isset($this->prefixLengthsPsr4[$first])) { |
500 | 500 | $subPath = $class; |
501 | 501 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
502 | 502 | $subPath = substr($subPath, 0, $lastPos); |
503 | - $search = $subPath . '\\'; |
|
503 | + $search = $subPath.'\\'; |
|
504 | 504 | if (isset($this->prefixDirsPsr4[$search])) { |
505 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
505 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
506 | 506 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
507 | - if (file_exists($file = $dir . $pathEnd)) { |
|
507 | + if (file_exists($file = $dir.$pathEnd)) { |
|
508 | 508 | return $file; |
509 | 509 | } |
510 | 510 | } |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | |
515 | 515 | // PSR-4 fallback dirs |
516 | 516 | foreach ($this->fallbackDirsPsr4 as $dir) { |
517 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
517 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
518 | 518 | return $file; |
519 | 519 | } |
520 | 520 | } |
@@ -526,14 +526,14 @@ discard block |
||
526 | 526 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
527 | 527 | } else { |
528 | 528 | // PEAR-like class name |
529 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
529 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | if (isset($this->prefixesPsr0[$first])) { |
533 | 533 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
534 | 534 | if (0 === strpos($class, $prefix)) { |
535 | 535 | foreach ($dirs as $dir) { |
536 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
536 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
537 | 537 | return $file; |
538 | 538 | } |
539 | 539 | } |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | |
544 | 544 | // PSR-0 fallback dirs |
545 | 545 | foreach ($this->fallbackDirsPsr0 as $dir) { |
546 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
546 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
547 | 547 | return $file; |
548 | 548 | } |
549 | 549 | } |
@@ -4,23 +4,23 @@ |
||
4 | 4 | |
5 | 5 | $issues = array(); |
6 | 6 | |
7 | -if (!(PHP_VERSION_ID >= 50600)) { |
|
8 | - $issues[] = 'Your Composer dependencies require a PHP version ">= 5.6.0". You are running ' . PHP_VERSION . '.'; |
|
7 | +if ( ! (PHP_VERSION_ID >= 50600)) { |
|
8 | + $issues[] = 'Your Composer dependencies require a PHP version ">= 5.6.0". You are running '.PHP_VERSION.'.'; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | if ($issues) { |
12 | - if (!headers_sent()) { |
|
12 | + if ( ! headers_sent()) { |
|
13 | 13 | header('HTTP/1.1 500 Internal Server Error'); |
14 | 14 | } |
15 | - if (!ini_get('display_errors')) { |
|
15 | + if ( ! ini_get('display_errors')) { |
|
16 | 16 | if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { |
17 | - fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL); |
|
18 | - } elseif (!headers_sent()) { |
|
19 | - echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; |
|
17 | + fwrite(STDERR, 'Composer detected issues in your platform:'.PHP_EOL.PHP_EOL.implode(PHP_EOL, $issues).PHP_EOL.PHP_EOL); |
|
18 | + } elseif ( ! headers_sent()) { |
|
19 | + echo 'Composer detected issues in your platform:'.PHP_EOL.PHP_EOL.str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)).PHP_EOL.PHP_EOL; |
|
20 | 20 | } |
21 | 21 | } |
22 | 22 | trigger_error( |
23 | - 'Composer detected issues in your platform: ' . implode(' ', $issues), |
|
23 | + 'Composer detected issues in your platform: '.implode(' ', $issues), |
|
24 | 24 | E_USER_ERROR |
25 | 25 | ); |
26 | 26 | } |
@@ -6,5 +6,5 @@ |
||
6 | 6 | $baseDir = dirname($vendorDir); |
7 | 7 | |
8 | 8 | return array( |
9 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
9 | + 'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php', |
|
10 | 10 | ); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | public static function getVersionRanges($packageName) |
138 | 138 | { |
139 | 139 | foreach (self::getInstalled() as $installed) { |
140 | - if (!isset($installed['versions'][$packageName])) { |
|
140 | + if ( ! isset($installed['versions'][$packageName])) { |
|
141 | 141 | continue; |
142 | 142 | } |
143 | 143 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | return implode(' || ', $ranges); |
159 | 159 | } |
160 | 160 | |
161 | - throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
161 | + throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -168,18 +168,18 @@ discard block |
||
168 | 168 | public static function getVersion($packageName) |
169 | 169 | { |
170 | 170 | foreach (self::getInstalled() as $installed) { |
171 | - if (!isset($installed['versions'][$packageName])) { |
|
171 | + if ( ! isset($installed['versions'][$packageName])) { |
|
172 | 172 | continue; |
173 | 173 | } |
174 | 174 | |
175 | - if (!isset($installed['versions'][$packageName]['version'])) { |
|
175 | + if ( ! isset($installed['versions'][$packageName]['version'])) { |
|
176 | 176 | return null; |
177 | 177 | } |
178 | 178 | |
179 | 179 | return $installed['versions'][$packageName]['version']; |
180 | 180 | } |
181 | 181 | |
182 | - throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
182 | + throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed'); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -189,18 +189,18 @@ discard block |
||
189 | 189 | public static function getPrettyVersion($packageName) |
190 | 190 | { |
191 | 191 | foreach (self::getInstalled() as $installed) { |
192 | - if (!isset($installed['versions'][$packageName])) { |
|
192 | + if ( ! isset($installed['versions'][$packageName])) { |
|
193 | 193 | continue; |
194 | 194 | } |
195 | 195 | |
196 | - if (!isset($installed['versions'][$packageName]['pretty_version'])) { |
|
196 | + if ( ! isset($installed['versions'][$packageName]['pretty_version'])) { |
|
197 | 197 | return null; |
198 | 198 | } |
199 | 199 | |
200 | 200 | return $installed['versions'][$packageName]['pretty_version']; |
201 | 201 | } |
202 | 202 | |
203 | - throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
203 | + throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed'); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -210,18 +210,18 @@ discard block |
||
210 | 210 | public static function getReference($packageName) |
211 | 211 | { |
212 | 212 | foreach (self::getInstalled() as $installed) { |
213 | - if (!isset($installed['versions'][$packageName])) { |
|
213 | + if ( ! isset($installed['versions'][$packageName])) { |
|
214 | 214 | continue; |
215 | 215 | } |
216 | 216 | |
217 | - if (!isset($installed['versions'][$packageName]['reference'])) { |
|
217 | + if ( ! isset($installed['versions'][$packageName]['reference'])) { |
|
218 | 218 | return null; |
219 | 219 | } |
220 | 220 | |
221 | 221 | return $installed['versions'][$packageName]['reference']; |
222 | 222 | } |
223 | 223 | |
224 | - throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
224 | + throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed'); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -231,14 +231,14 @@ discard block |
||
231 | 231 | public static function getInstallPath($packageName) |
232 | 232 | { |
233 | 233 | foreach (self::getInstalled() as $installed) { |
234 | - if (!isset($installed['versions'][$packageName])) { |
|
234 | + if ( ! isset($installed['versions'][$packageName])) { |
|
235 | 235 | continue; |
236 | 236 | } |
237 | 237 | |
238 | 238 | return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null; |
239 | 239 | } |
240 | 240 | |
241 | - throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed'); |
|
241 | + throw new \OutOfBoundsException('Package "'.$packageName.'" is not installed'); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | // only require the installed.php file if this file is loaded from its dumped location, |
268 | 268 | // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 |
269 | 269 | if (substr(__DIR__, -8, 1) !== 'C') { |
270 | - self::$installed = include __DIR__ . '/installed.php'; |
|
270 | + self::$installed = include __DIR__.'/installed.php'; |
|
271 | 271 | } else { |
272 | 272 | self::$installed = array(); |
273 | 273 | } |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | // only require the installed.php file if this file is loaded from its dumped location, |
341 | 341 | // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 |
342 | 342 | if (substr(__DIR__, -8, 1) !== 'C') { |
343 | - self::$installed = require __DIR__ . '/installed.php'; |
|
343 | + self::$installed = require __DIR__.'/installed.php'; |
|
344 | 344 | } else { |
345 | 345 | self::$installed = array(); |
346 | 346 | } |
@@ -17,27 +17,27 @@ |
||
17 | 17 | */ |
18 | 18 | class Wordlift_NitroPack_Adapter { |
19 | 19 | |
20 | - /** |
|
21 | - * Register hooks. |
|
22 | - */ |
|
23 | - public function register_hooks() { |
|
24 | - add_filter( 'wl_jsonld_term_html_output', array( $this, 'maybe_exclude_nitropack' ) ); |
|
25 | - add_filter( 'wl_jsonld_post_html_output', array( $this, 'maybe_exclude_nitropack' ) ); |
|
26 | - } |
|
20 | + /** |
|
21 | + * Register hooks. |
|
22 | + */ |
|
23 | + public function register_hooks() { |
|
24 | + add_filter( 'wl_jsonld_term_html_output', array( $this, 'maybe_exclude_nitropack' ) ); |
|
25 | + add_filter( 'wl_jsonld_post_html_output', array( $this, 'maybe_exclude_nitropack' ) ); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Modify JSON-LD if NitroPack active. |
|
30 | - * |
|
31 | - * @param $html |
|
32 | - * |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function maybe_exclude_nitropack( $html ) { |
|
36 | - if ( ! defined( 'NITROPACK_VERSION' ) ) { |
|
37 | - return $html; |
|
38 | - } |
|
28 | + /** |
|
29 | + * Modify JSON-LD if NitroPack active. |
|
30 | + * |
|
31 | + * @param $html |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function maybe_exclude_nitropack( $html ) { |
|
36 | + if ( ! defined( 'NITROPACK_VERSION' ) ) { |
|
37 | + return $html; |
|
38 | + } |
|
39 | 39 | |
40 | - return preg_replace( '@id="wl-jsonld(-term)?"@', 'id="wl-jsonld$1" nitro-exclude', $html ); |
|
41 | - } |
|
40 | + return preg_replace( '@id="wl-jsonld(-term)?"@', 'id="wl-jsonld$1" nitro-exclude', $html ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | * Register hooks. |
22 | 22 | */ |
23 | 23 | public function register_hooks() { |
24 | - add_filter( 'wl_jsonld_term_html_output', array( $this, 'maybe_exclude_nitropack' ) ); |
|
25 | - add_filter( 'wl_jsonld_post_html_output', array( $this, 'maybe_exclude_nitropack' ) ); |
|
24 | + add_filter('wl_jsonld_term_html_output', array($this, 'maybe_exclude_nitropack')); |
|
25 | + add_filter('wl_jsonld_post_html_output', array($this, 'maybe_exclude_nitropack')); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return string |
34 | 34 | */ |
35 | - public function maybe_exclude_nitropack( $html ) { |
|
36 | - if ( ! defined( 'NITROPACK_VERSION' ) ) { |
|
35 | + public function maybe_exclude_nitropack($html) { |
|
36 | + if ( ! defined('NITROPACK_VERSION')) { |
|
37 | 37 | return $html; |
38 | 38 | } |
39 | 39 | |
40 | - return preg_replace( '@id="wl-jsonld(-term)?"@', 'id="wl-jsonld$1" nitro-exclude', $html ); |
|
40 | + return preg_replace('@id="wl-jsonld(-term)?"@', 'id="wl-jsonld$1" nitro-exclude', $html); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | } |
@@ -16,78 +16,78 @@ |
||
16 | 16 | */ |
17 | 17 | class Plugin_Enabled { |
18 | 18 | |
19 | - /** |
|
20 | - * Register hooks. |
|
21 | - */ |
|
22 | - public function register_hooks() { |
|
23 | - add_filter( 'wl_is_enabled', array( $this, 'wl_is_enabled' ) ); |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * Enable/Disable WordLift Plugin. |
|
28 | - * |
|
29 | - * @param $enabled |
|
30 | - * |
|
31 | - * @return bool|mixed |
|
32 | - */ |
|
33 | - public function wl_is_enabled( $enabled ) { |
|
34 | - |
|
35 | - // Always enable wordlift on admin and rest api pages. |
|
36 | - if ( is_admin() || $this->is_rest_request() ) { |
|
37 | - return $enabled; |
|
38 | - } |
|
39 | - |
|
40 | - $path = strtok( (string) $_SERVER['REQUEST_URI'], '?' ); // phpcs:ignore |
|
41 | - $options = get_option( 'wl_exclude_include_urls_settings' ); |
|
42 | - $current_url = trailingslashit( home_url( $path ) ); |
|
43 | - |
|
44 | - // Bail out if URLs are not set. |
|
45 | - if ( empty( $options['urls'] ) ) { |
|
46 | - return $enabled; |
|
47 | - } |
|
48 | - |
|
49 | - // Set a default state. |
|
50 | - $default_state = ( $options['include_exclude'] === 'exclude' ); |
|
51 | - |
|
52 | - // Get URLs into an array from settings, trim them and make absolute if needed. |
|
53 | - $urls = array_map( |
|
54 | - function ( $url ) { |
|
55 | - $url = trim( $url ); |
|
56 | - if ( substr( $url, 0, 4 ) !== 'http' ) { |
|
57 | - return trailingslashit( home_url( $url ) ); |
|
58 | - } |
|
59 | - |
|
60 | - // Add a trailing slash and return the url |
|
61 | - return trailingslashit( $url ); |
|
62 | - }, |
|
63 | - explode( PHP_EOL, $options['urls'] ) |
|
64 | - ); |
|
65 | - |
|
66 | - foreach ( $urls as $url ) { |
|
67 | - if ( $url === $current_url ) { |
|
68 | - return ! $default_state; |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - return $default_state; |
|
73 | - |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * We cant rely on WP_REST_REQUEST constant here since it is loaded after init hook |
|
78 | - * |
|
79 | - * @return bool |
|
80 | - */ |
|
81 | - protected function is_rest_request() { |
|
82 | - if ( empty( $_SERVER['REQUEST_URI'] ) ) { |
|
83 | - // Probably a CLI request. |
|
84 | - return false; |
|
85 | - } |
|
86 | - |
|
87 | - $rest_prefix = trailingslashit( rest_get_url_prefix() ); |
|
88 | - $path = strtok( (string) $_SERVER['REQUEST_URI'], '?' ); // phpcs:ignore |
|
89 | - |
|
90 | - return strpos( $path, $rest_prefix ) !== false; |
|
91 | - } |
|
19 | + /** |
|
20 | + * Register hooks. |
|
21 | + */ |
|
22 | + public function register_hooks() { |
|
23 | + add_filter( 'wl_is_enabled', array( $this, 'wl_is_enabled' ) ); |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * Enable/Disable WordLift Plugin. |
|
28 | + * |
|
29 | + * @param $enabled |
|
30 | + * |
|
31 | + * @return bool|mixed |
|
32 | + */ |
|
33 | + public function wl_is_enabled( $enabled ) { |
|
34 | + |
|
35 | + // Always enable wordlift on admin and rest api pages. |
|
36 | + if ( is_admin() || $this->is_rest_request() ) { |
|
37 | + return $enabled; |
|
38 | + } |
|
39 | + |
|
40 | + $path = strtok( (string) $_SERVER['REQUEST_URI'], '?' ); // phpcs:ignore |
|
41 | + $options = get_option( 'wl_exclude_include_urls_settings' ); |
|
42 | + $current_url = trailingslashit( home_url( $path ) ); |
|
43 | + |
|
44 | + // Bail out if URLs are not set. |
|
45 | + if ( empty( $options['urls'] ) ) { |
|
46 | + return $enabled; |
|
47 | + } |
|
48 | + |
|
49 | + // Set a default state. |
|
50 | + $default_state = ( $options['include_exclude'] === 'exclude' ); |
|
51 | + |
|
52 | + // Get URLs into an array from settings, trim them and make absolute if needed. |
|
53 | + $urls = array_map( |
|
54 | + function ( $url ) { |
|
55 | + $url = trim( $url ); |
|
56 | + if ( substr( $url, 0, 4 ) !== 'http' ) { |
|
57 | + return trailingslashit( home_url( $url ) ); |
|
58 | + } |
|
59 | + |
|
60 | + // Add a trailing slash and return the url |
|
61 | + return trailingslashit( $url ); |
|
62 | + }, |
|
63 | + explode( PHP_EOL, $options['urls'] ) |
|
64 | + ); |
|
65 | + |
|
66 | + foreach ( $urls as $url ) { |
|
67 | + if ( $url === $current_url ) { |
|
68 | + return ! $default_state; |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + return $default_state; |
|
73 | + |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * We cant rely on WP_REST_REQUEST constant here since it is loaded after init hook |
|
78 | + * |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | + protected function is_rest_request() { |
|
82 | + if ( empty( $_SERVER['REQUEST_URI'] ) ) { |
|
83 | + // Probably a CLI request. |
|
84 | + return false; |
|
85 | + } |
|
86 | + |
|
87 | + $rest_prefix = trailingslashit( rest_get_url_prefix() ); |
|
88 | + $path = strtok( (string) $_SERVER['REQUEST_URI'], '?' ); // phpcs:ignore |
|
89 | + |
|
90 | + return strpos( $path, $rest_prefix ) !== false; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * Register hooks. |
21 | 21 | */ |
22 | 22 | public function register_hooks() { |
23 | - add_filter( 'wl_is_enabled', array( $this, 'wl_is_enabled' ) ); |
|
23 | + add_filter('wl_is_enabled', array($this, 'wl_is_enabled')); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -30,41 +30,41 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return bool|mixed |
32 | 32 | */ |
33 | - public function wl_is_enabled( $enabled ) { |
|
33 | + public function wl_is_enabled($enabled) { |
|
34 | 34 | |
35 | 35 | // Always enable wordlift on admin and rest api pages. |
36 | - if ( is_admin() || $this->is_rest_request() ) { |
|
36 | + if (is_admin() || $this->is_rest_request()) { |
|
37 | 37 | return $enabled; |
38 | 38 | } |
39 | 39 | |
40 | - $path = strtok( (string) $_SERVER['REQUEST_URI'], '?' ); // phpcs:ignore |
|
41 | - $options = get_option( 'wl_exclude_include_urls_settings' ); |
|
42 | - $current_url = trailingslashit( home_url( $path ) ); |
|
40 | + $path = strtok((string) $_SERVER['REQUEST_URI'], '?'); // phpcs:ignore |
|
41 | + $options = get_option('wl_exclude_include_urls_settings'); |
|
42 | + $current_url = trailingslashit(home_url($path)); |
|
43 | 43 | |
44 | 44 | // Bail out if URLs are not set. |
45 | - if ( empty( $options['urls'] ) ) { |
|
45 | + if (empty($options['urls'])) { |
|
46 | 46 | return $enabled; |
47 | 47 | } |
48 | 48 | |
49 | 49 | // Set a default state. |
50 | - $default_state = ( $options['include_exclude'] === 'exclude' ); |
|
50 | + $default_state = ($options['include_exclude'] === 'exclude'); |
|
51 | 51 | |
52 | 52 | // Get URLs into an array from settings, trim them and make absolute if needed. |
53 | 53 | $urls = array_map( |
54 | - function ( $url ) { |
|
55 | - $url = trim( $url ); |
|
56 | - if ( substr( $url, 0, 4 ) !== 'http' ) { |
|
57 | - return trailingslashit( home_url( $url ) ); |
|
54 | + function($url) { |
|
55 | + $url = trim($url); |
|
56 | + if (substr($url, 0, 4) !== 'http') { |
|
57 | + return trailingslashit(home_url($url)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Add a trailing slash and return the url |
61 | - return trailingslashit( $url ); |
|
61 | + return trailingslashit($url); |
|
62 | 62 | }, |
63 | - explode( PHP_EOL, $options['urls'] ) |
|
63 | + explode(PHP_EOL, $options['urls']) |
|
64 | 64 | ); |
65 | 65 | |
66 | - foreach ( $urls as $url ) { |
|
67 | - if ( $url === $current_url ) { |
|
66 | + foreach ($urls as $url) { |
|
67 | + if ($url === $current_url) { |
|
68 | 68 | return ! $default_state; |
69 | 69 | } |
70 | 70 | } |
@@ -79,15 +79,15 @@ discard block |
||
79 | 79 | * @return bool |
80 | 80 | */ |
81 | 81 | protected function is_rest_request() { |
82 | - if ( empty( $_SERVER['REQUEST_URI'] ) ) { |
|
82 | + if (empty($_SERVER['REQUEST_URI'])) { |
|
83 | 83 | // Probably a CLI request. |
84 | 84 | return false; |
85 | 85 | } |
86 | 86 | |
87 | - $rest_prefix = trailingslashit( rest_get_url_prefix() ); |
|
88 | - $path = strtok( (string) $_SERVER['REQUEST_URI'], '?' ); // phpcs:ignore |
|
87 | + $rest_prefix = trailingslashit(rest_get_url_prefix()); |
|
88 | + $path = strtok((string) $_SERVER['REQUEST_URI'], '?'); // phpcs:ignore |
|
89 | 89 | |
90 | - return strpos( $path, $rest_prefix ) !== false; |
|
90 | + return strpos($path, $rest_prefix) !== false; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | } |
@@ -4,80 +4,80 @@ |
||
4 | 4 | |
5 | 5 | class Ingredients_API { |
6 | 6 | |
7 | - /** |
|
8 | - * Ingredients Service. |
|
9 | - * |
|
10 | - * @var \Wordlift\Modules\Food_Kg\Services\Ingredients $ingredients_service The Ingredients Service. |
|
11 | - */ |
|
12 | - public $ingredients_service; |
|
7 | + /** |
|
8 | + * Ingredients Service. |
|
9 | + * |
|
10 | + * @var \Wordlift\Modules\Food_Kg\Services\Ingredients $ingredients_service The Ingredients Service. |
|
11 | + */ |
|
12 | + public $ingredients_service; |
|
13 | 13 | |
14 | - public function __construct( $ingredients_service ) { |
|
15 | - $this->ingredients_service = $ingredients_service; |
|
16 | - } |
|
14 | + public function __construct( $ingredients_service ) { |
|
15 | + $this->ingredients_service = $ingredients_service; |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * Register Hooks. |
|
20 | - */ |
|
21 | - public function register_hooks() { |
|
22 | - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
|
23 | - } |
|
18 | + /** |
|
19 | + * Register Hooks. |
|
20 | + */ |
|
21 | + public function register_hooks() { |
|
22 | + add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Register Routes. |
|
27 | - */ |
|
28 | - public function register_routes() { |
|
29 | - register_rest_route( |
|
30 | - WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
31 | - '/ingredients', |
|
32 | - array( |
|
33 | - 'methods' => \WP_REST_Server::READABLE, |
|
34 | - 'callback' => array( $this, 'get_ingredients' ), |
|
35 | - 'permission_callback' => function () { |
|
36 | - return current_user_can( 'manage_options' ); |
|
37 | - }, |
|
38 | - 'args' => array( |
|
39 | - 'per_page' => array( |
|
40 | - 'type' => 'integer', |
|
41 | - 'validate_callback' => 'rest_validate_request_arg', |
|
42 | - 'default' => 20, |
|
43 | - 'minimum' => 1, |
|
44 | - 'maximum' => 100, |
|
45 | - 'sanitize_callback' => 'absint', |
|
46 | - ), |
|
47 | - 'page' => array( |
|
48 | - 'type' => 'integer', |
|
49 | - 'validate_callback' => 'rest_validate_request_arg', |
|
50 | - 'default' => 1, |
|
51 | - 'sanitize_callback' => 'absint', |
|
52 | - ), |
|
53 | - 'offset' => array( |
|
54 | - 'type' => 'integer', |
|
55 | - 'validate_callback' => 'rest_validate_request_arg', |
|
56 | - 'sanitize_callback' => 'absint', |
|
57 | - ), |
|
58 | - ), |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
25 | + /** |
|
26 | + * Register Routes. |
|
27 | + */ |
|
28 | + public function register_routes() { |
|
29 | + register_rest_route( |
|
30 | + WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
31 | + '/ingredients', |
|
32 | + array( |
|
33 | + 'methods' => \WP_REST_Server::READABLE, |
|
34 | + 'callback' => array( $this, 'get_ingredients' ), |
|
35 | + 'permission_callback' => function () { |
|
36 | + return current_user_can( 'manage_options' ); |
|
37 | + }, |
|
38 | + 'args' => array( |
|
39 | + 'per_page' => array( |
|
40 | + 'type' => 'integer', |
|
41 | + 'validate_callback' => 'rest_validate_request_arg', |
|
42 | + 'default' => 20, |
|
43 | + 'minimum' => 1, |
|
44 | + 'maximum' => 100, |
|
45 | + 'sanitize_callback' => 'absint', |
|
46 | + ), |
|
47 | + 'page' => array( |
|
48 | + 'type' => 'integer', |
|
49 | + 'validate_callback' => 'rest_validate_request_arg', |
|
50 | + 'default' => 1, |
|
51 | + 'sanitize_callback' => 'absint', |
|
52 | + ), |
|
53 | + 'offset' => array( |
|
54 | + 'type' => 'integer', |
|
55 | + 'validate_callback' => 'rest_validate_request_arg', |
|
56 | + 'sanitize_callback' => 'absint', |
|
57 | + ), |
|
58 | + ), |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Get Ingredients Data. |
|
65 | - * |
|
66 | - * @param \WP_REST_Request $request The request. |
|
67 | - * |
|
68 | - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
69 | - */ |
|
70 | - public function get_ingredients( \WP_REST_Request $request ) { |
|
71 | - $per_page = $request['per_page']; |
|
72 | - $page = $request['page']; |
|
73 | - $offset = $request['offset']; |
|
63 | + /** |
|
64 | + * Get Ingredients Data. |
|
65 | + * |
|
66 | + * @param \WP_REST_Request $request The request. |
|
67 | + * |
|
68 | + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
69 | + */ |
|
70 | + public function get_ingredients( \WP_REST_Request $request ) { |
|
71 | + $per_page = $request['per_page']; |
|
72 | + $page = $request['page']; |
|
73 | + $offset = $request['offset']; |
|
74 | 74 | |
75 | - if ( ! isset( $offset ) ) { |
|
76 | - $offset = ( $page - 1 ) * $per_page; |
|
77 | - } |
|
75 | + if ( ! isset( $offset ) ) { |
|
76 | + $offset = ( $page - 1 ) * $per_page; |
|
77 | + } |
|
78 | 78 | |
79 | - $data = $this->ingredients_service->get_data( $per_page, $offset ); |
|
79 | + $data = $this->ingredients_service->get_data( $per_page, $offset ); |
|
80 | 80 | |
81 | - return rest_ensure_response( $data ); |
|
82 | - } |
|
81 | + return rest_ensure_response( $data ); |
|
82 | + } |
|
83 | 83 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | public $ingredients_service; |
13 | 13 | |
14 | - public function __construct( $ingredients_service ) { |
|
14 | + public function __construct($ingredients_service) { |
|
15 | 15 | $this->ingredients_service = $ingredients_service; |
16 | 16 | } |
17 | 17 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * Register Hooks. |
20 | 20 | */ |
21 | 21 | public function register_hooks() { |
22 | - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
|
22 | + add_action('rest_api_init', array($this, 'register_routes')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | '/ingredients', |
32 | 32 | array( |
33 | 33 | 'methods' => \WP_REST_Server::READABLE, |
34 | - 'callback' => array( $this, 'get_ingredients' ), |
|
35 | - 'permission_callback' => function () { |
|
36 | - return current_user_can( 'manage_options' ); |
|
34 | + 'callback' => array($this, 'get_ingredients'), |
|
35 | + 'permission_callback' => function() { |
|
36 | + return current_user_can('manage_options'); |
|
37 | 37 | }, |
38 | 38 | 'args' => array( |
39 | 39 | 'per_page' => array( |
@@ -67,17 +67,17 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
69 | 69 | */ |
70 | - public function get_ingredients( \WP_REST_Request $request ) { |
|
70 | + public function get_ingredients(\WP_REST_Request $request) { |
|
71 | 71 | $per_page = $request['per_page']; |
72 | 72 | $page = $request['page']; |
73 | 73 | $offset = $request['offset']; |
74 | 74 | |
75 | - if ( ! isset( $offset ) ) { |
|
76 | - $offset = ( $page - 1 ) * $per_page; |
|
75 | + if ( ! isset($offset)) { |
|
76 | + $offset = ($page - 1) * $per_page; |
|
77 | 77 | } |
78 | 78 | |
79 | - $data = $this->ingredients_service->get_data( $per_page, $offset ); |
|
79 | + $data = $this->ingredients_service->get_data($per_page, $offset); |
|
80 | 80 | |
81 | - return rest_ensure_response( $data ); |
|
81 | + return rest_ensure_response($data); |
|
82 | 82 | } |
83 | 83 | } |
@@ -4,99 +4,99 @@ |
||
4 | 4 | |
5 | 5 | class API { |
6 | 6 | |
7 | - public function register_hooks() { |
|
8 | - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
|
9 | - } |
|
7 | + public function register_hooks() { |
|
8 | + add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
|
9 | + } |
|
10 | 10 | |
11 | - public function register_routes() { |
|
12 | - register_rest_route( |
|
13 | - WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
14 | - '/include-exclude/config', |
|
15 | - array( |
|
16 | - 'methods' => \WP_REST_Server::READABLE, |
|
17 | - 'callback' => array( $this, 'get_include_exclude_data' ), |
|
18 | - 'permission_callback' => function () { |
|
19 | - return current_user_can( 'manage_options' ); |
|
20 | - }, |
|
21 | - ) |
|
22 | - ); |
|
11 | + public function register_routes() { |
|
12 | + register_rest_route( |
|
13 | + WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
14 | + '/include-exclude/config', |
|
15 | + array( |
|
16 | + 'methods' => \WP_REST_Server::READABLE, |
|
17 | + 'callback' => array( $this, 'get_include_exclude_data' ), |
|
18 | + 'permission_callback' => function () { |
|
19 | + return current_user_can( 'manage_options' ); |
|
20 | + }, |
|
21 | + ) |
|
22 | + ); |
|
23 | 23 | |
24 | - register_rest_route( |
|
25 | - WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
26 | - '/include-exclude/config', |
|
27 | - array( |
|
28 | - 'methods' => \WP_REST_Server::EDITABLE, |
|
29 | - 'callback' => array( $this, 'update_include_exclude_data' ), |
|
30 | - 'args' => array( |
|
31 | - 'type' => array( |
|
32 | - 'required' => true, |
|
33 | - 'type' => 'string', |
|
34 | - 'validate_callback' => function ( $param ) { |
|
35 | - if ( empty( $param ) || ! in_array( $param, array( 'include', 'exclude' ), true ) ) { |
|
36 | - return new \WP_Error( |
|
37 | - 'wordlift_invalid_include_exclude_type', |
|
38 | - __( 'type can be either include or exclude.', 'wordlift' ), |
|
39 | - array( |
|
40 | - 'status' => 400, |
|
41 | - ) |
|
42 | - ); |
|
43 | - } |
|
44 | - }, |
|
45 | - ), |
|
46 | - 'urls' => array( |
|
47 | - 'required' => true, |
|
48 | - 'type' => 'string', |
|
49 | - 'validate_callback' => function ( $param ) { |
|
50 | - return is_string( $param ) && ! empty( $param ); |
|
51 | - }, |
|
52 | - ), |
|
53 | - ), |
|
54 | - 'permission_callback' => function () { |
|
55 | - return current_user_can( 'manage_options' ); |
|
56 | - }, |
|
57 | - ) |
|
58 | - ); |
|
59 | - } |
|
24 | + register_rest_route( |
|
25 | + WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
26 | + '/include-exclude/config', |
|
27 | + array( |
|
28 | + 'methods' => \WP_REST_Server::EDITABLE, |
|
29 | + 'callback' => array( $this, 'update_include_exclude_data' ), |
|
30 | + 'args' => array( |
|
31 | + 'type' => array( |
|
32 | + 'required' => true, |
|
33 | + 'type' => 'string', |
|
34 | + 'validate_callback' => function ( $param ) { |
|
35 | + if ( empty( $param ) || ! in_array( $param, array( 'include', 'exclude' ), true ) ) { |
|
36 | + return new \WP_Error( |
|
37 | + 'wordlift_invalid_include_exclude_type', |
|
38 | + __( 'type can be either include or exclude.', 'wordlift' ), |
|
39 | + array( |
|
40 | + 'status' => 400, |
|
41 | + ) |
|
42 | + ); |
|
43 | + } |
|
44 | + }, |
|
45 | + ), |
|
46 | + 'urls' => array( |
|
47 | + 'required' => true, |
|
48 | + 'type' => 'string', |
|
49 | + 'validate_callback' => function ( $param ) { |
|
50 | + return is_string( $param ) && ! empty( $param ); |
|
51 | + }, |
|
52 | + ), |
|
53 | + ), |
|
54 | + 'permission_callback' => function () { |
|
55 | + return current_user_can( 'manage_options' ); |
|
56 | + }, |
|
57 | + ) |
|
58 | + ); |
|
59 | + } |
|
60 | 60 | |
61 | - public function get_include_exclude_data() { |
|
62 | - $include_exclude_data = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
63 | - if ( empty( $include_exclude_data ) || empty( $include_exclude_data['urls'] ) ) { |
|
64 | - return new \WP_Error( |
|
65 | - 'wl_include_exclude_data_not_found', |
|
66 | - __( 'Include/Exclude data not found', 'wordlift' ), |
|
67 | - array( |
|
68 | - 'status' => 404, |
|
69 | - ) |
|
70 | - ); |
|
71 | - } |
|
72 | - $data = array( |
|
73 | - 'type' => $include_exclude_data['include_exclude'], |
|
74 | - 'urls' => $include_exclude_data['urls'], |
|
75 | - ); |
|
61 | + public function get_include_exclude_data() { |
|
62 | + $include_exclude_data = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
63 | + if ( empty( $include_exclude_data ) || empty( $include_exclude_data['urls'] ) ) { |
|
64 | + return new \WP_Error( |
|
65 | + 'wl_include_exclude_data_not_found', |
|
66 | + __( 'Include/Exclude data not found', 'wordlift' ), |
|
67 | + array( |
|
68 | + 'status' => 404, |
|
69 | + ) |
|
70 | + ); |
|
71 | + } |
|
72 | + $data = array( |
|
73 | + 'type' => $include_exclude_data['include_exclude'], |
|
74 | + 'urls' => $include_exclude_data['urls'], |
|
75 | + ); |
|
76 | 76 | |
77 | - return rest_ensure_response( $data ); |
|
78 | - } |
|
77 | + return rest_ensure_response( $data ); |
|
78 | + } |
|
79 | 79 | |
80 | - public function update_include_exclude_data( \WP_REST_Request $request ) { |
|
81 | - $data = $request->get_params(); |
|
80 | + public function update_include_exclude_data( \WP_REST_Request $request ) { |
|
81 | + $data = $request->get_params(); |
|
82 | 82 | |
83 | - $include_exclude_data = array( |
|
84 | - 'include_exclude' => $data['type'], |
|
85 | - 'urls' => $data['urls'], |
|
86 | - ); |
|
83 | + $include_exclude_data = array( |
|
84 | + 'include_exclude' => $data['type'], |
|
85 | + 'urls' => $data['urls'], |
|
86 | + ); |
|
87 | 87 | |
88 | - $updated = update_option( 'wl_exclude_include_urls_settings', $include_exclude_data ); |
|
88 | + $updated = update_option( 'wl_exclude_include_urls_settings', $include_exclude_data ); |
|
89 | 89 | |
90 | - if ( $updated ) { |
|
91 | - return new \WP_REST_Response( null, 204 ); |
|
92 | - } else { |
|
93 | - return new \WP_Error( |
|
94 | - 'wl_include_exclude_data_update_failed', |
|
95 | - __( 'Include/Exclude data update failed.', 'wordlift' ), |
|
96 | - array( |
|
97 | - 'status' => 400, |
|
98 | - ) |
|
99 | - ); |
|
100 | - } |
|
101 | - } |
|
90 | + if ( $updated ) { |
|
91 | + return new \WP_REST_Response( null, 204 ); |
|
92 | + } else { |
|
93 | + return new \WP_Error( |
|
94 | + 'wl_include_exclude_data_update_failed', |
|
95 | + __( 'Include/Exclude data update failed.', 'wordlift' ), |
|
96 | + array( |
|
97 | + 'status' => 400, |
|
98 | + ) |
|
99 | + ); |
|
100 | + } |
|
101 | + } |
|
102 | 102 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | class API { |
6 | 6 | |
7 | 7 | public function register_hooks() { |
8 | - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
|
8 | + add_action('rest_api_init', array($this, 'register_routes')); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | public function register_routes() { |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | '/include-exclude/config', |
15 | 15 | array( |
16 | 16 | 'methods' => \WP_REST_Server::READABLE, |
17 | - 'callback' => array( $this, 'get_include_exclude_data' ), |
|
18 | - 'permission_callback' => function () { |
|
19 | - return current_user_can( 'manage_options' ); |
|
17 | + 'callback' => array($this, 'get_include_exclude_data'), |
|
18 | + 'permission_callback' => function() { |
|
19 | + return current_user_can('manage_options'); |
|
20 | 20 | }, |
21 | 21 | ) |
22 | 22 | ); |
@@ -26,16 +26,16 @@ discard block |
||
26 | 26 | '/include-exclude/config', |
27 | 27 | array( |
28 | 28 | 'methods' => \WP_REST_Server::EDITABLE, |
29 | - 'callback' => array( $this, 'update_include_exclude_data' ), |
|
29 | + 'callback' => array($this, 'update_include_exclude_data'), |
|
30 | 30 | 'args' => array( |
31 | 31 | 'type' => array( |
32 | 32 | 'required' => true, |
33 | 33 | 'type' => 'string', |
34 | - 'validate_callback' => function ( $param ) { |
|
35 | - if ( empty( $param ) || ! in_array( $param, array( 'include', 'exclude' ), true ) ) { |
|
34 | + 'validate_callback' => function($param) { |
|
35 | + if (empty($param) || ! in_array($param, array('include', 'exclude'), true)) { |
|
36 | 36 | return new \WP_Error( |
37 | 37 | 'wordlift_invalid_include_exclude_type', |
38 | - __( 'type can be either include or exclude.', 'wordlift' ), |
|
38 | + __('type can be either include or exclude.', 'wordlift'), |
|
39 | 39 | array( |
40 | 40 | 'status' => 400, |
41 | 41 | ) |
@@ -46,24 +46,24 @@ discard block |
||
46 | 46 | 'urls' => array( |
47 | 47 | 'required' => true, |
48 | 48 | 'type' => 'string', |
49 | - 'validate_callback' => function ( $param ) { |
|
50 | - return is_string( $param ) && ! empty( $param ); |
|
49 | + 'validate_callback' => function($param) { |
|
50 | + return is_string($param) && ! empty($param); |
|
51 | 51 | }, |
52 | 52 | ), |
53 | 53 | ), |
54 | - 'permission_callback' => function () { |
|
55 | - return current_user_can( 'manage_options' ); |
|
54 | + 'permission_callback' => function() { |
|
55 | + return current_user_can('manage_options'); |
|
56 | 56 | }, |
57 | 57 | ) |
58 | 58 | ); |
59 | 59 | } |
60 | 60 | |
61 | 61 | public function get_include_exclude_data() { |
62 | - $include_exclude_data = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
63 | - if ( empty( $include_exclude_data ) || empty( $include_exclude_data['urls'] ) ) { |
|
62 | + $include_exclude_data = get_option('wl_exclude_include_urls_settings', array()); |
|
63 | + if (empty($include_exclude_data) || empty($include_exclude_data['urls'])) { |
|
64 | 64 | return new \WP_Error( |
65 | 65 | 'wl_include_exclude_data_not_found', |
66 | - __( 'Include/Exclude data not found', 'wordlift' ), |
|
66 | + __('Include/Exclude data not found', 'wordlift'), |
|
67 | 67 | array( |
68 | 68 | 'status' => 404, |
69 | 69 | ) |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | 'urls' => $include_exclude_data['urls'], |
75 | 75 | ); |
76 | 76 | |
77 | - return rest_ensure_response( $data ); |
|
77 | + return rest_ensure_response($data); |
|
78 | 78 | } |
79 | 79 | |
80 | - public function update_include_exclude_data( \WP_REST_Request $request ) { |
|
80 | + public function update_include_exclude_data(\WP_REST_Request $request) { |
|
81 | 81 | $data = $request->get_params(); |
82 | 82 | |
83 | 83 | $include_exclude_data = array( |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | 'urls' => $data['urls'], |
86 | 86 | ); |
87 | 87 | |
88 | - $updated = update_option( 'wl_exclude_include_urls_settings', $include_exclude_data ); |
|
88 | + $updated = update_option('wl_exclude_include_urls_settings', $include_exclude_data); |
|
89 | 89 | |
90 | - if ( $updated ) { |
|
91 | - return new \WP_REST_Response( null, 204 ); |
|
90 | + if ($updated) { |
|
91 | + return new \WP_REST_Response(null, 204); |
|
92 | 92 | } else { |
93 | 93 | return new \WP_Error( |
94 | 94 | 'wl_include_exclude_data_update_failed', |
95 | - __( 'Include/Exclude data update failed.', 'wordlift' ), |
|
95 | + __('Include/Exclude data update failed.', 'wordlift'), |
|
96 | 96 | array( |
97 | 97 | 'status' => 400, |
98 | 98 | ) |