PluginProbe
Polylang / 1.7.11
Polylang v1.7.11
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
polylang / polylang.php

polylang.php in Polylang 1.7.11, at polylang.php

207 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Polylang
4 Plugin URI: http://polylang.wordpress.com/
5 Version: 1.7.11
6 Author: Frédéric Demarle
7 Author uri: http://polylang.wordpress.com
8 Description: Adds multilingual capability to WordPress
9 Text Domain: polylang
10 Domain Path: /languages
11 */
12
13 /*
14 * Copyright 2011-2015 Frédéric Demarle
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
29 * MA 02110-1301, USA.
30 *
31 */
32
33 // don't access directly
34 if (!function_exists('add_action'))
35 exit();
36
37 define('POLYLANG_VERSION', '1.7.11');
38 define('PLL_MIN_WP_VERSION', '3.9');
39
40 define('POLYLANG_BASENAME', plugin_basename(__FILE__)); // plugin name as known by WP
41
42 define('POLYLANG_DIR', dirname(__FILE__)); // our directory
43 define('PLL_INC', POLYLANG_DIR . '/include');
44 define('PLL_FRONT_INC', POLYLANG_DIR . '/frontend');
45 define('PLL_ADMIN_INC', POLYLANG_DIR . '/admin');
46 define('PLL_INSTALL_INC', POLYLANG_DIR . '/install');
47
48 // default directory to store user data such as custom flags
49 if (!defined('PLL_LOCAL_DIR'))
50 define('PLL_LOCAL_DIR', WP_CONTENT_DIR . '/polylang');
51
52 // includes local config file if exists
53 if (file_exists(PLL_LOCAL_DIR . '/pll-config.php'))
54 include_once(PLL_LOCAL_DIR . '/pll-config.php');
55
56 /*
57 * controls the plugin, as well as activation, and deactivation
58 *
59 * @since 0.1
60 */
61 class Polylang {
62
63 /*
64 * constructor
65 *
66 * @since 0.1
67 */
68 public function __construct() {
69 // FIXME maybe not available on every installations but widely used by WP plugins
70 spl_autoload_register(array(&$this, 'autoload')); // autoload classes
71
72 $install = new PLL_Install(POLYLANG_BASENAME);
73
74 // stopping here if we are going to deactivate the plugin (avoids breaking rewrite rules)
75 if ($install->is_deactivation())
76 return;
77
78 // plugin initialization
79 // take no action before all plugins are loaded
80 add_action('plugins_loaded', array(&$this, 'init'), 1);
81
82 // override load text domain waiting for the language to be defined
83 // here for plugins which load text domain as soon as loaded :(
84 if (!defined('PLL_OLT') || PLL_OLT)
85 PLL_OLT_Manager::instance();
86
87 // loads the API
88 require_once(PLL_INC.'/api.php');
89
90 // WPML API
91 if (!defined('PLL_WPML_COMPAT') || PLL_WPML_COMPAT)
92 PLL_WPML_Compat::instance();
93
94 // extra code for compatibility with some plugins
95 if (!defined('PLL_PLUGINS_COMPAT') || PLL_PLUGINS_COMPAT)
96 PLL_Plugins_Compat::instance();
97 }
98
99 /*
100 * autoload classes
101 *
102 * @since 1.2
103 *
104 * @param string $class
105 */
106 public function autoload($class) {
107 // not a Polylang class
108 if (0 !== strncmp('PLL_', $class, 4))
109 return;
110
111 $class = str_replace('_', '-', strtolower(substr($class, 4)));
112
113 if ((0 === strpos($class, 'choose') || 0 === strpos($class, 'frontend')) && file_exists($file = PLL_FRONT_INC . "/$class.php"))
114 require_once($file);
115
116 elseif ((0 === strpos($class, 'install') || 'upgrade' === $class) && file_exists($file = PLL_INSTALL_INC . "/$class.php"))
117 require_once($file);
118
119 elseif ((0 === strpos($class, 'admin') || 0 === strpos($class, 'table') || 'settings' === $class || 'wp-import' === $class) && file_exists($file = PLL_ADMIN_INC . "/$class.php"))
120 require_once($file);
121
122 elseif (file_exists($file = PLL_INC . "/$class.php"))
123 require_once($file);
124 }
125
126 /*
127 * defines constants
128 * may be overriden by a plugin if set before plugins_loaded, 1
129 *
130 * @since 1.6
131 */
132 static public function define_constants() {
133 // our url. Don't use WP_PLUGIN_URL http://wordpress.org/support/topic/ssl-doesnt-work-properly
134 if (!defined('POLYLANG_URL'))
135 define('POLYLANG_URL', plugins_url('', __FILE__));
136
137 // default url to access user data such as custom flags
138 if (!defined('PLL_LOCAL_URL'))
139 define('PLL_LOCAL_URL', content_url('/polylang'));
140
141 // cookie name. no cookie will be used if set to false
142 if (!defined('PLL_COOKIE'))
143 define('PLL_COOKIE', 'pll_language');
144
145 // avoid loading polylang admin for frontend ajax requests
146 // special test for plupload which does not use jquery ajax and thus does not pass our ajax prefilter
147 // special test for customize_save done in frontend but for which we want to load the admin
148 if (!defined('PLL_AJAX_ON_FRONT')) {
149 $in = isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('upload-attachment', 'customize_save'));
150 define('PLL_AJAX_ON_FRONT', defined('DOING_AJAX') && DOING_AJAX && empty($_REQUEST['pll_ajax_backend']) && !$in);
151 }
152
153 // admin
154 if (!defined('PLL_ADMIN'))
155 define('PLL_ADMIN', defined('DOING_CRON') || (is_admin() && !PLL_AJAX_ON_FRONT));
156
157 // settings page whatever the tab
158 if (!defined('PLL_SETTINGS'))
159 define('PLL_SETTINGS', is_admin() && isset($_GET['page']) && $_GET['page'] == 'mlang');
160 }
161
162 /*
163 * Polylang initialization
164 * setups models and separate admin and frontend
165 *
166 * @since 1.2
167 */
168 public function init() {
169 global $polylang;
170
171 self::define_constants();
172 $options = get_option('polylang');
173
174 // plugin upgrade
175 if ($options && version_compare($options['version'], POLYLANG_VERSION, '<')) {
176 $upgrade = new PLL_Upgrade($options);
177 if (!$upgrade->upgrade()) // if the version is too old
178 return;
179 }
180
181 $class = apply_filters('pll_model', PLL_SETTINGS ? 'PLL_Admin_Model' : 'PLL_Model');
182 $model = new $class($options);
183 $links_model = $model->get_links_model();
184
185 if (PLL_ADMIN) {
186 $polylang = new PLL_Admin($links_model);
187 $polylang->init();
188 }
189 // do nothing on frontend if no language is defined
190 elseif ($model->get_languages_list()) {
191 $polylang = new PLL_Frontend($links_model);
192 $polylang->init();
193 }
194
195 if (!$model->get_languages_list())
196 do_action('pll_no_language_defined'); // to load overriden textdomains
197
198 // load wpml-config.xml
199 if (!defined('PLL_WPML_COMPAT') || PLL_WPML_COMPAT)
200 PLL_WPML_Config::instance();
201
202 do_action('pll_init');
203 }
204 }
205
206 new Polylang();
207