PluginProbe
Polylang / 1.5.2
Polylang v1.5.2
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | polylang.php +306 -81 2.7.41.5.2 View file →
@@ -1,81 +1,306 @@
1 -<?php
2 -
3 -/**
4 - * Plugin Name: Polylang
5 - * Plugin URI: https://polylang.pro
6 - * Description: Adds multilingual capability to WordPress
7 - * Version: 2.7.4
8 - * Requires at least: 4.9
9 - * Requires PHP: 5.6
10 - * Author: WP SYNTEX
11 - * Author uri: https://polylang.pro
12 - * License: GPL v3 or later
13 - * License URI: https://www.gnu.org/licenses/gpl-3.0.html
14 - * Text Domain: polylang
15 - * Domain Path: /languages
16 - */
17 -
18 -/*
19 - * Copyright 2011-2019 Frédéric Demarle
20 - * Copyright 2019-2020 WP SYNTEX
21 - *
22 - * This program is free software: you can redistribute it and/or modify
23 - * it under the terms of the GNU General Public License as published by
24 - * the Free Software Foundation, either version 3 of the License, or
25 - * (at your option) any later version.
26 - *
27 - * This program is distributed in the hope that it will be useful,
28 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 - * GNU General Public License for more details.
31 - *
32 - * You should have received a copy of the GNU General Public License
33 - * along with this program. If not, see <https://www.gnu.org/licenses/>.
34 - */
35 -
36 -if ( ! defined( 'ABSPATH' ) ) {
37 - exit; // don't access directly
38 -};
39 -
40 -if ( defined( 'POLYLANG_BASENAME' ) ) {
41 - // The user is attempting to activate a second plugin instance, typically Polylang and Polylang Pro
42 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
43 - if ( defined( 'POLYLANG_PRO' ) ) {
44 - // Polylang Pro is already activated
45 - if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) {
46 - require_once ABSPATH . 'wp-includes/pluggable.php';
47 - deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate this plugin
48 - // WP does not allow us to send a custom meaningful message, so just tell the plugin has been deactivated
49 - wp_safe_redirect( add_query_arg( 'deactivate', 'true', remove_query_arg( 'activate' ) ) );
50 - exit;
51 - }
52 - } else {
53 - // Polylang was activated, deactivate it to keep only what we expect to be Polylang Pro
54 - deactivate_plugins( POLYLANG_BASENAME );
55 - }
56 -} else {
57 - // Go on loading the plugin
58 - define( 'POLYLANG_VERSION', '2.7.4' );
59 - define( 'PLL_MIN_WP_VERSION', '4.9' );
60 - define( 'PLL_MIN_PHP_VERSION', '5.6' );
61 -
62 - define( 'POLYLANG_FILE', __FILE__ ); // this file
63 - define( 'POLYLANG_BASENAME', plugin_basename( POLYLANG_FILE ) ); // plugin name as known by WP
64 - define( 'POLYLANG_DIR', dirname( POLYLANG_FILE ) ); // our directory
65 - define( 'POLYLANG', ucwords( str_replace( '-', ' ', dirname( POLYLANG_BASENAME ) ) ) );
66 -
67 - define( 'PLL_ADMIN_INC', POLYLANG_DIR . '/admin' );
68 - define( 'PLL_FRONT_INC', POLYLANG_DIR . '/frontend' );
69 - define( 'PLL_INC', POLYLANG_DIR . '/include' );
70 - define( 'PLL_INSTALL_INC', POLYLANG_DIR . '/install' );
71 - define( 'PLL_MODULES_INC', POLYLANG_DIR . '/modules' );
72 - define( 'PLL_SETTINGS_INC', POLYLANG_DIR . '/settings' );
73 - define( 'PLL_PREFIX', 'pll_' );
74 -
75 - if ( file_exists( PLL_MODULES_INC . '/pro.php' ) ) {
76 - define( 'POLYLANG_PRO', true );
77 - }
78 -
79 - require_once PLL_INC . '/class-polylang.php';
80 - new Polylang();
81 -}
1 +<?php
2 +/*
3 +Plugin Name: Polylang
4 +Plugin URI: http://polylang.wordpress.com/
5 +Version: 1.5.2
6 +Author: Frédéric Demarle
7 +Description: Adds multilingual capability to WordPress
8 +Text Domain: polylang
9 +Domain Path: /languages
10 +*/
11 +
12 +/*
13 + * Copyright 2011-2014 Frédéric Demarle
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 as published by
17 + * the Free Software Foundation; either version 2 of the License, or
18 + * (at your option) any later version.
19 + *
20 + * This program is distributed in the hope that it will be useful,
21 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 + * GNU General Public License for more details.
24 + *
25 + * You should have received a copy of the GNU General Public License
26 + * along with this program; if not, write to the Free Software
27 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28 + * MA 02110-1301, USA.
29 + *
30 + */
31 +
32 +// don't access directly
33 +if (!function_exists('add_action'))
34 + exit();
35 +
36 +define('POLYLANG_VERSION', '1.5.2');
37 +define('PLL_MIN_WP_VERSION', '3.5');
38 +
39 +define('POLYLANG_BASENAME', plugin_basename(__FILE__)); // plugin name as known by WP
40 +
41 +define('POLYLANG_DIR', dirname(__FILE__)); // our directory
42 +define('PLL_INC', POLYLANG_DIR . '/include');
43 +define('PLL_FRONT_INC', POLYLANG_DIR . '/frontend');
44 +define('PLL_ADMIN_INC', POLYLANG_DIR . '/admin');
45 +
46 +// default directory to store user data such as custom flags
47 +if (!defined('PLL_LOCAL_DIR'))
48 + define('PLL_LOCAL_DIR', WP_CONTENT_DIR . '/polylang');
49 +
50 +// includes local config file if exists
51 +if (file_exists(PLL_LOCAL_DIR . '/pll-config.php'))
52 + include_once(PLL_LOCAL_DIR . '/pll-config.php');
53 +
54 +// our url. Don't use WP_PLUGIN_URL http://wordpress.org/support/topic/ssl-doesnt-work-properly
55 +define('POLYLANG_URL', plugins_url('/' . basename(POLYLANG_DIR)));
56 +
57 +// default url to access user data such as custom flags
58 +if (!defined('PLL_LOCAL_URL'))
59 + define('PLL_LOCAL_URL', content_url('/polylang'));
60 +
61 +// cookie name. no cookie will be used if set to false
62 +if (!defined('PLL_COOKIE'))
63 + define('PLL_COOKIE', 'pll_language');
64 +
65 +// backward compatibility WP < 3.6
66 +// the search form js is no more needed in WP 3.6+ except if the search form is hardcoded elsewhere than in searchform.php
67 +if (!defined('PLL_SEARCH_FORM_JS') && !version_compare($GLOBALS['wp_version'], '3.6', '<'))
68 + define('PLL_SEARCH_FORM_JS', false);
69 +
70 +/*
71 + * controls the plugin, as well as activation, and deactivation
72 + *
73 + * @since 0.1
74 + */
75 +class Polylang {
76 +
77 + /*
78 + * constructor
79 + *
80 + * @since 0.1
81 + */
82 + public function __construct() {
83 + // manages plugin activation and deactivation
84 + register_activation_hook( __FILE__, array(&$this, 'activate'));
85 + register_deactivation_hook( __FILE__, array(&$this, 'deactivate'));
86 +
87 + // stopping here if we are going to deactivate the plugin (avoids breaking rewrite rules)
88 + if (isset($_GET['action'], $_GET['plugin']) && 'deactivate' == $_GET['action'] && plugin_basename(__FILE__) == $_GET['plugin'])
89 + return;
90 +
91 + // avoid loading polylang admin for frontend ajax requests
92 + // special test for plupload which does not use jquery ajax and thus does not pass our ajax prefilter
93 + // special test for customize_save done in frontend but for which we want to load the admin
94 + if (!defined('PLL_AJAX_ON_FRONT')) {
95 + $in = isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('upload-attachment', 'customize_save'));
96 + define('PLL_AJAX_ON_FRONT', defined('DOING_AJAX') && DOING_AJAX && empty($_REQUEST['pll_ajax_backend']) && !$in);
97 + }
98 +
99 + if (!defined('PLL_ADMIN'))
100 + define('PLL_ADMIN', defined('DOING_CRON') || (is_admin() && !PLL_AJAX_ON_FRONT));
101 +
102 + if (!defined('PLL_SETTINGS'))
103 + define('PLL_SETTINGS', is_admin() && isset($_GET['page']) && $_GET['page'] == 'mlang');
104 +
105 + // blog creation on multisite
106 + add_action('wpmu_new_blog', array(&$this, 'wpmu_new_blog'), 5); // before WP attempts to send mails which can break on some PHP versions
107 +
108 + // FIXME maybe not available on every installations but widely used by WP plugins
109 + spl_autoload_register(array(&$this, 'autoload')); // autoload classes
110 +
111 + // override load text domain waiting for the language to be defined
112 + // here for plugins which load text domain as soon as loaded :(
113 + if (!defined('PLL_OLT') || PLL_OLT)
114 + new PLL_OLT_Manager();
115 +
116 + // plugin initialization
117 + // take no action before all plugins are loaded
118 + add_action('plugins_loaded', array(&$this, 'init'), 1);
119 +
120 + // loads the API
121 + require_once(PLL_INC.'/api.php');
122 +
123 + // WPML API
124 + if (!defined('PLL_WPML_COMPAT') || PLL_WPML_COMPAT)
125 + require_once (PLL_INC.'/wpml-compat.php');
126 +
127 + // extra code for compatibility with some plugins
128 + if (!defined('PLL_PLUGINS_COMPAT') || PLL_PLUGINS_COMPAT)
129 + new PLL_Plugins_Compat();
130 + }
131 +
132 + /*
133 + * activation or deactivation for all blogs
134 + *
135 + * @since 1.2
136 + *
137 + * @param string $what either 'activate' or 'deactivate'
138 + */
139 + protected function do_for_all_blogs($what) {
140 + // network
141 + if (is_multisite() && isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) {
142 + global $wpdb;
143 +
144 + foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs") as $blog_id) {
145 + switch_to_blog($blog_id);
146 + $what == 'activate' ? $this->_activate() : $this->_deactivate();
147 + }
148 + restore_current_blog();
149 + }
150 +
151 + // single blog
152 + else
153 + $what == 'activate' ? $this->_activate() : $this->_deactivate();
154 + }
155 +
156 + /*
157 + * plugin activation for multisite
158 + *
159 + * @since 0.1
160 + */
161 + public function activate() {
162 + global $wp_version;
163 + load_plugin_textdomain('polylang', false, basename(POLYLANG_DIR).'/languages'); // plugin i18n
164 +
165 + if (version_compare($wp_version, PLL_MIN_WP_VERSION , '<'))
166 + die (sprintf('<p style = "font-family: sans-serif; font-size: 12px; color: #333; margin: -5px">%s</p>',
167 + sprintf(__('You are using WordPress %s. Polylang requires at least WordPress %s.', 'polylang'),
168 + esc_html($wp_version),
169 + PLL_MIN_WP_VERSION
170 + )
171 + ));
172 +
173 + $this->do_for_all_blogs('activate');
174 + }
175 +
176 + /*
177 + * plugin activation
178 + *
179 + * @since 0.5
180 + */
181 + protected function _activate() {
182 + global $polylang;
183 +
184 + if ($options = get_option('polylang')) {
185 + // plugin upgrade
186 + if (version_compare($options['version'], POLYLANG_VERSION, '<')) {
187 + $upgrade = new PLL_Upgrade($options);
188 + $upgrade->upgrade_at_activation();
189 + }
190 + }
191 + // defines default values for options in case this is the first installation
192 + else {
193 + $options = array(
194 + 'browser' => 1, // default language for the front page is set by browser preference
195 + 'rewrite' => 1, // remove /language/ in permalinks (was the opposite before 0.7.2)
196 + 'hide_default' => 0, // do not remove URL language information for default language
197 + 'force_lang' => 0, // do not add URL language information when useless
198 + 'redirect_lang' => 0, // do not redirect the language page to the homepage
199 + 'media_support' => 1, // support languages and translation for media by default
200 + 'sync' => array(), // synchronisation is disabled by default (was the opposite before 1.2)
201 + 'post_types' => array_values(get_post_types(array('_builtin' => false, 'show_ui => true'))),
202 + 'taxonomies' => array_values(get_taxonomies(array('_builtin' => false, 'show_ui => true'))),
203 + 'domains' => array(),
204 + 'version' => POLYLANG_VERSION,
205 + );
206 +
207 + update_option('polylang', $options);
208 + }
209 +
210 + // always provide a global $polylang object and add our rewrite rules if needed
211 + $polylang = new StdClass();
212 + $polylang->options = &$options;
213 + $polylang->model = new PLL_Admin_Model($options);
214 + $polylang->links_model = $polylang->model->get_links_model();
215 + flush_rewrite_rules();
216 + }
217 +
218 + /*
219 + * plugin deactivation for multisite
220 + *
221 + * @since 0.1
222 + */
223 + public function deactivate() {
224 + $this->do_for_all_blogs('deactivate');
225 + }
226 +
227 + /*
228 + * plugin deactivation
229 + *
230 + * @since 0.5
231 + */
232 + protected function _deactivate() {
233 + flush_rewrite_rules();
234 + }
235 +
236 + /*
237 + * blog creation on multisite (to set default options)
238 + *
239 + * @since 0.9.4
240 + *
241 + * @param int $blog_id
242 + */
243 + public function wpmu_new_blog($blog_id) {
244 + switch_to_blog($blog_id);
245 + $this->_activate();
246 + restore_current_blog();
247 + }
248 +
249 + /*
250 + * autoload classes
251 + *
252 + * @since 1.2
253 + *
254 + * @param string $class
255 + */
256 + public function autoload($class) {
257 + $class = str_replace('_', '-', strtolower(substr($class, 4)));
258 + foreach (array(PLL_INC, PLL_FRONT_INC, PLL_ADMIN_INC) as $path) {
259 + if (file_exists($file = "$path/$class.php")) {
260 + require_once($file);
261 + break;
262 + }
263 + }
264 + }
265 +
266 + /*
267 + * Polylang initialization
268 + * setups models and separate admin and frontend
269 + *
270 + * @since 1.2
271 + */
272 + public function init() {
273 + global $polylang;
274 +
275 + $options = get_option('polylang');
276 +
277 + // plugin upgrade
278 + if ($options && version_compare($options['version'], POLYLANG_VERSION, '<')) {
279 + $upgrade = new PLL_Upgrade($options);
280 + if (!$upgrade->upgrade()) // if the version is too old
281 + return;
282 + }
283 +
284 + $class = apply_filters('pll_model', PLL_SETTINGS ? 'PLL_Admin_Model' : 'PLL_Model');
285 + $model = new $class($options);
286 + $links_model = $model->get_links_model();
287 +
288 + if (PLL_ADMIN) {
289 + $polylang = new PLL_Admin($links_model);
290 + $polylang->init();
291 + }
292 + // do nothing on frontend if no language is defined
293 + elseif ($model->get_languages_list()) {
294 + $polylang = new PLL_Frontend($links_model);
295 + $polylang->init();
296 + }
297 + else
298 + do_action('pll_no_language_defined'); // to load overriden textdomains
299 +
300 + // load wpml-config.xml
301 + if (!defined('PLL_WPML_COMPAT') || PLL_WPML_COMPAT)
302 + new PLL_WPML_Config;
303 + }
304 +}
305 +
306 +new Polylang();