3
3
class InMap_Helper {
4
4
5
5
static public function make_hash ($ data , $ length = 6 ) {
6
- if (!is_string ($ data )) {
6
+ if (! is_string ($ data )) {
7
7
$ data = json_encode ($ data );
8
8
}
9
9
@@ -18,40 +18,20 @@ static public function site_url($url_path = '') {
18
18
return InMap_Config::get_item ('site_url ' ) . $ url_path ;
19
19
}
20
20
21
- static public function http_url ($ data = array () ) {
22
- return trim (add_query_arg (array_merge (array ( 'inmap_http ' => '1 ' ) , $ data ), home_url ('/ ' )), '/ ' );
21
+ static public function http_url ($ data = [] ) {
22
+ return trim (add_query_arg (array_merge ([ 'inmap_http ' => '1 ' ] , $ data ), home_url ('/ ' )), '/ ' );
23
23
}
24
24
25
- static public function plugin_url ($ file_path = '' , $ plugin_slug = '' ) {
26
- if (!$ plugin_slug ) {
27
- $ plugin_slug = InMap_Config::get_item ('plugin_slug ' );
28
- }
29
-
30
- return plugin_dir_url ('' ) . $ plugin_slug . '/ ' . $ file_path ;
31
- }
32
-
33
- static public function plugin_file_path ($ file_path = '' , $ plugin_slug = '' ) {
34
- if (!$ file_path ) {
35
- $ file_path = InMap_Config::get_item ('plugin_slug ' ) . '.php ' ;
36
- }
37
-
38
- if (!$ plugin_slug ) {
39
- $ plugin_slug = InMap_Config::get_item ('plugin_slug ' );
40
- }
41
-
42
- return $ plugin_slug . '/ ' . $ file_path ;
25
+ static public function plugin_url ($ file_path = '' ) {
26
+ return dirname (plugin_dir_url (__DIR__ )) . '/ ' . $ file_path ;
43
27
}
44
28
45
- static public function asset_url ($ file_path = '' , $ plugin_slug = '' ) {
46
- if (!$ plugin_slug ) {
47
- $ plugin_slug = InMap_Config::get_item ('plugin_slug ' );
48
- }
49
-
50
- return plugin_dir_url ('' ) . $ plugin_slug . '/dist/ ' . $ file_path ;
29
+ static public function asset_url ($ file_path = '' ) {
30
+ return self ::plugin_url ('dist/ ' . $ file_path );
51
31
}
52
32
53
33
static public function plugin_name ($ short = false ) {
54
- if (!$ short ) {
34
+ if (! $ short ) {
55
35
return InMap_Config::get_item ('plugin_name ' );
56
36
} else {
57
37
return InMap_Config::get_item ('plugin_name_short ' );
@@ -79,14 +59,14 @@ static public function plugin_about() {
79
59
80
60
//WP.org Directory Link
81
61
if (InMap_Config::get_item ('directory_url ' ) && $ directory_url = parse_url (InMap_Config::get_item ('directory_url ' ))) {
82
- if (isset ($ directory_url ['host ' ]) && !empty ($ directory_url ['host ' ])) {
62
+ if (isset ($ directory_url ['host ' ]) && ! empty ($ directory_url ['host ' ])) {
83
63
$ out .= ' <li><a href=" ' . InMap_Config::get_item ('directory_url ' ) . '"> ' . $ directory_url ['host ' ] . '</a></li> ' . "\n" ;
84
64
}
85
65
}
86
66
87
67
//GitHub Repo Link
88
68
if ($ github_url = parse_url (InMap_Config::get_item ('github_url ' ))) {
89
- if (isset ($ github_url ['host ' ]) && !empty ($ github_url ['host ' ])) {
69
+ if (isset ($ github_url ['host ' ]) && ! empty ($ github_url ['host ' ])) {
90
70
$ out .= ' <li><a href=" ' . InMap_Config::get_item ('github_url ' ) . '"> ' . $ github_url ['host ' ] . '</a></li> ' . "\n" ;
91
71
}
92
72
}
@@ -110,17 +90,17 @@ static public function do_debug() {
110
90
}
111
91
112
92
static public function debug ($ thing , $ die = false ) {
113
- if (!self ::do_debug ()) {
93
+ if (! self ::do_debug ()) {
114
94
return ;
115
95
}
116
96
117
- if (!$ die ) {
97
+ if (! $ die ) {
118
98
echo '<textarea onclick="jQuery(this).hide()" style="background:rgba(255,255,255,.8);position:absolute;top:30px;right:0;width:400px;height:400px;padding:15px;z-index:+10000000"><pre> ' ;
119
99
}
120
100
121
101
print_r ($ thing );
122
102
123
- if (!$ die ) {
103
+ if (! $ die ) {
124
104
echo '</pre></textarea> ' ;
125
105
} else {
126
106
die;
@@ -135,7 +115,7 @@ static public function make_key($str, $prefix = '', $use_underscores = true) {
135
115
}
136
116
137
117
//Like in JS
138
- if (!$ use_underscores ) {
118
+ if (! $ use_underscores ) {
139
119
$ str = str_replace ('_ ' , '' , $ str );
140
120
}
141
121
@@ -151,15 +131,15 @@ static public function anchor_urls(string $text) {
151
131
}
152
132
153
133
public static function convert_values_to_single_value ($ array_in ) {
154
- $ array_out = array () ;
134
+ $ array_out = [] ;
155
135
156
- if (!is_array ($ array_in )) {
136
+ if (! is_array ($ array_in )) {
157
137
return $ array_out ;
158
138
}
159
139
160
140
foreach ($ array_in as $ key => $ value ) {
161
141
//Single value
162
- if (!is_array ($ value )) {
142
+ if (! is_array ($ value )) {
163
143
//Use that
164
144
$ array_out [$ key ] = $ value ;
165
145
//Multiple values
@@ -175,7 +155,7 @@ public static function convert_values_to_single_value($array_in) {
175
155
public static function convert_single_value_to_array ($ value_in ) {
176
156
//Array
177
157
if (is_array ($ value_in )) {
178
- $ array_out = array () ;
158
+ $ array_out = [] ;
179
159
180
160
foreach ($ value_in as $ key => $ value ) {
181
161
$ multi = explode (InMap_Config::get_item ('multi_value_seperator ' ), $ value );
@@ -212,23 +192,23 @@ public static function css_prefix($text = '') {
212
192
public static function slug_prefix ($ text = '' , $ sep = '_ ' , $ hyphen = true ) {
213
193
$ out = InMap_Config::get_item ('plugin_slug ' ) . $ sep . $ text ;
214
194
215
- if (!$ hyphen ) {
195
+ if (! $ hyphen ) {
216
196
$ out = str_replace ('- ' , '_ ' , $ out );
217
197
}
218
198
219
199
return $ out ;
220
200
}
221
201
222
202
public static function array_string_to_array ($ string ) {
223
- $ string = str_replace (array ( '[ ' , '] ' , '" ' , '" ' ), array ( '' , '' , '' , '' ) , $ string );
203
+ $ string = str_replace ([ '[ ' , '] ' , '" ' , '" ' ], [ '' , '' , '' , '' ] , $ string );
224
204
225
205
return self ::comma_string_to_array ($ string );
226
206
}
227
207
228
208
public static function comma_string_to_array ($ string ) {
229
209
//Process options
230
210
$ options_exploded = explode (', ' , $ string );
231
- $ options_array = array () ;
211
+ $ options_array = [] ;
232
212
foreach ($ options_exploded as $ option ) {
233
213
$ value = trim ($ option );
234
214
$ key = self ::make_key ($ value );
@@ -240,7 +220,7 @@ public static function comma_string_to_array($string) {
240
220
}
241
221
242
222
public static function multi_use_as_key ($ array_in , $ as_key = false ) {
243
- $ array_out = array () ;
223
+ $ array_out = [] ;
244
224
245
225
$ count = 0 ;
246
226
foreach ($ array_in as $ data ) {
@@ -259,7 +239,7 @@ public static function multi_use_as_key($array_in, $as_key = false) {
259
239
}
260
240
261
241
static public function flatten_meta ($ data_in ) {
262
- $ data_out = array () ;
242
+ $ data_out = [] ;
263
243
264
244
if (is_array ($ data_in )) {
265
245
foreach ($ data_in as $ data_key => $ data_value ) {
@@ -271,10 +251,10 @@ static public function flatten_meta($data_in) {
271
251
}
272
252
273
253
static public function repeatable_setting_option_array ($ tab , $ section , $ key ) {
274
- $ options_array = array () ;
254
+ $ options_array = [] ;
275
255
$ values = InMap_Config::get_item ($ tab , $ section , true );
276
256
277
- if (!is_array ($ values )) {
257
+ if (! is_array ($ values )) {
278
258
return null ;
279
259
}
280
260
@@ -290,7 +270,7 @@ static public function repeatable_setting_option_array($tab, $section, $key) {
290
270
}
291
271
292
272
public static function assoc_array_table ($ assoc_array ) {
293
- if (!is_array ($ assoc_array ) || !sizeof ($ assoc_array )) {
273
+ if (! is_array ($ assoc_array ) || ! sizeof ($ assoc_array )) {
294
274
return false ;
295
275
}
296
276
@@ -329,7 +309,7 @@ static function time_ago($time = '0', $comparison = false) {
329
309
__ ('Years ' , InMap_Config::get_item ('plugin_text_domain ' )),
330
310
];
331
311
332
- $ lengths = array ( "60 " , "60 " , "24 " , "7 " , "4.35 " , "12 " , "365 " ) ;
312
+ $ lengths = [ "60 " , "60 " , "24 " , "7 " , "4.35 " , "12 " , "365 " ] ;
333
313
334
314
$ now = time ();
335
315
if ($ comparison && ($ now >= $ comparison )) {
0 commit comments