PluginProbe
Polylang / 2.1
Polylang v2.1
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 | settings/settings.php +75 -176 2.7.22.1 View file →
@@ -3,9 +3,9 @@
3 3 /**
4 4 * A class for the Polylang settings pages
5 5 * accessible in $polylang global object
6 6 *
7 - * Properties:
7 + * properties:
8 8 * options => inherited, reference to Polylang options array
9 9 * model => inherited, reference to PLL_Model object
10 10 * links_model => inherited, reference to PLL_Links_Model object
11 11 * links => inherited, reference to PLL_Admin_Links object
@@ -16,31 +16,11 @@
16 16 *
17 17 * @since 1.2
18 18 */
19 19 class PLL_Settings extends PLL_Admin_Base {
20 + protected $active_tab, $modules;
20 21
21 22 /**
22 - * Name of the active module
23 - *
24 - * @var string $active_tab
25 - */
26 - protected $active_tab;
27 -
28 - /**
29 - * Array of modules classes
30 - *
31 - * @var array $modules
32 - */
33 - protected $modules;
34 -
35 - /**
36 - * Reference to PLL_Import_Export
37 - *
38 - * @var PLL_Import_Export $import_export
39 - */
40 - protected $import_export;
41 -
42 - /**
43 23 * Constructor
44 24 *
45 25 * @since 1.2
46 26 *
@@ -48,26 +28,22 @@
48 28 */
49 29 public function __construct( &$links_model ) {
50 30 parent::__construct( $links_model );
51 31
52 - if ( isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
53 - $this->active_tab = 'mlang' === $_GET['page'] ? 'lang' : substr( sanitize_key( $_GET['page'] ), 6 ); // phpcs:ignore WordPress.Security.NonceVerification
32 + if ( isset( $_GET['page'] ) ) {
33 + $this->active_tab = 'mlang' === $_GET['page'] ? 'lang' : substr( $_GET['page'], 6 );
54 34 }
55 35
56 36 PLL_Admin_Strings::init();
57 37
58 - if ( class_exists( 'PLL_Import_Export' ) ) {
59 - $this->import_export = new PLL_Import_Export( $this );
60 - }
61 -
62 38 // FIXME put this as late as possible
63 39 add_action( 'admin_init', array( $this, 'register_settings_modules' ) );
64 40
65 - // Adds screen options and the about box in the languages admin panel
66 - add_action( 'load-toplevel_page_mlang', array( $this, 'load_page' ) );
67 - add_action( 'load-languages_page_mlang_strings', array( $this, 'load_page_strings' ) );
41 + // adds screen options and the about box in the languages admin panel
42 + add_action( 'load-toplevel_page_mlang', array( $this, 'load_page' ) );
43 + add_action( 'load-languages_page_mlang_strings', array( $this, 'load_page_strings' ) );
68 44
69 - // Saves per-page value in screen option
45 + // saves per-page value in screen option
70 46 add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
71 47 }
72 48
73 49 /**
@@ -76,25 +52,23 @@
76 52 * @since 1.8
77 53 */
78 54 public function register_settings_modules() {
79 55 $modules = array(
56 + 'PLL_Settings_Tools',
80 57 'PLL_Settings_Licenses',
81 58 );
82 59
83 60 if ( $this->model->get_languages_list() ) {
84 - $modules = array_merge(
85 - array(
86 - 'PLL_Settings_Url',
87 - 'PLL_Settings_Browser',
88 - 'PLL_Settings_Media',
89 - 'PLL_Settings_CPT',
90 - 'PLL_Settings_Sync',
91 - 'PLL_Settings_WPML',
92 - 'PLL_Settings_Share_Slug',
93 - 'PLL_Settings_Translate_Slugs',
94 - ),
95 - $modules
96 - );
61 + $modules = array_merge( array(
62 + 'PLL_Settings_Url',
63 + 'PLL_Settings_Browser',
64 + 'PLL_Settings_Media',
65 + 'PLL_Settings_CPT',
66 + 'PLL_Settings_Sync',
67 + 'PLL_Settings_WPML',
68 + 'PLL_Settings_Share_Slug',
69 + 'PLL_Settings_Translate_Slugs',
70 + ), $modules );
97 71 }
98 72
99 73 /**
100 74 * Filter the list of setting modules
@@ -116,9 +90,9 @@
116 90 *
117 91 * @since 0.8
118 92 */
119 93 public function metabox_about() {
120 - include PLL_SETTINGS_INC . '/view-about.php';
94 + include( PLL_SETTINGS_INC.'/view-about.php' );
121 95 }
122 96
123 97 /**
124 98 * Adds screen options and the about box in the languages admin panel
@@ -130,21 +104,18 @@
130 104 add_meta_box(
131 105 'pll-about-box',
132 106 __( 'About Polylang', 'polylang' ),
133 107 array( $this, 'metabox_about' ),
134 - 'toplevel_page_mlang',
108 + 'settings_page_mlang', // FIXME not shown in screen options
135 109 'normal'
136 110 );
137 111 }
138 112
139 - add_screen_option(
140 - 'per_page',
141 - array(
142 - 'label' => __( 'Languages', 'polylang' ),
143 - 'default' => 10,
144 - 'option' => 'pll_lang_per_page',
145 - )
146 - );
113 + add_screen_option( 'per_page', array(
114 + 'label' => __( 'Languages', 'polylang' ),
115 + 'default' => 10,
116 + 'option' => 'pll_lang_per_page',
117 + ) );
147 118
148 119 add_action( 'admin_notices', array( $this, 'notice_objects_with_no_lang' ) );
149 120 }
150 121
@@ -153,16 +124,13 @@
153 124 *
154 125 * @since 2.1
155 126 */
156 127 public function load_page_strings() {
157 - add_screen_option(
158 - 'per_page',
159 - array(
160 - 'label' => __( 'Strings translations', 'polylang' ),
161 - 'default' => 10,
162 - 'option' => 'pll_strings_per_page',
163 - )
164 - );
128 + add_screen_option( 'per_page', array(
129 + 'label' => __( 'Strings translations', 'polylang' ),
130 + 'default' => 10,
131 + 'option' => 'pll_strings_per_page',
132 + ) );
165 133 }
166 134
167 135 /**
168 136 * Save the "Views/Uploads per page" option set by this user
@@ -168,11 +136,11 @@
168 136 * Save the "Views/Uploads per page" option set by this user
169 137 *
170 138 * @since 0.9.5
171 139 *
172 - * @param mixed $status false or value returned by previous filter
173 - * @param string $option Name of the option being changed
174 - * @param string $value Value of the option
140 + * @param mixed $status false or value returned by previous filter
141 + * @param string $option Name of the option being changed
142 + * @param string $value Value of the option
175 143 *
176 144 * @return string New value if this is our option, otherwise nothing
177 145 */
178 146 public function set_screen_option( $status, $option, $value ) {
@@ -189,58 +157,39 @@
189 157 public function handle_actions( $action ) {
190 158 switch ( $action ) {
191 159 case 'add':
192 160 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
193 - $errors = $this->model->add_language( $_POST );
194 161
195 - if ( is_wp_error( $errors ) ) {
196 - foreach ( $errors->get_error_messages() as $message ) {
197 - add_settings_error( 'general', 'pll_add_language', $message );
162 + if ( $this->model->add_language( $_POST ) && 'en_US' !== $_POST['locale'] ) {
163 + // attempts to install the language pack
164 + require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
165 + if ( ! wp_download_language_pack( $_POST['locale'] ) ) {
166 + add_settings_error( 'general', 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ) );
198 167 }
199 - } else {
200 - add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' );
201 - $locale = sanitize_text_field( wp_unslash( $_POST['locale'] ) ); // phpcs:ignore WordPress.Security
202 168
203 - if ( 'en_US' !== $locale ) {
204 - // Attempts to install the language pack
205 - require_once ABSPATH . 'wp-admin/includes/translation-install.php';
206 - if ( ! wp_download_language_pack( $locale ) ) {
207 - add_settings_error( 'general', 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ) );
208 - }
209 -
210 - // Force checking for themes and plugins translations updates
211 - wp_clean_themes_cache();
212 - wp_clean_plugins_cache();
213 - }
169 + // force checking for themes and plugins translations updates
170 + wp_clean_themes_cache();
171 + wp_clean_plugins_cache();
214 172 }
215 - self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
216 - break;
173 + self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true )
174 + break;
217 175
218 176 case 'delete':
219 177 check_admin_referer( 'delete-lang' );
220 178
221 - if ( ! empty( $_GET['lang'] ) && $this->model->delete_language( (int) $_GET['lang'] ) ) {
222 - add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' );
179 + if ( ! empty( $_GET['lang'] ) ) {
180 + $this->model->delete_language( (int) $_GET['lang'] );
223 181 }
224 182
225 - self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
226 - break;
183 + self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true )
184 + break;
227 185
228 186 case 'update':
229 187 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
230 - $errors = $this->model->update_language( $_POST );
188 + $error = $this->model->update_language( $_POST );
189 + self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true )
190 + break;
231 191
232 - if ( is_wp_error( $errors ) ) {
233 - foreach ( $errors->get_error_messages() as $message ) {
234 - add_settings_error( 'general', 'pll_update_language', $message );
235 - }
236 - } else {
237 - add_settings_error( 'general', 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'updated' );
238 - }
239 -
240 - self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
241 - break;
242 -
243 192 case 'default-lang':
244 193 check_admin_referer( 'default-lang' );
245 194
246 195 if ( $lang = $this->model->get_language( (int) $_GET['lang'] ) ) {
@@ -246,10 +195,10 @@
246 195 if ( $lang = $this->model->get_language( (int) $_GET['lang'] ) ) {
247 196 $this->model->update_default_lang( $lang->slug );
248 197 }
249 198
250 - self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
251 - break;
199 + self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true )
200 + break;
252 201
253 202 case 'content-default-lang':
254 203 check_admin_referer( 'content-default-lang' );
255 204
@@ -261,32 +210,22 @@
261 210 $this->model->set_language_in_mass( 'term', $nolang['terms'], $this->options['default_lang'] );
262 211 }
263 212 }
264 213
265 - self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
266 - break;
214 + self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true )
215 + break;
267 216
268 217 case 'activate':
269 218 check_admin_referer( 'pll_activate' );
270 - if ( isset( $_GET['module'] ) ) {
271 - $module = sanitize_key( $_GET['module'] );
272 - if ( isset( $this->modules[ $module ] ) ) {
273 - $this->modules[ $module ]->activate();
274 - }
275 - }
219 + $this->modules[ $_GET['module'] ]->activate();
276 220 self::redirect();
277 - break;
221 + break;
278 222
279 223 case 'deactivate':
280 224 check_admin_referer( 'pll_deactivate' );
281 - if ( isset( $_GET['module'] ) ) {
282 - $module = sanitize_key( $_GET['module'] );
283 - if ( isset( $this->modules[ $module ] ) ) {
284 - $this->modules[ $module ]->deactivate();
285 - }
286 - }
225 + $this->modules[ $_GET['module'] ]->deactivate();
287 226 self::redirect();
288 - break;
227 + break;
289 228
290 229 default:
291 230 /**
292 231 * Fires when a non default action has been sent to Polylang settings
@@ -293,15 +232,15 @@
293 232 *
294 233 * @since 1.8
295 234 */
296 235 do_action( "mlang_action_$action" );
297 - break;
236 + break;
298 237 }
299 238 }
300 239
301 240 /**
302 241 * Displays the 3 tabs pages: languages, strings translations, settings
303 - * Also manages user input for these pages
242 + * also manages user input for these pages
304 243 *
305 244 * @since 0.1
306 245 */
307 246 public function languages_page() {
@@ -306,30 +245,29 @@
306 245 */
307 246 public function languages_page() {
308 247 switch ( $this->active_tab ) {
309 248 case 'lang':
310 - // Prepare the list table of languages
249 + // prepare the list table of languages
311 250 $list_table = new PLL_Table_Languages();
312 251 $list_table->prepare_items( $this->model->get_languages_list() );
313 - break;
252 + break;
314 253
315 254 case 'strings':
316 255 $string_table = new PLL_Table_String( $this->model->get_languages_list() );
317 256 $string_table->prepare_items();
318 - break;
257 + break;
319 258 }
320 259
321 - // Handle user input
322 - $action = isset( $_REQUEST['pll_action'] ) ? sanitize_key( $_REQUEST['pll_action'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
323 - if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
324 - // phpcs:ignore WordPress.Security.NonceVerification, WordPressVIPMinimum.Variables.VariableAnalysis.UnusedVariable
260 + // handle user input
261 + $action = isset( $_REQUEST['pll_action'] ) ? $_REQUEST['pll_action'] : '';
262 + if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) {
325 263 $edit_lang = $this->model->get_language( (int) $_GET['lang'] );
326 264 } else {
327 265 $this->handle_actions( $action );
328 266 }
329 267
330 - // Displays the page
331 - include PLL_SETTINGS_INC . '/view-languages.php';
268 + // displays the page
269 + include( PLL_SETTINGS_INC . '/view-languages.php' );
332 270 }
333 271
334 272 /**
335 273 * Enqueues scripts and styles
@@ -338,9 +276,9 @@
338 276 parent::admin_enqueue_scripts();
339 277
340 278 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
341 279
342 - wp_enqueue_script( 'pll_admin', plugins_url( '/js/admin' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu' ), POLYLANG_VERSION );
280 + wp_enqueue_script( 'pll_admin', plugins_url( '/js/admin' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu' ), POLYLANG_VERSION );
343 281 wp_localize_script( 'pll_admin', 'pll_flag_base_url', plugins_url( '/flags/', POLYLANG_FILE ) );
344 282
345 283 wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/selectmenu' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION );
346 284 }
@@ -350,13 +288,13 @@
350 288 *
351 289 * @since 1.8
352 290 */
353 291 public function notice_objects_with_no_lang() {
354 - if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) {
292 + if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang() ) {
355 293 printf(
356 294 '<div class="error"><p>%s <a href="%s">%s</a></p></div>',
357 295 esc_html__( 'There are posts, pages, categories or tags without language.', 'polylang' ),
358 - esc_url( wp_nonce_url( '?page=mlang&pll_action=content-default-lang&noheader=true', 'content-default-lang' ) ),
296 + wp_nonce_url( '?page=mlang&amp;pll_action=content-default-lang&amp;noheader=true', 'content-default-lang' ),
359 297 esc_html__( 'You can set them all to the default language.', 'polylang' )
360 298 );
361 299 }
362 300 }
@@ -368,53 +306,14 @@
368 306 * @since 1.5
369 307 *
370 308 * @param array $args query arguments to add to the url
371 309 */
372 - public static function redirect( $args = array() ) {
310 + static public function redirect( $args = array() ) {
373 311 if ( $errors = get_settings_errors() ) {
374 312 set_transient( 'settings_errors', $errors, 30 );
375 313 $args['settings-updated'] = 1;
376 314 }
377 - // Remove possible 'pll_action' and 'lang' query args from the referer before redirecting
378 - wp_safe_redirect( add_query_arg( $args, remove_query_arg( array( 'pll_action', 'lang' ), wp_get_referer() ) ) );
315 + // remove possible 'pll_action' and 'lang' query args from the referer before redirecting
316 + wp_safe_redirect( add_query_arg( $args, remove_query_arg( array( 'pll_action', 'lang' ), wp_get_referer() ) ) );
379 317 exit;
380 - }
381 -
382 - /**
383 - * Get the list of predefined languages
384 - *
385 - * @since 2.3
386 - */
387 - public static function get_predefined_languages() {
388 - require_once ABSPATH . 'wp-admin/includes/translation-install.php';
389 -
390 - $languages = include PLL_SETTINGS_INC . '/languages.php';
391 - $translations = wp_get_available_translations();
392 -
393 - // Keep only languages with existing WP language pack
394 - // Unless the transient has expired and we don't have an internet connection to refresh it
395 - if ( ! empty( $translations ) ) {
396 - $translations['en_US'] = ''; // Languages packs don't include en_US
397 - $languages = array_intersect_key( $languages, $translations );
398 - }
399 -
400 - /**
401 - * Filter the list of predefined languages
402 - *
403 - * @since 1.7.10
404 - * @since 2.3 The languages arrays use associative keys instead of numerical keys
405 - * @see settings/languages.php
406 - *
407 - * @param array $languages
408 - */
409 - $languages = apply_filters( 'pll_predefined_languages', $languages );
410 -
411 - // Keep only languages with all necessary informations
412 - foreach ( $languages as $k => $lang ) {
413 - if ( ! isset( $lang['code'], $lang['locale'], $lang['name'], $lang['dir'], $lang['flag'] ) ) {
414 - unset( $languages[ $k ] );
415 - }
416 - }
417 -
418 - return $languages;
419 318 }
420 319 }