-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
MultisiteLanguageSwitcher.php
234 lines (212 loc) · 5.76 KB
/
MultisiteLanguageSwitcher.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
/**
* Multisite Language Switcher Plugin
*
* @copyright Copyright (C) 2011-2022, 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: Multisite Language Switcher
* Version: 2.9.4
* Plugin URI: http://msls.co/
* Description: A simple but powerful plugin that will help you to manage the relations of your contents in a multilingual multisite-installation.
* Author: Dennis Ploetner
* Author URI: http://lloc.de/
* Text Domain: multisite-language-switcher
* Domain Path: /languages/
* 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
*/
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require __DIR__ . '/vendor/autoload.php';
}
/**
* MultisiteLanguageSwitcher
*
* @author Dennis Ploetner <[email protected]>
*/
if ( ! defined( 'MSLS_PLUGIN_VERSION' ) ) {
define( 'MSLS_PLUGIN_VERSION', '2.9.4' );
define( 'MSLS_PLUGIN_PATH', plugin_basename( __FILE__ ) );
define( 'MSLS_PLUGIN__FILE__', __FILE__ );
/**
* Get the output for using the links to the translations in your code
*
* @package Msls
*
* @param mixed $attr
*
* @return string
*/
function get_the_msls( $attr ): string {
$arr = is_array( $attr ) ? $attr : array();
$obj = apply_filters( 'msls_get_output', null );
return ! is_null( $obj ) ? strval( $obj->set_tags( $arr ) ) : '';
}
/**
* Output the links to the translations in your template
*
* You can call this function directly like that
*
* if ( function_exists ( 'the_msls' ) )
* the_msls();
*
* or just use it as shortcode [sc_msls]
*
* @package Msls
* @uses get_the_msls
*
* @param string[] $arr
*/
function the_msls( array $arr = array() ): void {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo get_the_msls( $arr );
}
/**
* Gets the URL of the country flag-icon for a specific locale
*
* @param string $locale
*
* @return string
*/
function get_msls_flag_url( string $locale ): string {
return ( new \lloc\Msls\MslsOptions() )->get_flag_url( $locale );
}
/**
* Gets the description for a blog for a specific locale
*
* @param string $locale
*
* @return string
*/
function get_msls_blog_description( string $locale, string $default = '' ): string {
$blog = msls_blog( $locale );
return $blog ? $blog->get_description() : $default;
}
/**
* Gets the permalink for a translation of the current post in a given language
*
* @param string $locale
* @param string $default
*
* @return string
*/
function get_msls_permalink( string $locale, string $default = '' ): string {
$url = null;
$blog = msls_blog( $locale );
if ( $blog ) {
$options = \lloc\Msls\MslsOptions::create();
$url = $blog->get_url( $options );
}
return $url ?? $default;
}
/**
* Looks for the MslsBlog instance for a specific locale
*
* @param string $locale
*
* @return \lloc\Msls\MslsBlog|null
*/
function msls_blog( string $locale ): ?\lloc\Msls\MslsBlog {
return msls_blog_collection()->get_blog( $locale );
}
/**
* Gets the MslsBlogCollection instance
*
* @return \lloc\Msls\MslsBlogCollection
*/
function msls_blog_collection(): \lloc\Msls\MslsBlogCollection {
return \lloc\Msls\MslsBlogCollection::instance();
}
/**
* Gets the MslsOptions instance
*
* @return \lloc\Msls\MslsOptions
*/
function msls_options(): \lloc\Msls\MslsOptions {
return \lloc\Msls\MslsOptions::instance();
}
/**
* Gets the MslsContentTypes instance
*
* @return \lloc\Msls\MslsContentTypes
*/
function msls_content_types(): \lloc\Msls\MslsContentTypes {
return \lloc\Msls\MslsContentTypes::create();
}
/**
* Gets the MslsPostType instance
*
* @return \lloc\Msls\MslsPostType
*/
function msls_post_type(): \lloc\Msls\MslsPostType {
return \lloc\Msls\MslsPostType::instance();
}
/**
* Gets the MslsTaxonomy instance
*
* @return \lloc\Msls\MslsTaxonomy
*/
function msls_taxonomy(): \lloc\Msls\MslsTaxonomy {
return \lloc\Msls\MslsTaxonomy::instance();
}
/**
* Gets the MslsOutput instance
*
* @return \lloc\Msls\MslsOutput
*/
function msls_output(): \lloc\Msls\MslsOutput {
return \lloc\Msls\MslsOutput::create();
}
/**
* Retrieves the MslsOptionsPost instance.
*
* @param int $id
* @return \lloc\Msls\MslsOptionsPost
*/
function msls_get_post( int $id ): \lloc\Msls\MslsOptionsPost {
return new \lloc\Msls\MslsOptionsPost( $id );
}
/**
* Retrieves the MslsOptionsTax instance.
*
* Determines the current query based on conditional tags:
* - is_category
* - is_tag
* - is_tax
*
* @param int $id
* @return \lloc\Msls\MslsOptionsTax
*/
function msls_get_tax( int $id ): \lloc\Msls\MslsOptionsTax {
return \lloc\Msls\MslsOptionsTax::create( $id );
}
/**
* Retrieves the MslsOptionsQuery instance.
*
* Determines the current query based on conditional tags:
* - is_day
* - is_month
* - is_year
* - is_author
* - is_post_type_archive
*
* @return ?\lloc\Msls\MslsOptionsQuery
*/
function msls_get_query(): ?\lloc\Msls\MslsOptionsQuery {
return \lloc\Msls\MslsOptionsQuery::create();
}
lloc\Msls\MslsPlugin::init();
}