Completed
Pull Request — master (#131)
by
unknown
01:31
created

MslsAdmin::get_options_page_link()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * MslsAdmin
4
 * @author Dennis Ploetner <[email protected]>
5
 * @since 0.9.8
6
 */
7
8
namespace lloc\Msls;
9
10
/**
11
 * Administration of the options
12
 * @package Msls
13
 */
14
class MslsAdmin extends MslsMain {
15
16
	/**
17
	 * Factory
18
	 *
19
	 * @codeCoverageIgnore
20
	 *
21
	 * @return MslsAdmin
22
	 */
23
	public static function init() {
24
		if ( ! ( $obj = MslsRegistry::get_object( __CLASS__ ) ) ) {
25
			$options    = MslsOptions::instance();
26
			$collection = MslsBlogCollection::instance();
27
28
			$obj = new static( $options, $collection );
29
30
			MslsRegistry::set_object( __CLASS__, $obj );
31
32
			/**
33
			 * Override the capabilities needed for the plugin's settings
34
			 *
35
			 * @since 2.0
36
			 *
37
			 * @param string $capability
38
			 */
39
			$caps = apply_filters( 'msls_admin_caps', 'manage_options' );
40
			if ( current_user_can( $caps ) ) {
41
				$title = __( 'Multisite Language Switcher', 'multisite-language-switcher' );
42
				add_options_page( $title, $title, 'manage_options', $obj->get_menu_slug(), [ $obj, 'render' ] );
43
44
				add_action( 'admin_init', [ $obj, 'register' ] );
45
				add_action( 'admin_notices', [ $obj, 'has_problems' ] );
46
47
				add_filter( 'msls_admin_validate', [ $obj, 'set_blog_language' ] );
48
			}
49
		}
50
51
		return $obj;
52
	}
53
54
	/**
55
	 * Let's do this simple
56
	 *
57
	 * @return string
58
	 */
59
	public function get_menu_slug() {
60
		return 'MslsAdmin';
61
	}
62
63
	/**
64
	 * Get's the link for the switcher-settings in the wp-admin
65
	 *
66
	 * @return string
67
	 */
68
	public function get_options_page_link() {
69
		return sprintf( '/options-general.php?page=%s', $this->get_menu_slug() );
70
	}
71
72
	/**
73
	 * You can use every method of the decorated object
74
	 *
75
	 * @param string $method
76
	 * @param mixed $args
77
	 *
78
	 * @return mixed
79
	 */
80
	public function __call( $method, $args ) {
81
		$parts = explode( '_', $method, 2 );
82
		if ( 2 == count( $parts ) ) {
83
			switch ( $parts[0] ) {
84
				case 'rewrite':
85
					return $this->render_rewrite( $parts[1] );
86
					break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
87
				case 'text':
88
					echo $this->render_input( $parts[1] );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
89
					break;
90
			}
91
		}
92
	}
93
94
	/**
95
	 * There is something wrong? Here comes the message...
96
	 * @return bool
97
	 */
98
	public function has_problems() {
99
		$message = '';
100
101
		if ( $this->options->is_empty() ) {
102
			$message = sprintf(
103
				__( 'Multisite Language Switcher is almost ready. You must complete the configuration process</a>.' ),
104
				esc_url( admin_url( $this->get_options_page_link() ) )
105
			);
106
		} elseif ( 1 == count( $this->options->get_available_languages() ) ) {
107
			$message = sprintf(
108
				__( '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.' ),
109
				esc_url( 'http://codex.wordpress.org/Installing_WordPress_in_Your_Language#Manually_Installing_Language_Files' ),
110
				esc_url( 'http://wordpress.org/plugins/wp-native-dashboard/' )
111
			);
112
		}
113
114
		return MslsPlugin::message_handler( $message, 'updated fade' );
115
	}
116
117
	/**
118
	 * Render the options-page
119
	 * @codeCoverageIgnore
120
	 */
121
	public function render() {
122
		printf(
123
			'<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>',
124
			__( 'Multisite Language Switcher Options', 'multisite-language-switcher' ),
125
			$this->subsubsub(),
126
			__( 'To achieve maximum flexibility, you have to configure each blog separately.', 'multisite-language-switcher' )
127
		);
128
129
		settings_fields( 'msls' );
130
		do_settings_sections( __CLASS__ );
131
132
		printf(
133
			'<p class="submit"><input name="Submit" type="submit" class="button button-primary" value="%s" /></p></form></div>',
134
			( $this->options->is_empty() ? __( 'Configure', 'multisite-language-switcher' ) : __( 'Update', 'multisite-language-switcher' ) )
135
		);
136
	}
137
138
139
	/**
140
	 * Create a submenu which contains links to all blogs of the current user
141
	 * @return string
142
	 */
143
	public function subsubsub() {
144
		$arr = [];
145
146
		foreach ( $this->collection->get_plugin_active_blogs() as $blog ) {
147
			$arr[] = sprintf(
148
				'<a href="%s"%s>%s / %s</a>',
149
				get_admin_url( $blog->userblog_id, $this->get_options_page_link() ),
150
				( $blog->userblog_id == $this->collection->get_current_blog_id() ? ' class="current"' : '' ),
151
				$blog->blogname,
152
				$blog->get_description()
153
			);
154
		}
155
156
		return (
157
			empty( $arr ) ?
158
			'' :
159
			sprintf(
160
				'<ul class="subsubsub"><li>%s</li></ul>',
161
				implode( ' | </li><li>', $arr )
162
			)
163
		);
164
	}
165
166
	/**
167
	 * Register the form-elements
168
	 * @codeCoverageIgnore
169
	 */
170
	public function register() {
171
		register_setting( 'msls', 'msls', [ $this, 'validate' ] );
172
173
		add_settings_section( 'language_section', __( 'Language Settings', 'multisite-language-switcher' ), array(
174
			$this,
175
			'language_section'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
176
		), __CLASS__ );
177
		add_settings_section( 'main_section', __( 'Main Settings', 'multisite-language-switcher' ), array(
178
			$this,
179
			'main_section'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
180
		), __CLASS__ );
181
		add_settings_section( 'advanced_section', __( 'Advanced Settings', 'multisite-language-switcher' ), array(
182
			$this,
183
			'advanced_section'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
184
		), __CLASS__ );
185
186
		global $wp_rewrite;
187
		if ( $wp_rewrite->using_permalinks() ) {
188
			add_settings_section( 'rewrites_section', __( 'Rewrites Settings', 'multisite-language-switcher' ), array(
189
				$this,
190
				'rewrites_section'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
191
			), __CLASS__ );
192
		}
193
194
		/**
195
		 * Lets you add your own settings section
196
		 * @since 1.0
197
		 *
198
		 * @param string $page
199
		 */
200
		do_action( 'msls_admin_register', __CLASS__ );
201
	}
202
203
	/**
204
	 * Register the fields in the language_section
205
	 * @codeCoverageIgnore
206
	 */
207
	public function language_section() {
208
		add_settings_field( 'blog_language', __( 'Blog Language', 'multisite-language-switcher' ), array(
209
			$this,
210
			'blog_language'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
211
		), __CLASS__, 'language_section', array( 'label_for' => 'blog_language' ) );
212
213
		/**
214
		 * Lets you add your own field to the language section
215
		 * @since 1.0
216
		 *
217
		 * @param string $page
218
		 * @param string $section
219
		 */
220
		do_action( 'msls_admin_language_section', __CLASS__, 'language_section' );
221
	}
222
223
	/**
224
	 * Register the fields in the main_section
225
	 * @codeCoverageIgnore
226
	 */
227
	public function main_section() {
228
		add_settings_field( 'display', __( 'Display', 'multisite-language-switcher' ), array(
229
			$this,
230
			'display'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
231
		), __CLASS__, 'main_section', array( 'label_for' => 'display' ) );
232
		add_settings_field( 'sort_by_description', __( 'Sort languages', 'multisite-language-switcher' ), array(
233
			$this,
234
			'sort_by_description'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
235
		), __CLASS__, 'main_section' );
236
		add_settings_field( 'output_current_blog', __( 'Current language link', 'multisite-language-switcher' ), array(
237
			$this,
238
			'output_current_blog'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
239
		), __CLASS__, 'main_section' );
240
		add_settings_field( 'only_with_translation', __( 'Translation links', 'multisite-language-switcher' ), array(
241
			$this,
242
			'only_with_translation'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
243
		), __CLASS__, 'main_section' );
244
		add_settings_field( 'description', __( 'Description', 'multisite-language-switcher' ), array(
245
			$this,
246
			'description'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
247
		), __CLASS__, 'main_section', array( 'label_for' => 'description' ) );
248
		add_settings_field( 'before_output', __( 'Text/HTML before the list', 'multisite-language-switcher' ), array(
249
			$this,
250
			'text_before_output'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
251
		), __CLASS__, 'main_section', array( 'label_for' => 'before_output' ) );
252
		add_settings_field( 'after_output', __( 'Text/HTML after the list', 'multisite-language-switcher' ), array(
253
			$this,
254
			'text_after_output'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
255
		), __CLASS__, 'main_section', array( 'label_for' => 'after_output' ) );
256
		add_settings_field( 'before_item', __( 'Text/HTML before each item', 'multisite-language-switcher' ), array(
257
			$this,
258
			'text_before_item'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
259
		), __CLASS__, 'main_section', array( 'label_for' => 'before_item' ) );
260
		add_settings_field( 'after_item', __( 'Text/HTML after each item', 'multisite-language-switcher' ), array(
261
			$this,
262
			'text_after_item'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
263
		), __CLASS__, 'main_section', array( 'label_for' => 'after_item' ) );
264
		add_settings_field( 'content_filter', __( 'Available translations hint', 'multisite-language-switcher' ), array(
265
			$this,
266
			'content_filter'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
267
		), __CLASS__, 'main_section' );
268
		add_settings_field( 'content_priority', __( 'Hint priority', 'multisite-language-switcher' ), array(
269
			$this,
270
			'content_priority'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
271
		), __CLASS__, 'main_section', array( 'label_for' => 'content_priority' ) );
272
273
		/**
274
		 * Lets you add your own field to the main section
275
		 * @since 1.0
276
		 *
277
		 * @param string $page
278
		 * @param string $section
279
		 */
280
		do_action( 'msls_admin_main_section', __CLASS__, 'main_section' );
281
	}
282
283
	/**
284
	 * Register the fields in the advanced_section
285
	 * @codeCoverageIgnore
286
	 */
287
	public function advanced_section() {
288
		add_settings_field( 'activate_autocomplete', __( 'Autocomplete', 'multisite-language-switcher' ), array(
289
			$this,
290
			'activate_autocomplete'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
291
		), __CLASS__, 'advanced_section' );
292
		add_settings_field( 'image_url', __( 'Custom URL for flag-images', 'multisite-language-switcher' ), array(
293
			$this,
294
			'text_image_url'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
295
		), __CLASS__, 'advanced_section', array( 'label_for' => 'image_url' ) );
296
		add_settings_field( 'reference_user', __( 'Reference user', 'multisite-language-switcher' ), array(
297
			$this,
298
			'reference_user'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
299
		), __CLASS__, 'advanced_section', array( 'label_for' => 'reference_user' ) );
300
		add_settings_field( 'exclude_current_blog', __( 'Exclude blog', 'multisite-language-switcher' ), array(
301
			$this,
302
			'exclude_current_blog'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
303
		), __CLASS__, 'advanced_section' );
304
		add_settings_field( 'activate_content_import', __( 'Content import', 'multisite-language-switcher' ), array(
305
			$this,
306
			'activate_content_import'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
307
		), __CLASS__, 'advanced_section' );
308
309
		/**
310
		 * Lets you add your own field to the advanced section
311
		 * @since 1.0
312
		 *
313
		 * @param string $page
314
		 * @param string $section
315
		 */
316
		do_action( 'msls_admin_advanced_section', __CLASS__, 'advanced_section' );
317
	}
318
319
	/**
320
	 * Register the fields in the rewrites_section
321
	 * @since 1.1
322
	 * @codeCoverageIgnore
323
	 */
324
	public function rewrites_section() {
325
		foreach ( get_post_types( [ 'public' => true ], 'objects' ) as $key => $object ) {
326
			$title = sprintf( __( '%s Slug', 'multisite-language-switcher' ), $object->label );
327
			add_settings_field(
328
				"rewrite_{$key}",
329
				$title,
330
				[ $this, "rewrite_{$key}" ],
331
				__CLASS__,
332
				'rewrites_section',
333
				array( 'label_for' => "rewrite_{$key}" )
334
			);
335
		}
336
337
		/**
338
		 * Lets you add your own field to the rewrites section
339
		 *
340
		 * @param string $page
341
		 * @param string $section
342
		 */
343
		do_action( 'msls_admin_rewrites_section', __CLASS__, 'rewrites_section' );
344
	}
345
346
	/**
347
	 * Shows the select-form-field 'blog_language'
348
	 */
349
	public function blog_language() {
350
		echo $this->render_select(
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
351
			'blog_language',
352
			$this->options->get_available_languages(),
353
			get_option( 'WPLANG', 'en_US' )
354
		);
355
	}
356
357
	/**
358
	 * Shows the select-form-field 'display'
359
	 */
360
	public function display() {
361
		echo $this->render_select(
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
362
			'display',
363
			MslsLink::get_types_description(),
364
			$this->options->display
365
		);
366
	}
367
368
	/**
369
	 * Shows the select-form-field 'reference_user'
370
	 */
371
	public function reference_user() {
372
		$users = array();
373
374
		foreach ( $this->collection->get_users() as $user ) {
375
			$users[ $user->ID ] = $user->user_nicename;
376
		}
377
378
		echo $this->render_select( 'reference_user', $users, $this->options->reference_user );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
379
	}
380
381
	/**
382
	 * render
383
	 *
384
	 * You can decide if you want to activate the experimental autocomplete
385
	 * input fields in the backend instead of the traditional select-menus.
386
	 */
387
	public function activate_autocomplete() {
388
		printf(
389
			'%s %s',
390
			$this->render_checkbox( 'activate_autocomplete' ),
391
			$this->render_checkbox_label(
392
				'activate_autocomplete',
393
				__( 'Activate experimental autocomplete inputs', 'multisite-language-switcher' )
394
			)
395
		);
396
	}
397
398
	/**
399
	 * render
400
	 *
401
	 * You can decide if you want to activate the content import functionality
402
	 * in the backend instead of the traditional select-menus.
403
	 */
404
	public function activate_content_import() {
405
		printf(
406
			'%s %s',
407
			$this->render_checkbox( 'activate_content_import' ),
408
			$this->render_checkbox_label(
409
				'activate_content_import',
410
				__( 'Activate the content import functionality', 'multisite-language-switcher' )
411
			)
412
		);
413
	}
414
415
	/**
416
	 * Show sort_by_description-field
417
	 *
418
	 * You can decide that the output will be sorted by the description. If not
419
	 * the output will be sorted by the language-code.
420
	 */
421
	public function sort_by_description() {
422
		printf(
423
			'%s %s',
424
			$this->render_checkbox( 'sort_by_description' ),
425
			$this->render_checkbox_label(
426
				'sort_by_description',
427
				__( 'Sort languages by description', 'multisite-language-switcher' )
428
			)
429
		);
430
	}
431
432
	/**
433
	 * Exclude the current blog
434
	 *
435
	 * You can exclude a blog explicitly. All your settings will be safe but the
436
	 * plugin will ignore this blog while this option is active.
437
	 */
438
	public function exclude_current_blog() {
439
		printf(
440
			'%s %s',
441
			$this->render_checkbox( 'exclude_current_blog' ),
442
			$this->render_checkbox_label(
443
				'exclude_current_blog',
444
				__( 'Exclude this blog from output', 'multisite-language-switcher' )
445
			)
446
		);
447
	}
448
449
	/**
450
	 * Show only a link  if a translation is available
451
	 *
452
	 * Some user requested this feature. Shows only links to available
453
	 * translations.
454
	 */
455
	public function only_with_translation() {
456
		printf(
457
			'%s %s',
458
			$this->render_checkbox( 'only_with_translation' ),
459
			$this->render_checkbox_label(
460
				'only_with_translation',
461
				__( 'Show only links with a translation', 'multisite-language-switcher' )
462
			)
463
		);
464
	}
465
466
	/**
467
	 * Show a link to the current blog
468
	 *
469
	 * Some user requested this feature. If active the plugin will place also a
470
	 * link to the current blog.
471
	 */
472
	public function output_current_blog() {
473
		printf(
474
			'%s %s',
475
			$this->render_checkbox( 'output_current_blog' ),
476
			$this->render_checkbox_label(
477
				'output_current_blog',
478
				__( 'Display link to the current language', 'multisite-language-switcher' )
479
			)
480
		);
481
	}
482
483
	/**
484
	 * The description for the current blog
485
	 *
486
	 * The language will be used ff there is no description.
487
	 */
488
	public function description() {
489
		echo $this->render_input( 'description', '40' );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
490
	}
491
492
	/**
493
	 * The output can be placed after the_content
494
	 */
495
	public function content_filter() {
496
		printf(
497
			'%s %s',
498
			$this->render_checkbox( 'content_filter' ),
499
			$this->render_checkbox_label(
500
				'content_filter',
501
				__( 'Add hint for available translations', 'multisite-language-switcher' )
502
			)
503
		);
504
	}
505
506
	/**
507
	 * If the output in the_content is active you can set the priority too
508
	 *
509
	 * Default is 10. But may be there are other plugins active and you run into
510
	 * trouble. So you can decide a higher (from 1) or a lower (to 100) priority
511
	 * for the output
512
	 */
513
	public function content_priority() {
514
		$temp     = array_merge( range( 1, 10 ), [ 20, 50, 100 ] );
515
		$arr      = array_combine( $temp, $temp );
516
		$selected = (
517
		empty( $this->options->content_priority ) ?
518
			10 :
519
			$this->options->content_priority
520
		);
521
522
		echo $this->render_select( 'content_priority', $arr, $selected );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
523
	}
524
525
	/**
526
	 * Rewrites slugs for registered post types
527
	 *
528
	 * @param string $key
529
	 */
530
	public function render_rewrite( $key ) {
531
		$rewrite = get_post_type_object( $key )->rewrite;
532
533
		$value = '';
534
		if ( true === $rewrite ) {
535
			$value = $key;
536
		} elseif ( ! empty( $rewrite['slug'] ) ) {
537
			$value = $rewrite['slug'];
538
		}
539
540
		echo $this->render_input( "rewrite_{$key}", 30, $value, true );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
541
	}
542
543
	/**
544
	 * Render form-element (checkbox)
545
	 *
546
	 * @param string $key   Name and ID of the form-element
547
	 *
548
	 * @return string
549
	 */
550
	public function render_checkbox( $key ) {
551
		return sprintf(
552
			'<input type="checkbox" id="%1$s" name="msls[%1$s]" value="1" %2$s/>',
553
			$key,
554
			checked( 1, $this->options->$key, false )
555
		);
556
	}
557
558
	/**
559
	 * Renders a form checkbox label.
560
	 *
561
	 * @param string $key   Name and ID of the checkbox.
562
	 * @param string $label Label text for the checkbox.
563
	 *
564
	 * @return string
565
	 */
566
	public function render_checkbox_label( $key, $label ) {
567
		return sprintf(
568
			'<label for="%1$s">%2$s</label>',
569
			$key,
570
			esc_html( $label )
571
		);
572
	}
573
574
	/**
575
	 * Render form-element (text-input)
576
	 *
577
	 * @param string $key Name and ID of the form-element
578
	 * @param string $size Size-attribute of the input-field
579
	 * @param string $default
580
	 * @param bool $readonly
581
	 *
582
	 * @return string
583
	 */
584
	public function render_input( $key, $size = '30', $default = '', $readonly = false ) {
585
		return sprintf(
586
			'<input type="text" class="regular-text" id="%1$s" name="msls[%1$s]" value="%2$s" size="%3$s"%4$s/>',
587
			$key,
588
			esc_attr( ! empty( $this->options->$key ) ? $this->options->$key : $default ),
589
			$size,
590
			$readonly ? ' readonly="readonly"' : ''
591
		);
592
	}
593
594
	/**
595
	 * Render form-element (select)
596
	 * @uses selected
597
	 *
598
	 * @param string $key Name and ID of the form-element
599
	 * @param array $arr Options as associative array
600
	 * @param string $selected Values which should be selected
601
	 *
602
	 * @return string
603
	 */
604
	public function render_select( $key, array $arr, $selected = '' ) {
605
		$options = [];
606
607
		foreach ( $arr as $value => $description ) {
608
			$options[] = sprintf(
609
				'<option value="%s" %s>%s</option>',
610
				$value,
611
				selected( $value, $selected, false ),
612
				$description
613
			);
614
		}
615
616
		return sprintf(
617
			'<select id="%1$s" name="msls[%1$s]">%2$s</select>',
618
			$key,
619
			implode( '', $options )
620
		);
621
	}
622
623
	/**
624
	 * Validates input before saving it
625
	 *
626
	 * @param array $arr Values of the submitted form
627
	 *
628
	 * @return array Validated input
629
	 */
630
	public function validate( array $arr ) {
631
		/**
632
		 * Returns custom filtered input array
633
		 * @since 1.0
634
		 *
635
		 * @param array $arr
636
		 */
637
		$arr = apply_filters( 'msls_admin_validate', $arr );
638
639
		$arr['display'] = (
640
		isset( $arr['display'] ) ?
641
			(int) $arr['display'] :
642
			0
643
		);
644
645
		if ( isset( $arr['image_url'] ) ) {
646
			$arr['image_url'] = rtrim( esc_attr( $arr['image_url'] ), '/' );
647
		}
648
649
		return $arr;
650
	}
651
652
	/**
653
	 * Filter which sets the global blog language
654
	 *
655
	 * @param array $arr
656
	 *
657
	 * @return array
658
	 */
659
	public function set_blog_language( array $arr ) {
660
		if ( isset( $arr['blog_language'] ) ) {
661
			$blog_language = ( 'en_US' === $arr['blog_language'] ) ? '' : $arr['blog_language'];
662
			update_option( 'WPLANG', $blog_language );
663
			unset( $arr['blog_language'] );
664
		}
665
666
		return $arr;
667
	}
668
669
}
670