| @@ -1,88 +1,31 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -use UltimateStoreKit\Base\Support\Optional; | |
| 4 | - | |
| 5 | -if(!function_exists('dd')){ | |
| 6 | - | |
| 7 | - /** | |
| 8 | - * dump & die. | |
| 9 | - */ | |
| 10 | - function dd( $x ) { | |
| 11 | - echo '<pre>'; | |
| 12 | - if ( is_array( $x ) || is_object( $x ) ) { | |
| 13 | - print_r( $x ); | |
| 14 | - } else { | |
| 15 | - echo $x; | |
| 16 | - } | |
| 17 | - echo '</pre>';exit; | |
| 18 | - } | |
| 19 | -} | |
| 20 | - | |
| 21 | -if (! function_exists('optional')) { | |
| 22 | - /** | |
| 23 | - * Provide access to optional objects. | |
| 24 | - * | |
| 25 | - * @param mixed $value | |
| 26 | - * @param callable|null $callback | |
| 27 | - * @return mixed | |
| 28 | - */ | |
| 29 | - function optional($value = null, callable $callback = null) | |
| 30 | - { | |
| 31 | - if (is_null($callback)) { | |
| 32 | - return new Optional($value); | |
| 33 | - } elseif (! is_null($value)) { | |
| 34 | - return $callback($value); | |
| 35 | - } | |
| 36 | - } | |
| 37 | -} | |
| 38 | - | |
| 39 | - | |
| 40 | -if (! function_exists('array_except')) { | |
| 41 | - /** | |
| 42 | - * Provide access to optional objects. | |
| 43 | - * | |
| 44 | - * @param mixed $value | |
| 45 | - * @param callable|null $callback | |
| 46 | - * @return mixed | |
| 47 | - */ | |
| 48 | - function array_except($array, $keys) | |
| 49 | - { | |
| 50 | - | |
| 51 | - $original = &$array; | |
| 52 | - | |
| 53 | - $keys = (array) $keys; | |
| 54 | - | |
| 55 | - if (count($keys) === 0) { | |
| 56 | - return; | |
| 57 | - } | |
| 58 | - | |
| 59 | - foreach ($keys as $key) { | |
| 60 | - // if the exact key exists in the top-level, remove it | |
| 61 | - if (array_key_exists($key, $array)) { | |
| 62 | - unset($array[$key]); | |
| 63 | - | |
| 64 | - continue; | |
| 65 | - } | |
| 66 | - | |
| 67 | - $parts = explode('.', $key); | |
| 68 | - | |
| 69 | - // clean up before each pass | |
| 70 | - $array = &$original; | |
| 71 | - | |
| 72 | - while (count($parts) > 1) { | |
| 73 | - $part = array_shift($parts); | |
| 74 | - | |
| 75 | - if (isset($array[$part]) && is_array($array[$part])) { | |
| 76 | - $array = &$array[$part]; | |
| 77 | - } else { | |
| 78 | - continue 2; | |
| 79 | - } | |
| 80 | - } | |
| 81 | - | |
| 82 | - unset($array[array_shift($parts)]); | |
| 83 | - } | |
| 84 | - | |
| 85 | - return $array; | |
| 86 | - } | |
| 87 | -} | |
| 88 | - | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +if (! defined('ABSPATH')) { | |
| 4 | + exit; // Exit if accessed directly | |
| 5 | +} | |
| 6 | + | |
| 7 | +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals -- usk_ / BDTUSK_ / ultimate-store-kit- are this plugin's established public prefixes. Ultimate Store Kit Pro calls into these names, as does third-party integration code, so renaming them is a breaking change. Plugin Check only recognises prefixes derived verbatim from the slug and so reports them as unprefixed. | |
| 8 | + | |
| 9 | +use UltimateStoreKit\Base\Support\Optional; | |
| 10 | + | |
| 11 | +if (! function_exists('ultimate_store_kit_optional')) { | |
| 12 | + /** | |
| 13 | + * Provide access to optional objects. | |
| 14 | + * | |
| 15 | + * Named ultimate_store_kit_optional() rather than optional(): the unprefixed name is the | |
| 16 | + * Laravel helper, which any plugin bundling illuminate/support also declares. | |
| 17 | + * Behind a function_exists() guard the first declaration wins, so an | |
| 18 | + * unprefixed version would silently hand this plugin a foreign Optional class. | |
| 19 | + * | |
| 20 | + * @param mixed $value | |
| 21 | + * @param callable|null $callback | |
| 22 | + * @return mixed | |
| 23 | + */ | |
| 24 | + function ultimate_store_kit_optional($value = null, ?callable $callback = null) { | |
| 25 | + if (is_null($callback)) { | |
| 26 | + return new Optional($value); | |
| 27 | + } elseif (! is_null($value)) { | |
| 28 | + return $callback($value); | |
| 29 | + } | |
| 30 | + } | |
| 31 | +} | |