1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Multisite Language Switcher Plugin |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2011-2020, Dennis Ploetner, [email protected] |
6
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 or later |
7
|
|
|
* @wordpress-plugin |
8
|
|
|
* |
9
|
|
|
* Plugin Name: Multisite Language Switcher |
10
|
|
|
* Version: 2.4.11 |
11
|
|
|
* Plugin URI: http://msls.co/ |
12
|
|
|
* Description: A simple but powerful plugin that will help you to manage the relations of your contents in a multilingual multisite-installation. |
13
|
|
|
* Author: Dennis Ploetner |
14
|
|
|
* Author URI: http://lloc.de/ |
15
|
|
|
* Text Domain: multisite-language-switcher |
16
|
|
|
* Domain Path: /languages/ |
17
|
|
|
* License: GPLv2 or later |
18
|
|
|
* |
19
|
|
|
* This program is free software; you can redistribute it and/or modify |
20
|
|
|
* it under the terms of the GNU General Public License, version 2, as |
21
|
|
|
* published by the Free Software Foundation. |
22
|
|
|
* |
23
|
|
|
* This program is distributed in the hope that it will be useful, |
24
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
25
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26
|
|
|
* GNU General Public License for more details. |
27
|
|
|
* |
28
|
|
|
* You should have received a copy of the GNU General Public License |
29
|
|
|
* along with this program; if not, write to the Free Software |
30
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
34
|
|
|
require __DIR__ . '/vendor/autoload.php'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* MultisiteLanguageSwitcher |
39
|
|
|
* |
40
|
|
|
* @author Dennis Ploetner <[email protected]> |
41
|
|
|
*/ |
42
|
|
|
if ( ! defined( 'MSLS_PLUGIN_VERSION' ) ) { |
43
|
|
|
define( 'MSLS_PLUGIN_VERSION', '2.4.11' ); |
44
|
|
|
define( 'MSLS_PLUGIN_PATH', plugin_basename( __FILE__ ) ); |
45
|
|
|
define( 'MSLS_PLUGIN__FILE__', __FILE__ ); |
46
|
|
|
|
47
|
|
|
lloc\Msls\MslsPlugin::init(); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the output for using the links to the translations in your code |
51
|
|
|
* |
52
|
|
|
* @package Msls |
53
|
|
|
* |
54
|
|
|
* @param array $attr |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
function get_the_msls( $attr ) { |
59
|
|
|
$arr = is_array( $attr ) ? $attr : []; |
60
|
|
|
$obj = apply_filters( 'msls_get_output', null ); |
61
|
|
|
|
62
|
|
|
return ! is_null( $obj ) ? strval( $obj->set_tags( $arr ) ) : ''; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
add_shortcode( 'sc_msls', 'get_the_msls' ); |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Output the links to the translations in your template |
69
|
|
|
* |
70
|
|
|
* You can call this function directly like that |
71
|
|
|
* |
72
|
|
|
* if ( function_exists ( 'the_msls' ) ) |
73
|
|
|
* the_msls(); |
74
|
|
|
* |
75
|
|
|
* or just use it as shortcode [sc_msls] |
76
|
|
|
* |
77
|
|
|
* @package Msls |
78
|
|
|
* @uses get_the_msls |
79
|
|
|
* |
80
|
|
|
* @param array $arr |
81
|
|
|
*/ |
82
|
|
|
function the_msls( array $arr = [] ) { |
83
|
|
|
echo get_the_msls( $arr ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Gets the URL of the country flag-icon for a specific locale |
88
|
|
|
* |
89
|
|
|
* @param string $locale |
90
|
|
|
* |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
function get_msls_flag_url( $locale ) { |
94
|
|
|
return ( new \lloc\Msls\MslsOptions )->get_flag_url( $locale ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Gets the description for a blog for a specific locale |
99
|
|
|
* |
100
|
|
|
* @param string $locale |
101
|
|
|
* |
102
|
|
|
* @return bool|string |
103
|
|
|
*/ |
104
|
|
|
function get_msls_blog_description( $locale ) { |
105
|
|
|
$blog = \lloc\Msls\MslsBlogCollection::instance()->get_blog( $locale ); |
106
|
|
|
|
107
|
|
|
return $blog->get_description(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Gets the permalink for a translation of the current post in a given language |
112
|
|
|
* |
113
|
|
|
* @param string $locale |
114
|
|
|
* |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
function get_msls_permalink( $locale ) { |
118
|
|
|
$options = \lloc\Msls\MslsOptions::create(); |
119
|
|
|
$blog = \lloc\Msls\MslsBlogCollection::instance()->get_blog( $locale ); |
120
|
|
|
|
121
|
|
|
return $blog->get_url( $options ); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: