Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/inc/helpers/options.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
3
+
/**
4
+
* Generate a random ID.
5
+
*
6
+
* Keep function_exists() check for some time because Blocksy Companion 1.9
7
+
* framework/helpers/blocksy-integration.php declares it again.
8
+
*/
9
+
if (! function_exists('blocksy_rand_md5')) {
10
+
function blocksy_rand_md5() {
11
+
return md5(time() . '-' . uniqid(wp_rand(), true) . '-' . wp_rand());
12
+
}
13
+
}
14
+
15
+
/**
16
+
* Extract a key from an array with defaults.
17
+
*
18
+
* @param string $keys 'a/b/c' path.
19
+
* @param array|object $array_or_object array to extract from.
20
+
* @param null|mixed $default_value defualt value.
21
+
*
22
+
* Keep function_exists() check for some time because Blocksy Companion 1.9
23
+
* framework/helpers/blocksy-integration.php declares it again.
24
+
*/
25
+
if (! function_exists('blocksy_default_akg')) {
26
+
function blocksy_default_akg($keys, $array_or_object, $default_value) {
27
+
return blocksy_akg($keys, $array_or_object, $default_value);
28
+
}
29
+
}
30
+
31
+
/**
32
+
* Recursively find a key's value in array
33
+
*
34
+
* @param string $keys 'a/b/c' path.
35
+
* @param array|object $array_or_object array to extract from.
36
+
* @param null|mixed $default_value defualt value.
37
+
*
38
+
* @return null|mixed
39
+
*/
40
+
if (! function_exists('blocksy_akg')) {
41
+
function blocksy_akg($keys, $array_or_object, $default_value = null) {
42
+
if (! is_array($keys)) {
43
+
$keys = explode('/', (string) $keys);
44
+
}
45
+
46
+
$array_or_object = $array_or_object;
47
+
$key_or_property = array_shift($keys);
48
+
49
+
if (is_null($key_or_property)) {
50
+
return $default_value;
51
+
}
52
+
53
+
$is_object = is_object($array_or_object);
54
+
55
+
if ($is_object) {
56
+
if (! property_exists($array_or_object, $key_or_property)) {
57
+
return $default_value;
58
+
}
59
+
} else {
60
+
if (! is_array($array_or_object) || ! array_key_exists($key_or_property, $array_or_object)) {
61
+
return $default_value;
62
+
}
63
+
}
64
+
65
+
if (isset($keys[0])) { // not used count() for performance reasons.
66
+
if ($is_object) {
67
+
return blocksy_akg($keys, $array_or_object->{$key_or_property}, $default_value);
68
+
} else {
69
+
return blocksy_akg($keys, $array_or_object[$key_or_property], $default_value);
70
+
}
71
+
} else {
72
+
if ($is_object) {
73
+
return $array_or_object->{$key_or_property};
74
+
} else {
75
+
return $array_or_object[ $key_or_property ];
76
+
}
77
+
}
78
+
}
79
+
}
80
+
81
+
function blocksy_akg_or_customizer($key, $source, $default = null) {
82
+
$source = wp_parse_args(
83
+
$source,
84
+
[
85
+
'prefix' => '',
86
+
87
+
// customizer | array
88
+
'strategy' => 'customizer',
89
+
]
90
+
);
91
+
92
+
if ($source['strategy'] !== 'customizer' && !is_array($source['strategy'])) {
93
+
throw new Error(
94
+
'strategy wrong value provided. Array or customizer is required.'
95
+
);
96
+
}
97
+
98
+
if (! empty($source['prefix'])) {
99
+
$source['prefix'] .= '_';
100
+
}
101
+
102
+
if ($source['strategy'] === 'customizer') {
103
+
return blocksy_get_theme_mod($source['prefix'] . $key, $default);
104
+
}
105
+
106
+
return blocksy_akg($source['prefix'] . $key, $source['strategy'], $default);
107
+
}
108
+
109
+
// When adding new migration, also implement same key in:
110
+
// - static/js/options/containers/MigrateValues.js
111
+
function blocksy_migrate_values($values, $args = []) {
112
+
$args = wp_parse_args($args, [
113
+
'migrations' => []
114
+
]);
115
+
116
+
$new_value = $values;
117
+
118
+
foreach ($args['migrations'] as $migration) {
119
+
if ($migration === 'popups_new_close_actions') {
120
+
if (
121
+
isset($new_value['close_button_type'])
122
+
&&
123
+
$new_value['close_button_type'] === 'none'
124
+
) {
125
+
$new_value['close_button_type'] = 'outside';
126
+
$new_value['popup_close_button'] = 'no';
127
+
}
128
+
129
+
if (isset($new_value['popup_additional_close_strategy'])) {
130
+
$new_value['popup_custom_close'] = 'yes';
131
+
$new_value['popup_custom_close_strategy'] = $new_value['popup_additional_close_strategy'];
132
+
133
+
if (isset($new_value['aditional_close_button_click_selector'])) {
134
+
$new_value['popup_custom_close_button_selector'] = $new_value['aditional_close_button_click_selector'];
135
+
}
136
+
137
+
if (isset($new_value['popup_additional_close_submit_delay'])) {
138
+
$new_value['popup_custom_close_action_delay'] = $new_value['popup_additional_close_submit_delay'];
139
+
}
140
+
141
+
unset($new_value['popup_additional_close_strategy']);
142
+
unset($new_value['aditional_close_button_click_selector']);
143
+
unset($new_value['popup_additional_close_submit_delay']);
144
+
}
145
+
}
146
+
}
147
+
148
+
return $new_value;
149
+
}
150
+