PluginProbe
Polylang / 1.7.4
Polylang v1.7.4
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.4, at polylang.php

206 lines 6.4 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.4
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-2015 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.7.4');
37 define('PLL_MIN_WP_VERSION', '3.8');
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 define('PLL_INSTALL_INC', POLYLANG_DIR . '/install');
46
47 // default directory to store user data such as custom flags
48 if (!defined('PLL_LOCAL_DIR'))
49 define('PLL_LOCAL_DIR', WP_CONTENT_DIR . '/polylang');
50
51 // includes local config file if exists
52 if (file_exists(PLL_LOCAL_DIR . '/pll-config.php'))
53 include_once(PLL_LOCAL_DIR . '/pll-config.php');
54
55 /*
56 * controls the plugin, as well as activation, and deactivation
57 *
58 * @since 0.1
59 */
60 class Polylang {
61
62 /*
63 * constructor
64 *
65 * @since 0.1
66 */
67 public function __construct() {
68 // FIXME maybe not available on every installations but widely used by WP plugins
69 spl_autoload_register(array(&$this, 'autoload')); // autoload classes
70
71 $install = new PLL_Install(POLYLANG_BASENAME);
72
73 // stopping here if we are going to deactivate the plugin (avoids breaking rewrite rules)
74 if ($install->is_deactivation())
75 return;
76
77 // plugin initialization
78 // take no action before all plugins are loaded
79 add_action('plugins_loaded', array(&$this, 'init'), 1);
80
81 // override load text domain waiting for the language to be defined
82 // here for plugins which load text domain as soon as loaded :(
83 if (!defined('PLL_OLT') || PLL_OLT)
84 PLL_OLT_Manager::instance();
85
86 // loads the API
87 require_once(PLL_INC.'/api.php');
88
89 // WPML API
90 if (!defined('PLL_WPML_COMPAT') || PLL_WPML_COMPAT)
91 PLL_WPML_Compat::instance();
92
93 // extra code for compatibility with some plugins
94 if (!defined('PLL_PLUGINS_COMPAT') || PLL_PLUGINS_COMPAT)
95 PLL_Plugins_Compat::instance();
96 }
97
98 /*
99 * autoload classes
100 *
101 * @since 1.2
102 *
103 * @param string $class
104 */
105 public function autoload($class) {
106 // not a Polylang class
107 if (0 !== strncmp('PLL_', $class, 4))
108 return;
109
110 $class = str_replace('_', '-', strtolower(substr($class, 4)));
111
112 if ((0 === strpos($class, 'choose') || 0 === strpos($class, 'frontend')) && file_exists($file = PLL_FRONT_INC . "/$class.php"))
113 require_once($file);
114
115 elseif ((0 === strpos($class, 'install') || 'upgrade' === $class) && file_exists($file = PLL_INSTALL_INC . "/$class.php"))
116 require_once($file);
117
118 elseif ((0 === strpos($class, 'admin') || 0 === strpos($class, 'table') || 'settings' === $class || 'wp-import' === $class) && file_exists($file = PLL_ADMIN_INC . "/$class.php"))
119 require_once($file);
120
121 elseif (file_exists($file = PLL_INC . "/$class.php"))
122 require_once($file);
123 }
124
125 /*
126 * defines constants
127 * may be overriden by a plugin if set before plugins_loaded, 1
128 *
129 * @since 1.6
130 */
131 static public function define_constants() {
132 // our url. Don't use WP_PLUGIN_URL http://wordpress.org/support/topic/ssl-doesnt-work-properly
133 if (!defined('POLYLANG_URL'))
134 define('POLYLANG_URL', plugins_url('', __FILE__));
135
136 // default url to access user data such as custom flags
137 if (!defined('PLL_LOCAL_URL'))
138 define('PLL_LOCAL_URL', content_url('/polylang'));
139
140 // cookie name. no cookie will be used if set to false
141 if (!defined('PLL_COOKIE'))
142 define('PLL_COOKIE', 'pll_language');
143
144 // avoid loading polylang admin for frontend ajax requests
145 // special test for plupload which does not use jquery ajax and thus does not pass our ajax prefilter
146 // special test for customize_save done in frontend but for which we want to load the admin
147 if (!defined('PLL_AJAX_ON_FRONT')) {
148 $in = isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('upload-attachment', 'customize_save'));
149 define('PLL_AJAX_ON_FRONT', defined('DOING_AJAX') && DOING_AJAX && empty($_REQUEST['pll_ajax_backend']) && !$in);
150 }
151
152 // admin
153 if (!defined('PLL_ADMIN'))
154 define('PLL_ADMIN', defined('DOING_CRON') || (is_admin() && !PLL_AJAX_ON_FRONT));
155
156 // settings page whatever the tab
157 if (!defined('PLL_SETTINGS'))
158 define('PLL_SETTINGS', is_admin() && isset($_GET['page']) && $_GET['page'] == 'mlang');
159 }
160
161 /*
162 * Polylang initialization
163 * setups models and separate admin and frontend
164 *
165 * @since 1.2
166 */
167 public function init() {
168 global $polylang;
169
170 self::define_constants();
171 $options = get_option('polylang');
172
173 // plugin upgrade
174 if ($options && version_compare($options['version'], POLYLANG_VERSION, '<')) {
175 $upgrade = new PLL_Upgrade($options);
176 if (!$upgrade->upgrade()) // if the version is too old
177 return;
178 }
179
180 $class = apply_filters('pll_model', PLL_SETTINGS ? 'PLL_Admin_Model' : 'PLL_Model');
181 $model = new $class($options);
182 $links_model = $model->get_links_model();
183
184 if (PLL_ADMIN) {
185 $polylang = new PLL_Admin($links_model);
186 $polylang->init();
187 }
188 // do nothing on frontend if no language is defined
189 elseif ($model->get_languages_list()) {
190 $polylang = new PLL_Frontend($links_model);
191 $polylang->init();
192 }
193
194 if (!$model->get_languages_list())
195 do_action('pll_no_language_defined'); // to load overriden textdomains
196
197 // load wpml-config.xml
198 if (!defined('PLL_WPML_COMPAT') || PLL_WPML_COMPAT)
199 PLL_WPML_Config::instance();
200
201 do_action('pll_init');
202 }
203 }
204
205 new Polylang();
206