1
1
<?php
2
2
/**
3
3
* MslsOptions
4
+ *
4
5
* @author Dennis Ploetner <[email protected] >
5
6
* @since 0.9.8
6
7
*/
11
12
12
13
/**
13
14
* General options class
15
+ *
14
16
* @package Msls
15
17
* @property bool $activate_autocomplete
16
18
* @property bool output_current_blog
@@ -29,42 +31,49 @@ class MslsOptions extends MslsGetSet {
29
31
30
32
/**
31
33
* Args
34
+ *
32
35
* @var array
33
36
*/
34
37
protected $ args ;
35
38
36
39
/**
37
40
* Name
41
+ *
38
42
* @var string
39
43
*/
40
44
protected $ name ;
41
45
42
46
/**
43
47
* Exists
48
+ *
44
49
* @var bool
45
50
*/
46
51
protected $ exists = false ;
47
52
48
53
/**
49
54
* Separator
55
+ *
50
56
* @var string
51
57
*/
52
58
protected $ sep = '' ;
53
59
54
60
/**
55
61
* Autoload
62
+ *
56
63
* @var string
57
64
*/
58
65
protected $ autoload = 'yes ' ;
59
66
60
67
/**
61
68
* Available languages
69
+ *
62
70
* @var array
63
71
*/
64
72
private $ available_languages ;
65
73
66
74
/**
67
75
* Rewrite with front
76
+ *
68
77
* @var bool
69
78
*/
70
79
public $ with_front ;
@@ -99,23 +108,23 @@ public static function create( $id = 0 ) {
99
108
$ options = new MslsOptionsPost ( get_queried_object_id () );
100
109
}
101
110
102
- add_filter ( 'check_url ' , [ $ options , 'check_for_blog_slug ' ] , 10 , 2 );
111
+ add_filter ( 'check_url ' , array ( $ options , 'check_for_blog_slug ' ) , 10 , 2 );
103
112
104
113
return $ options ;
105
114
}
106
115
107
116
/**
108
117
* Determines if the current page is the main page (front page, search, 404).
109
- *
110
- * @return boolean
118
+ *
119
+ * @return boolean
111
120
*/
112
121
public static function is_main_page () {
113
122
return is_front_page () || is_search () || is_404 ();
114
123
}
115
124
116
125
/**
117
126
* Determines if the current page is a category, tag or taxonomy page.
118
- *
127
+ *
119
128
* @return boolean
120
129
*/
121
130
public static function is_tax_page () {
@@ -124,7 +133,7 @@ public static function is_tax_page() {
124
133
125
134
/**
126
135
* Determines if the current page is an archive page for a date, author, or any other post type.
127
- *
136
+ *
128
137
* @return boolean
129
138
*/
130
139
public static function is_query_page () {
@@ -142,17 +151,18 @@ public function __construct() {
142
151
143
152
/**
144
153
* Gets an element of arg by index
145
- *
146
- * The returned value will either be cast to the type of `$retval` or, if nothing is set at this index, it will be the value of `$retval`.
147
154
*
148
- * @param int $idx
149
- * @param mixed $val
155
+ * The returned value will either be cast to the type of `$default` or, if nothing is set at this index, it will be the value of `$default`.
156
+ *
157
+ * @param int $index
158
+ * @param mixed $default
150
159
*
151
160
* @return mixed
152
161
*/
153
- public function get_arg ( $ idx , $ val = null ) {
154
- $ arg = isset ( $ this ->args [ $ idx ] ) ? $ this ->args [ $ idx ] : $ val ;
155
- settype ( $ arg , gettype ( $ val ) );
162
+ public function get_arg ( int $ index , $ default = null ) {
163
+ $ arg = $ this ->args [ $ index ] ?? $ default ;
164
+
165
+ settype ( $ arg , gettype ( $ default ) );
156
166
157
167
return $ arg ;
158
168
}
@@ -176,6 +186,7 @@ public function save( $arr ) {
176
186
177
187
/**
178
188
* Delete
189
+ *
179
190
* @codeCoverageIgnore
180
191
*/
181
192
public function delete () {
@@ -200,7 +211,10 @@ public function set( $arr ) {
200
211
/**
201
212
* Mapping for us language code
202
213
*/
203
- $ map = [ 'us ' => 'en_US ' , 'en ' => 'en_US ' ];
214
+ $ map = array (
215
+ 'us ' => 'en_US ' ,
216
+ 'en ' => 'en_US ' ,
217
+ );
204
218
foreach ( $ map as $ old => $ new ) {
205
219
if ( isset ( $ arr [ $ old ] ) ) {
206
220
$ arr [ $ new ] = $ arr [ $ old ];
@@ -229,7 +243,6 @@ public function get_permalink( $language ) {
229
243
* @param string $language
230
244
*
231
245
* @since 0.9.8
232
- *
233
246
*/
234
247
$ postlink = (string ) apply_filters (
235
248
'msls_options_get_permalink ' ,
@@ -253,6 +266,7 @@ public function get_postlink( $language ) {
253
266
254
267
/**
255
268
* Get the queried taxonomy
269
+ *
256
270
* @return string
257
271
*/
258
272
public function get_tax_query () {
@@ -261,6 +275,7 @@ public function get_tax_query() {
261
275
262
276
/**
263
277
* Get current link
278
+ *
264
279
* @return string
265
280
*/
266
281
public function get_current_link () {
@@ -269,6 +284,7 @@ public function get_current_link() {
269
284
270
285
/**
271
286
* Is excluded
287
+ *
272
288
* @return bool
273
289
*/
274
290
public function is_excluded () {
@@ -277,6 +293,7 @@ public function is_excluded() {
277
293
278
294
/**
279
295
* Is content
296
+ *
280
297
* @return bool
281
298
*/
282
299
public function is_content_filter () {
@@ -285,6 +302,7 @@ public function is_content_filter() {
285
302
286
303
/**
287
304
* Get order
305
+ *
288
306
* @return string
289
307
*/
290
308
public function get_order () {
@@ -346,7 +364,6 @@ public function get_flag_url( $language ) {
346
364
* @param string $url
347
365
*
348
366
* @since 0.9.9
349
- *
350
367
*/
351
368
$ url = (string ) apply_filters ( 'msls_options_get_flag_url ' , $ url );
352
369
@@ -359,7 +376,6 @@ public function get_flag_url( $language ) {
359
376
* @param string $language
360
377
*
361
378
* @since 1.0.3
362
- *
363
379
*/
364
380
$ icon = (string ) apply_filters ( 'msls_options_get_flag_icon ' , $ icon , $ language );
365
381
@@ -375,9 +391,9 @@ public function get_flag_url( $language ) {
375
391
*/
376
392
public function get_available_languages () {
377
393
if ( empty ( $ this ->available_languages ) ) {
378
- $ this ->available_languages = [
394
+ $ this ->available_languages = array (
379
395
'en_US ' => __ ( 'American English ' , 'multisite-language-switcher ' ),
380
- ] ;
396
+ ) ;
381
397
382
398
foreach ( get_available_languages () as $ code ) {
383
399
$ this ->available_languages [ esc_attr ( $ code ) ] = format_code_lang ( $ code );
@@ -389,7 +405,6 @@ public function get_available_languages() {
389
405
* @param array $available_languages
390
406
*
391
407
* @since 1.0
392
- *
393
408
*/
394
409
$ this ->available_languages = (array ) apply_filters (
395
410
'msls_options_get_available_languages ' ,
@@ -403,7 +418,7 @@ public function get_available_languages() {
403
418
/**
404
419
* The 'blog'-slug-problem :/
405
420
*
406
- * @param string $url
421
+ * @param string $url
407
422
* @param MslsOptions $options
408
423
*
409
424
* @return string
@@ -443,5 +458,4 @@ public static function check_for_blog_slug( $url, $options ) {
443
458
public function get_icon_type (): string {
444
459
return MslsAdminIcon::TYPE_LABEL === $ this ->admin_display ? MslsAdminIcon::TYPE_LABEL : MslsAdminIcon::TYPE_FLAG ;
445
460
}
446
-
447
461
}
0 commit comments