@@ -49,17 +49,16 @@ public static function init() {
49
49
* @param string $capability
50
50
*
51
51
* @since 2.0
52
- *
53
52
*/
54
53
$ caps = apply_filters ( 'msls_admin_caps ' , 'manage_options ' );
55
54
if ( current_user_can ( $ caps ) ) {
56
55
$ title = __ ( 'Multisite Language Switcher ' , 'multisite-language-switcher ' );
57
- add_options_page ( $ title , $ title , 'manage_options ' , $ obj ->get_menu_slug (), [ $ obj , 'render ' ] );
56
+ add_options_page ( $ title , $ title , 'manage_options ' , $ obj ->get_menu_slug (), array ( $ obj , 'render ' ) );
58
57
59
- add_action ( 'admin_init ' , [ $ obj , 'register ' ] );
60
- add_action ( 'admin_notices ' , [ $ obj , 'has_problems ' ] );
58
+ add_action ( 'admin_init ' , array ( $ obj , 'register ' ) );
59
+ add_action ( 'admin_notices ' , array ( $ obj , 'has_problems ' ) );
61
60
62
- add_filter ( 'msls_admin_validate ' , [ $ obj , 'set_blog_language ' ] );
61
+ add_filter ( 'msls_admin_validate ' , array ( $ obj , 'set_blog_language ' ) );
63
62
}
64
63
}
65
64
@@ -88,32 +87,41 @@ public function get_options_page_link() {
88
87
* You can use every method of the decorated object
89
88
*
90
89
* @param string $method
91
- * @param mixed $args
90
+ * @param mixed $args
92
91
*
93
92
* @return mixed
94
93
*/
95
94
public function __call ( $ method , $ args ) {
96
95
$ parts = explode ( '_ ' , $ method , 2 );
97
96
98
97
if ( is_array ( $ parts ) && 'rewrite ' === $ parts [0 ] ) {
99
- return $ this ->render_rewrite ( $ parts [1 ] );
98
+ $ this ->render_rewrite ( $ parts [1 ] );
99
+ return ;
100
100
}
101
101
102
- $ checkboxes = [
103
- 'activate_autocomplete ' => __ ( 'Activate experimental autocomplete inputs ' ,
104
- 'multisite-language-switcher ' ),
105
- 'activate_content_import ' => __ ( 'Activate the content import functionality ' ,
106
- 'multisite-language-switcher ' ),
102
+ $ checkboxes = array (
103
+ 'activate_autocomplete ' => __ (
104
+ 'Activate experimental autocomplete inputs ' ,
105
+ 'multisite-language-switcher '
106
+ ),
107
+ 'activate_content_import ' => __ (
108
+ 'Activate the content import functionality ' ,
109
+ 'multisite-language-switcher '
110
+ ),
107
111
'sort_by_description ' => __ ( 'Sort languages by description ' , 'multisite-language-switcher ' ),
108
112
'exclude_current_blog ' => __ ( 'Exclude this blog from output ' , 'multisite-language-switcher ' ),
109
113
'only_with_translation ' => __ ( 'Show only links with a translation ' , 'multisite-language-switcher ' ),
110
114
'output_current_blog ' => __ ( 'Display link to the current language ' , 'multisite-language-switcher ' ),
111
115
'content_filter ' => __ ( 'Add hint for available translations ' , 'multisite-language-switcher ' ),
112
- ] ;
116
+ ) ;
113
117
114
- if ( isset ( $ checkboxes [ $ method ] ) ) {
115
- echo ( new Group () )->add ( new Checkbox ( $ method , $ this ->options ->$ method ) )->add ( new Label ( $ method ,
116
- $ checkboxes [ $ method ] ) )->render ();
118
+ if ( isset ( $ checkboxes [ $ method ] ) ) {
119
+ echo ( new Group () )->add ( new Checkbox ( $ method , $ this ->options ->$ method ) )->add (
120
+ new Label (
121
+ $ method ,
122
+ $ checkboxes [ $ method ]
123
+ )
124
+ )->render ();
117
125
} else {
118
126
$ value = ! empty ( $ this ->options ->$ method ) ? $ this ->options ->$ method : '' ;
119
127
echo ( new Text ( $ method , $ value ) )->render ();
@@ -122,21 +130,26 @@ public function __call( $method, $args ) {
122
130
123
131
/**
124
132
* There is something wrong? Here comes the message...
133
+ *
125
134
* @return bool
126
135
*/
127
- public function has_problems () {
136
+ public function has_problems (): bool {
128
137
$ message = '' ;
129
138
130
139
if ( $ this ->options ->is_empty () ) {
131
140
$ message = sprintf (
132
- __ ( 'Multisite Language Switcher is almost ready. You must <a href="%s">complete the configuration process</a>. ' ,
133
- 'multisite-language-switcher ' ),
141
+ __ (
142
+ 'Multisite Language Switcher is almost ready. You must <a href="%s">complete the configuration process</a>. ' ,
143
+ 'multisite-language-switcher '
144
+ ),
134
145
esc_url ( admin_url ( $ this ->get_options_page_link () ) )
135
146
);
136
147
} elseif ( 1 == count ( $ this ->options ->get_available_languages () ) ) {
137
148
$ message = sprintf (
138
- __ ( 'There are no language files installed. You can <a href="%s">manually install some language files</a> or you could use a <a href="%s">plugin</a> to download these files automatically. ' ,
139
- 'multisite-language-switcher ' ),
149
+ __ (
150
+ 'There are no language files installed. You can <a href="%1$s">manually install some language files</a> or you could use a <a href="%2$s">plugin</a> to download these files automatically. ' ,
151
+ 'multisite-language-switcher '
152
+ ),
140
153
esc_url ( 'http://codex.wordpress.org/Installing_WordPress_in_Your_Language#Manually_Installing_Language_Files ' ),
141
154
esc_url ( 'http://wordpress.org/plugins/wp-native-dashboard/ ' )
142
155
);
@@ -148,43 +161,50 @@ public function has_problems() {
148
161
/**
149
162
* Render the options-page
150
163
*/
151
- public function render () {
164
+ public function render (): void {
152
165
printf (
153
166
'<div class="wrap"><div class="icon32" id="icon-options-general"><br/></div><h1>%s</h1>%s<br class="clear"/><form action="options.php" method="post"><p>%s</p> ' ,
154
167
__ ( 'Multisite Language Switcher Options ' , 'multisite-language-switcher ' ),
155
168
$ this ->subsubsub (),
156
- __ ( 'To achieve maximum flexibility, you have to configure each blog separately. ' ,
157
- 'multisite-language-switcher ' )
169
+ __ (
170
+ 'To achieve maximum flexibility, you have to configure each blog separately. ' ,
171
+ 'multisite-language-switcher '
172
+ )
158
173
);
159
174
160
175
settings_fields ( 'msls ' );
161
176
do_settings_sections ( __CLASS__ );
162
177
163
178
printf (
164
179
'<p class="submit"><input name="Submit" type="submit" class="button button-primary" value="%s" /></p></form></div> ' ,
165
- ( $ this ->options ->is_empty () ? __ ( 'Configure ' , 'multisite-language-switcher ' ) : __ ( 'Update ' ,
166
- 'multisite-language-switcher ' ) )
180
+ ( $ this ->options ->is_empty () ? __ ( 'Configure ' , 'multisite-language-switcher ' ) : __ (
181
+ 'Update ' ,
182
+ 'multisite-language-switcher '
183
+ ) )
167
184
);
168
185
}
169
186
170
187
171
188
/**
172
189
* Create a submenu which contains links to all blogs of the current user
190
+ *
173
191
* @return string
174
192
*/
175
193
public function subsubsub () {
176
194
$ icon_type = $ this ->options ->get_icon_type ();
177
195
178
- $ arr = [] ;
196
+ $ arr = array () ;
179
197
foreach ( $ this ->collection ->get_plugin_active_blogs () as $ blog ) {
180
198
$ admin_url = get_admin_url ( $ blog ->userblog_id , $ this ->get_options_page_link () );
181
199
$ current = $ blog ->userblog_id == $ this ->collection ->get_current_blog_id () ? ' class="current" ' : '' ;
182
200
183
201
$ arr [] = sprintf ( '<a href="%1$s"%2$s>%3$s</a> ' , $ admin_url , $ current , $ blog ->get_title ( $ icon_type ) );
184
202
}
185
203
186
- return empty ( $ arr ) ? '' : sprintf ( '<ul class="subsubsub"><li>%s</li></ul> ' ,
187
- implode ( ' | </li><li> ' , $ arr ) );
204
+ return empty ( $ arr ) ? '' : sprintf (
205
+ '<ul class="subsubsub"><li>%s</li></ul> ' ,
206
+ implode ( ' | </li><li> ' , $ arr )
207
+ );
188
208
}
189
209
190
210
/**
@@ -193,21 +213,21 @@ public function subsubsub() {
193
213
* @codeCoverageIgnore
194
214
*/
195
215
public function register () {
196
- register_setting ( 'msls ' , 'msls ' , [ $ this , 'validate ' ] );
216
+ register_setting ( 'msls ' , 'msls ' , array ( $ this , 'validate ' ) );
197
217
198
- $ sections = [
218
+ $ sections = array (
199
219
'language_section ' => __ ( 'Language Settings ' , 'multisite-language-switcher ' ),
200
220
'main_section ' => __ ( 'Main Settings ' , 'multisite-language-switcher ' ),
201
221
'advanced_section ' => __ ( 'Advanced Settings ' , 'multisite-language-switcher ' ),
202
- ] ;
222
+ ) ;
203
223
204
224
global $ wp_rewrite ;
205
225
if ( $ wp_rewrite ->using_permalinks () ) {
206
226
$ sections ['rewrites_section ' ] = __ ( 'Rewrites Settings ' , 'multisite-language-switcher ' );
207
227
}
208
228
209
229
foreach ( $ sections as $ id => $ title ) {
210
- add_settings_section ( $ id , $ title , [ $ this , $ id ] , __CLASS__ );
230
+ add_settings_section ( $ id , $ title , array ( $ this , $ id ) , __CLASS__ );
211
231
}
212
232
213
233
/**
@@ -216,7 +236,6 @@ public function register() {
216
236
* @param string $page
217
237
*
218
238
* @since 1.0
219
- *
220
239
*/
221
240
do_action ( 'msls_admin_register ' , __CLASS__ );
222
241
}
@@ -229,7 +248,7 @@ public function register() {
229
248
* @return int
230
249
*/
231
250
public function language_section (): int {
232
- $ map = [ 'blog_language ' => __ ( 'Blog Language ' , 'multisite-language-switcher ' ) ] ;
251
+ $ map = array ( 'blog_language ' => __ ( 'Blog Language ' , 'multisite-language-switcher ' ) ) ;
233
252
234
253
return $ this ->add_settings_fields ( $ map , 'language_section ' );
235
254
}
@@ -242,7 +261,7 @@ public function language_section(): int {
242
261
* @return int
243
262
*/
244
263
public function main_section (): int {
245
- $ map = [
264
+ $ map = array (
246
265
'display ' => __ ( 'Display ' , 'multisite-language-switcher ' ),
247
266
'admin_display ' => __ ( 'Admin Display ' , 'multisite-language-switcher ' ),
248
267
'sort_by_description ' => __ ( 'Sort languages ' , 'multisite-language-switcher ' ),
@@ -255,7 +274,7 @@ public function main_section(): int {
255
274
'after_item ' => __ ( 'Text/HTML after each item ' , 'multisite-language-switcher ' ),
256
275
'content_filter ' => __ ( 'Available translations hint ' , 'multisite-language-switcher ' ),
257
276
'content_priority ' => __ ( 'Hint priority ' , 'multisite-language-switcher ' ),
258
- ] ;
277
+ ) ;
259
278
260
279
return $ this ->add_settings_fields ( $ map , 'main_section ' );
261
280
}
@@ -268,13 +287,13 @@ public function main_section(): int {
268
287
* @return int
269
288
*/
270
289
public function advanced_section (): int {
271
- $ map = [
290
+ $ map = array (
272
291
'activate_autocomplete ' => __ ( 'Autocomplete ' , 'multisite-language-switcher ' ),
273
292
'image_url ' => __ ( 'Custom URL for flag-images ' , 'multisite-language-switcher ' ),
274
293
'reference_user ' => __ ( 'Reference user ' , 'multisite-language-switcher ' ),
275
294
'exclude_current_blog ' => __ ( 'Exclude blog ' , 'multisite-language-switcher ' ),
276
295
'activate_content_import ' => __ ( 'Content import ' , 'multisite-language-switcher ' ),
277
- ] ;
296
+ ) ;
278
297
279
298
return $ this ->add_settings_fields ( $ map , 'advanced_section ' );
280
299
}
@@ -287,23 +306,23 @@ public function advanced_section(): int {
287
306
* @return int
288
307
*/
289
308
public function rewrites_section (): int {
290
- $ map = [] ;
291
- foreach ( get_post_types ( [ 'public ' => true ] , 'objects ' ) as $ key => $ object ) {
292
- $ map ["rewrite_ {$ key }" ] = sprintf ( __ ( '%s Slug ' , 'multisite-language-switcher ' ), $ object ->label );
309
+ $ map = array () ;
310
+ foreach ( get_post_types ( array ( 'public ' => true ) , 'objects ' ) as $ key => $ object ) {
311
+ $ map [ "rewrite_ {$ key }" ] = sprintf ( __ ( '%s Slug ' , 'multisite-language-switcher ' ), $ object ->label );
293
312
}
294
313
295
314
return $ this ->add_settings_fields ( $ map , 'rewrites_section ' );
296
315
}
297
316
298
317
/**
299
- * @param array $map
318
+ * @param array $map
300
319
* @param string $section
301
320
*
302
321
* @return int
303
322
*/
304
323
protected function add_settings_fields ( array $ map , string $ section ): int {
305
324
foreach ( $ map as $ id => $ title ) {
306
- add_settings_field ( $ id , $ title , [ $ this , $ id ] , __CLASS__ , $ section , [ 'label_for ' => $ id ] );
325
+ add_settings_field ( $ id , $ title , array ( $ this , $ id ) , __CLASS__ , $ section , array ( 'label_for ' => $ id ) );
307
326
}
308
327
309
328
/**
@@ -313,7 +332,6 @@ protected function add_settings_fields( array $map, string $section ): int {
313
332
* @param string $section
314
333
*
315
334
* @since 2.4.4
316
- *
317
335
*/
318
336
do_action ( "msls_admin_ {$ section }" , __CLASS__ , $ section );
319
337
@@ -341,30 +359,34 @@ public function display() {
341
359
* Shows the select-form-field 'admin_display'
342
360
*/
343
361
public function admin_display () {
344
- echo ( new Select ( 'admin_display ' ,
362
+ echo ( new Select (
363
+ 'admin_display ' ,
345
364
array (
346
365
'flag ' => __ ( 'Flag ' , 'multisite-language-switcher ' ),
347
- 'label ' => __ ( 'Label ' , 'multisite-language-switcher ' )
366
+ 'label ' => __ ( 'Label ' , 'multisite-language-switcher ' ),
348
367
),
349
- $ this ->options ->admin_display ) )->render ();
368
+ $ this ->options ->admin_display
369
+ ) )->render ();
350
370
}
351
371
352
372
/**
353
373
* Shows the select-form-field 'reference_user'
354
374
*/
355
375
public function reference_user () {
356
- $ users = [] ;
376
+ $ users = array () ;
357
377
358
- foreach ( ( array ) apply_filters ( 'msls_reference_users ' , $ this ->collection ->get_users () ) as $ user ) {
378
+ foreach ( (array ) apply_filters ( 'msls_reference_users ' , $ this ->collection ->get_users () ) as $ user ) {
359
379
$ users [ $ user ->ID ] = $ user ->user_nicename ;
360
380
}
361
381
362
382
if ( count ( $ users ) > self ::MAX_REFERENCE_USERS ) {
363
383
$ users = array_slice ( $ users , 0 , self ::MAX_REFERENCE_USERS , true );
364
384
365
385
$ message = sprintf (
366
- __ ( 'Multisite Language Switcher: Collection for reference user has been truncated because it exceeded the maximum of %s users. Please, use the hook "msls_reference_users" to filter the result before! ' ,
367
- 'multisite-language-switcher ' ),
386
+ __ (
387
+ 'Multisite Language Switcher: Collection for reference user has been truncated because it exceeded the maximum of %s users. Please, use the hook "msls_reference_users" to filter the result before! ' ,
388
+ 'multisite-language-switcher '
389
+ ),
368
390
self ::MAX_REFERENCE_USERS
369
391
);
370
392
trigger_error ( $ message );
@@ -390,7 +412,7 @@ public function description() {
390
412
* for the output
391
413
*/
392
414
public function content_priority () {
393
- $ temp = array_merge ( range ( 1 , 10 ), [ 20 , 50 , 100 ] );
415
+ $ temp = array_merge ( range ( 1 , 10 ), array ( 20 , 50 , 100 ) );
394
416
$ arr = array_combine ( $ temp , $ temp );
395
417
$ selected = empty ( $ this ->options ->content_priority ) ? 10 : $ this ->options ->content_priority ;
396
418
@@ -429,7 +451,6 @@ public function validate( array $arr ) {
429
451
* @param array $arr
430
452
*
431
453
* @since 1.0
432
- *
433
454
*/
434
455
$ arr = (array ) apply_filters ( 'msls_admin_validate ' , $ arr );
435
456
@@ -457,5 +478,4 @@ public function set_blog_language( array $arr ) {
457
478
458
479
return $ arr ;
459
480
}
460
-
461
481
}
0 commit comments