| 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 |
} |
| 32 |
|