|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
Plugin Name: MslsSelect |
|
5
|
|
|
Plugin URI: https://github.com/lloc/MslsSelect |
|
6
|
|
|
Description: Transforms the output of the Multisite Language Switcher to an HTML select |
|
7
|
|
|
Version: 2.2.2 |
|
8
|
|
|
Author: Dennis Ploetner |
|
9
|
|
|
Author URI: http://lloc.de/ |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/* |
|
13
|
|
|
Copyright 2014 Dennis Ploetner (email : [email protected]) |
|
14
|
|
|
|
|
15
|
|
|
This program is free software; you can redistribute it and/or modify |
|
16
|
|
|
it under the terms of the GNU General Public License, version 2, as |
|
17
|
|
|
published by the Free Software Foundation. |
|
18
|
|
|
|
|
19
|
|
|
This program is distributed in the hope that it will be useful, |
|
20
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
GNU General Public License for more details. |
|
23
|
|
|
|
|
24
|
|
|
You should have received a copy of the GNU General Public License |
|
25
|
|
|
along with this program; if not, write to the Free Software |
|
26
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* MslsSelect Class |
|
31
|
|
|
* |
|
32
|
|
|
* @package mslsselect |
|
33
|
|
|
*/ |
|
34
|
|
|
class MslsSelect { |
|
35
|
|
|
|
|
36
|
|
|
const VERSION = '2.2.2'; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct() { |
|
39
|
|
|
$options = get_option( 'msls' ); |
|
40
|
|
|
|
|
41
|
|
|
if ( empty( $options['output_current_blog'] ) ) { |
|
42
|
|
|
$options['output_current_blog'] = 1; |
|
43
|
|
|
|
|
44
|
|
|
update_option( 'msls', $options ); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Init |
|
50
|
|
|
* |
|
51
|
|
|
* @return MslsSelect |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function init(): self { |
|
54
|
|
|
if ( ! is_admin() ) { |
|
55
|
|
|
add_action( 'wp_enqueue_scripts', [ MslsSelect::class, 'enqueue_scripts' ] ); |
|
56
|
|
|
add_filter( 'msls_output_get_tags', [ MslsSelect::class, 'get_tags' ] ); |
|
57
|
|
|
add_filter( 'msls_output_get', [ MslsSelect::class, 'output_get' ], 10, 3 ); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return new self; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Enqueue scripts action |
|
65
|
|
|
* |
|
66
|
|
|
* @codeCoverageIgnore |
|
67
|
|
|
*/ |
|
68
|
|
|
public function enqueue_scripts(): void { |
|
69
|
|
|
wp_enqueue_script( 'mslsselect', plugins_url( '/js/mslsselect.min.js', __FILE__ ), [], self::VERSION, true ); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Filter for the 'msls_output_get'-hook |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $url |
|
76
|
|
|
* @param object $link |
|
77
|
|
|
* @param bool $current |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function output_get( string $url, $link, bool $current ): string { |
|
82
|
|
|
return sprintf( '<option value="%s"%s>%s</option>', $url, ( $current ? ' selected="selected"' : '' ), $link->txt ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Filter for the 'msls_output_get_tags'-hook |
|
87
|
|
|
* |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
|
|
public function get_tags(): array { |
|
91
|
|
|
return [ |
|
92
|
|
|
'before_item' => '', |
|
93
|
|
|
'after_item' => '', |
|
94
|
|
|
'before_output' => '<select class="msls_languages">', |
|
95
|
|
|
'after_output' => '</select>', |
|
96
|
|
|
]; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// @codeCoverageIgnoreStart |
|
102
|
|
|
if ( function_exists( 'add_action' ) ) { |
|
103
|
|
|
add_action( 'plugins_loaded', function () { |
|
104
|
|
|
MslsSelect::init(); |
|
105
|
|
|
} ); |
|
106
|
|
|
} |
|
107
|
|
|
// @codeCoverageIgnoreEnd |
|
108
|
|
|
|