PluginProbe
Polylang / 2.5.2
Polylang v2.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 | settings/settings.php +41 -78 2.82.5.2 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * A class for the Polylang settings pages
8 5 * accessible in $polylang global object
@@ -19,24 +16,11 @@
19 16 *
20 17 * @since 1.2
21 18 */
22 19 class PLL_Settings extends PLL_Admin_Base {
20 + protected $active_tab, $modules;
23 21
24 22 /**
25 - * Name of the active module
26 - *
27 - * @var string $active_tab
28 - */
29 - protected $active_tab;
30 -
31 - /**
32 - * Array of modules classes
33 - *
34 - * @var array $modules
35 - */
36 - protected $modules;
37 -
38 - /**
39 23 * Constructor
40 24 *
41 25 * @since 1.2
42 26 *
@@ -44,14 +28,15 @@
44 28 */
45 29 public function __construct( &$links_model ) {
46 30 parent::__construct( $links_model );
47 31
48 - if ( isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
49 - $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 );
50 34 }
51 35
52 36 PLL_Admin_Strings::init();
53 37
38 + // FIXME put this as late as possible
54 39 add_action( 'admin_init', array( $this, 'register_settings_modules' ) );
55 40
56 41 // Adds screen options and the about box in the languages admin panel
57 42 add_action( 'load-toplevel_page_mlang', array( $this, 'load_page' ) );
@@ -66,21 +51,29 @@
66 51 *
67 52 * @since 1.8
68 53 */
69 54 public function register_settings_modules() {
70 - $modules = array();
55 + $modules = array(
56 + 'PLL_Settings_Tools',
57 + 'PLL_Settings_Licenses',
58 + );
71 59
72 60 if ( $this->model->get_languages_list() ) {
73 - $modules = array(
74 - 'PLL_Settings_Url',
75 - 'PLL_Settings_Browser',
76 - 'PLL_Settings_Media',
77 - 'PLL_Settings_CPT',
61 + $modules = array_merge(
62 + array(
63 + 'PLL_Settings_Url',
64 + 'PLL_Settings_Browser',
65 + 'PLL_Settings_Media',
66 + 'PLL_Settings_CPT',
67 + 'PLL_Settings_Sync',
68 + 'PLL_Settings_WPML',
69 + 'PLL_Settings_Share_Slug',
70 + 'PLL_Settings_Translate_Slugs',
71 + ),
72 + $modules
78 73 );
79 74 }
80 75
81 - $modules[] = 'PLL_Settings_Licenses';
82 -
83 76 /**
84 77 * Filter the list of setting modules
85 78 *
86 79 * @since 1.8
@@ -100,9 +93,9 @@
100 93 *
101 94 * @since 0.8
102 95 */
103 96 public function metabox_about() {
104 - include __DIR__ . '/view-about.php';
97 + include PLL_SETTINGS_INC . '/view-about.php';
105 98 }
106 99
107 100 /**
108 101 * Adds screen options and the about box in the languages admin panel
@@ -114,9 +107,9 @@
114 107 add_meta_box(
115 108 'pll-about-box',
116 109 __( 'About Polylang', 'polylang' ),
117 110 array( $this, 'metabox_about' ),
118 - 'toplevel_page_mlang',
111 + 'settings_page_mlang', // FIXME not shown in screen options
119 112 'normal'
120 113 );
121 114 }
122 115
@@ -173,29 +166,19 @@
173 166 public function handle_actions( $action ) {
174 167 switch ( $action ) {
175 168 case 'add':
176 169 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
177 - $errors = $this->model->add_language( $_POST );
178 170
179 - if ( is_wp_error( $errors ) ) {
180 - foreach ( $errors->get_error_messages() as $message ) {
181 - add_settings_error( 'general', 'pll_add_language', $message );
171 + if ( $this->model->add_language( $_POST ) && 'en_US' !== $_POST['locale'] ) {
172 + // Attempts to install the language pack
173 + require_once ABSPATH . 'wp-admin/includes/translation-install.php';
174 + if ( ! wp_download_language_pack( $_POST['locale'] ) ) {
175 + add_settings_error( 'general', 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ) );
182 176 }
183 - } else {
184 - add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' );
185 - $locale = sanitize_text_field( wp_unslash( $_POST['locale'] ) ); // phpcs:ignore WordPress.Security
186 177
187 - if ( 'en_US' !== $locale ) {
188 - // Attempts to install the language pack
189 - require_once ABSPATH . 'wp-admin/includes/translation-install.php';
190 - if ( ! wp_download_language_pack( $locale ) ) {
191 - add_settings_error( 'general', 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ) );
192 - }
193 -
194 - // Force checking for themes and plugins translations updates
195 - wp_clean_themes_cache();
196 - wp_clean_plugins_cache();
197 - }
178 + // Force checking for themes and plugins translations updates
179 + wp_clean_themes_cache();
180 + wp_clean_plugins_cache();
198 181 }
199 182 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
200 183 break;
201 184
@@ -201,10 +184,10 @@
201 184
202 185 case 'delete':
203 186 check_admin_referer( 'delete-lang' );
204 187
205 - if ( ! empty( $_GET['lang'] ) && $this->model->delete_language( (int) $_GET['lang'] ) ) {
206 - add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' );
188 + if ( ! empty( $_GET['lang'] ) ) {
189 + $this->model->delete_language( (int) $_GET['lang'] );
207 190 }
208 191
209 192 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
210 193 break;
@@ -210,18 +193,9 @@
210 193 break;
211 194
212 195 case 'update':
213 196 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
214 - $errors = $this->model->update_language( $_POST );
215 -
216 - if ( is_wp_error( $errors ) ) {
217 - foreach ( $errors->get_error_messages() as $message ) {
218 - add_settings_error( 'general', 'pll_update_language', $message );
219 - }
220 - } else {
221 - add_settings_error( 'general', 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'updated' );
222 - }
223 -
197 + $error = $this->model->update_language( $_POST );
224 198 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
225 199 break;
226 200
227 201 case 'default-lang':
@@ -250,25 +224,15 @@
250 224 break;
251 225
252 226 case 'activate':
253 227 check_admin_referer( 'pll_activate' );
254 - if ( isset( $_GET['module'] ) ) {
255 - $module = sanitize_key( $_GET['module'] );
256 - if ( isset( $this->modules[ $module ] ) ) {
257 - $this->modules[ $module ]->activate();
258 - }
259 - }
228 + $this->modules[ $_GET['module'] ]->activate();
260 229 self::redirect();
261 230 break;
262 231
263 232 case 'deactivate':
264 233 check_admin_referer( 'pll_deactivate' );
265 - if ( isset( $_GET['module'] ) ) {
266 - $module = sanitize_key( $_GET['module'] );
267 - if ( isset( $this->modules[ $module ] ) ) {
268 - $this->modules[ $module ]->deactivate();
269 - }
270 - }
234 + $this->modules[ $_GET['module'] ]->deactivate();
271 235 self::redirect();
272 236 break;
273 237
274 238 default:
@@ -302,11 +266,10 @@
302 266 break;
303 267 }
304 268
305 269 // Handle user input
306 - $action = isset( $_REQUEST['pll_action'] ) ? sanitize_key( $_REQUEST['pll_action'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
307 - if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
308 - // phpcs:ignore WordPress.Security.NonceVerification, WordPressVIPMinimum.Variables.VariableAnalysis.UnusedVariable
270 + $action = isset( $_REQUEST['pll_action'] ) ? $_REQUEST['pll_action'] : '';
271 + if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) {
309 272 $edit_lang = $this->model->get_language( (int) $_GET['lang'] );
310 273 } else {
311 274 $this->handle_actions( $action );
312 275 }
@@ -311,9 +274,9 @@
311 274 $this->handle_actions( $action );
312 275 }
313 276
314 277 // Displays the page
315 - include __DIR__ . '/view-languages.php';
278 + include PLL_SETTINGS_INC . '/view-languages.php';
316 279 }
317 280
318 281 /**
319 282 * Enqueues scripts and styles
@@ -338,9 +301,9 @@
338 301 if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) {
339 302 printf(
340 303 '<div class="error"><p>%s <a href="%s">%s</a></p></div>',
341 304 esc_html__( 'There are posts, pages, categories or tags without language.', 'polylang' ),
342 - esc_url( wp_nonce_url( '?page=mlang&pll_action=content-default-lang&noheader=true', 'content-default-lang' ) ),
305 + wp_nonce_url( '?page=mlang&amp;pll_action=content-default-lang&amp;noheader=true', 'content-default-lang' ),
343 306 esc_html__( 'You can set them all to the default language.', 'polylang' )
344 307 );
345 308 }
346 309 }
@@ -367,12 +330,12 @@
367 330 * Get the list of predefined languages
368 331 *
369 332 * @since 2.3
370 333 */
371 - public static function get_predefined_languages() {
334 + public function get_predefined_languages() {
372 335 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
336 + include PLL_SETTINGS_INC . '/languages.php';
373 337
374 - $languages = include __DIR__ . '/languages.php';
375 338 $translations = wp_get_available_translations();
376 339
377 340 // Keep only languages with existing WP language pack
378 341 // Unless the transient has expired and we don't have an internet connection to refresh it