PluginProbe
Ultimate Store Kit / 3.0.9
Ultimate Store Kit v3.0.9
3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 92 releases
ultimate-store-kit / base / support / helpers.php

helpers.php in Ultimate Store Kit 3.0.9, at base/support/helpers.php

87 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 wp_kses_post($x);
16 }
17 echo '</pre>';
18 exit;
19 }
20 }
21
22 if (! function_exists('optional')) {
23 /**
24 * Provide access to optional objects.
25 *
26 * @param mixed $value
27 * @param callable|null $callback
28 * @return mixed
29 */
30 function optional($value = null, ?callable $callback = null) {
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 $original = &$array;
51
52 $keys = (array) $keys;
53
54 if (count($keys) === 0) {
55 return;
56 }
57
58 foreach ($keys as $key) {
59 // if the exact key exists in the top-level, remove it
60 if (array_key_exists($key, $array)) {
61 unset($array[$key]);
62
63 continue;
64 }
65
66 $parts = explode('.', $key);
67
68 // clean up before each pass
69 $array = &$original;
70
71 while (count($parts) > 1) {
72 $part = array_shift($parts);
73
74 if (isset($array[$part]) && is_array($array[$part])) {
75 $array = &$array[$part];
76 } else {
77 continue 2;
78 }
79 }
80
81 unset($array[array_shift($parts)]);
82 }
83
84 return $array;
85 }
86 }
87