PluginProbe
Polylang / 2.3.6
Polylang v2.3.6
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 +47 -93 2.82.3.6 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,26 @@
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(
61 + $modules = array_merge( array(
74 62 'PLL_Settings_Url',
75 63 'PLL_Settings_Browser',
76 64 'PLL_Settings_Media',
77 65 'PLL_Settings_CPT',
78 - );
66 + 'PLL_Settings_Sync',
67 + 'PLL_Settings_WPML',
68 + 'PLL_Settings_Share_Slug',
69 + 'PLL_Settings_Translate_Slugs',
70 + ), $modules );
79 71 }
80 72
81 - $modules[] = 'PLL_Settings_Licenses';
82 -
83 73 /**
84 74 * Filter the list of setting modules
85 75 *
86 76 * @since 1.8
@@ -100,9 +90,9 @@
100 90 *
101 91 * @since 0.8
102 92 */
103 93 public function metabox_about() {
104 - include __DIR__ . '/view-about.php';
94 + include PLL_SETTINGS_INC . '/view-about.php';
105 95 }
106 96
107 97 /**
108 98 * Adds screen options and the about box in the languages admin panel
@@ -114,21 +104,18 @@
114 104 add_meta_box(
115 105 'pll-about-box',
116 106 __( 'About Polylang', 'polylang' ),
117 107 array( $this, 'metabox_about' ),
118 - 'toplevel_page_mlang',
108 + 'settings_page_mlang', // FIXME not shown in screen options
119 109 'normal'
120 110 );
121 111 }
122 112
123 - add_screen_option(
124 - 'per_page',
125 - array(
126 - 'label' => __( 'Languages', 'polylang' ),
127 - 'default' => 10,
128 - 'option' => 'pll_lang_per_page',
129 - )
130 - );
113 + add_screen_option( 'per_page', array(
114 + 'label' => __( 'Languages', 'polylang' ),
115 + 'default' => 10,
116 + 'option' => 'pll_lang_per_page',
117 + ) );
131 118
132 119 add_action( 'admin_notices', array( $this, 'notice_objects_with_no_lang' ) );
133 120 }
134 121
@@ -137,16 +124,13 @@
137 124 *
138 125 * @since 2.1
139 126 */
140 127 public function load_page_strings() {
141 - add_screen_option(
142 - 'per_page',
143 - array(
144 - 'label' => __( 'Strings translations', 'polylang' ),
145 - 'default' => 10,
146 - 'option' => 'pll_strings_per_page',
147 - )
148 - );
128 + add_screen_option( 'per_page', array(
129 + 'label' => __( 'Strings translations', 'polylang' ),
130 + 'default' => 10,
131 + 'option' => 'pll_strings_per_page',
132 + ) );
149 133 }
150 134
151 135 /**
152 136 * Save the "Views/Uploads per page" option set by this user
@@ -173,29 +157,19 @@
173 157 public function handle_actions( $action ) {
174 158 switch ( $action ) {
175 159 case 'add':
176 160 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
177 - $errors = $this->model->add_language( $_POST );
178 161
179 - if ( is_wp_error( $errors ) ) {
180 - foreach ( $errors->get_error_messages() as $message ) {
181 - 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' ) );
182 167 }
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 168
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 - }
169 + // Force checking for themes and plugins translations updates
170 + wp_clean_themes_cache();
171 + wp_clean_plugins_cache();
198 172 }
199 173 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
200 174 break;
201 175
@@ -201,10 +175,10 @@
201 175
202 176 case 'delete':
203 177 check_admin_referer( 'delete-lang' );
204 178
205 - if ( ! empty( $_GET['lang'] ) && $this->model->delete_language( (int) $_GET['lang'] ) ) {
206 - add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' );
179 + if ( ! empty( $_GET['lang'] ) ) {
180 + $this->model->delete_language( (int) $_GET['lang'] );
207 181 }
208 182
209 183 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
210 184 break;
@@ -210,18 +184,9 @@
210 184 break;
211 185
212 186 case 'update':
213 187 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 -
188 + $error = $this->model->update_language( $_POST );
224 189 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
225 190 break;
226 191
227 192 case 'default-lang':
@@ -250,25 +215,15 @@
250 215 break;
251 216
252 217 case 'activate':
253 218 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 - }
219 + $this->modules[ $_GET['module'] ]->activate();
260 220 self::redirect();
261 221 break;
262 222
263 223 case 'deactivate':
264 224 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 - }
225 + $this->modules[ $_GET['module'] ]->deactivate();
271 226 self::redirect();
272 227 break;
273 228
274 229 default:
@@ -302,11 +257,10 @@
302 257 break;
303 258 }
304 259
305 260 // 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
261 + $action = isset( $_REQUEST['pll_action'] ) ? $_REQUEST['pll_action'] : '';
262 + if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) {
309 263 $edit_lang = $this->model->get_language( (int) $_GET['lang'] );
310 264 } else {
311 265 $this->handle_actions( $action );
312 266 }
@@ -311,9 +265,9 @@
311 265 $this->handle_actions( $action );
312 266 }
313 267
314 268 // Displays the page
315 - include __DIR__ . '/view-languages.php';
269 + include PLL_SETTINGS_INC . '/view-languages.php';
316 270 }
317 271
318 272 /**
319 273 * Enqueues scripts and styles
@@ -338,9 +292,9 @@
338 292 if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) {
339 293 printf(
340 294 '<div class="error"><p>%s <a href="%s">%s</a></p></div>',
341 295 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' ) ),
296 + wp_nonce_url( '?page=mlang&amp;pll_action=content-default-lang&amp;noheader=true', 'content-default-lang' ),
343 297 esc_html__( 'You can set them all to the default language.', 'polylang' )
344 298 );
345 299 }
346 300 }
@@ -352,9 +306,9 @@
352 306 * @since 1.5
353 307 *
354 308 * @param array $args query arguments to add to the url
355 309 */
356 - public static function redirect( $args = array() ) {
310 + static public function redirect( $args = array() ) {
357 311 if ( $errors = get_settings_errors() ) {
358 312 set_transient( 'settings_errors', $errors, 30 );
359 313 $args['settings-updated'] = 1;
360 314 }
@@ -367,12 +321,12 @@
367 321 * Get the list of predefined languages
368 322 *
369 323 * @since 2.3
370 324 */
371 - public static function get_predefined_languages() {
372 - require_once ABSPATH . 'wp-admin/includes/translation-install.php';
325 + public function get_predefined_languages() {
326 + require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
327 + include PLL_SETTINGS_INC . '/languages.php';
373 328
374 - $languages = include __DIR__ . '/languages.php';
375 329 $translations = wp_get_available_translations();
376 330
377 331 // Keep only languages with existing WP language pack
378 332 // Unless the transient has expired and we don't have an internet connection to refresh it