-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
75 lines (64 loc) · 1.97 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
ini_set('xdebug.var_display_max_depth', 50);
if (! function_exists('array_get')) {
function array_get($array, $key, $default = null)
{
if (is_null($key)) {
return $array;
}
if (isset($array[$key])) {
return $array[$key];
}
foreach (explode('.', $key) as $segment) {
if (! is_array($array) || ! array_key_exists($segment, $array)) {
return $default;
}
$array = $array[$segment];
}
return $array;
}
}
if (! function_exists('getField')) {
function getField(array $dataArray, $field_name, $fallback = null)
{
foreach ($dataArray['fields']['data'] as $row) {
if ($row['field']['legacy_id'] == $field_name) {
return $row['markup'];
}
}
return $fallback;
}
}
if (! function_exists('getFieldArray')) {
function getFieldArray($dataArray, $field_name, $fallback = null)
{
foreach ($dataArray['fields']['data'] as $row) {
if ($row['field']['legacy_id'] == $field_name) {
return $row;
}
}
return $fallback;
}
}
if (! function_exists('array_get_from_field_array')) {
function array_get_from_field_array(array $dataArray, $field_name, $key, $default = null)
{
$array = getFieldArray($dataArray, $field_name);
return array_get($array, $key, $default);
}
}
if (! function_exists('escapeJsonString')) {
function escapeJsonString($value)
{
$escapers = ["\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c"];
$replacements = ["\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b"];
$result = str_replace($escapers, $replacements, $value);
return $result;
}
}
if (! function_exists('currentRates')) {
function currentRates()
{
return json_decode(file_get_contents(plugin_dir_path(__FILE__) . '../rates/rates-cache.json'), true);
}
}