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