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 +45 -107 2.7.22.3.6 View file →
@@ -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,18 +28,14 @@
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 41 // Adds screen options and the about box in the languages admin panel
@@ -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
@@ -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
@@ -189,29 +157,19 @@
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 173 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
216 174 break;
217 175
@@ -217,10 +175,10 @@
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 183 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
226 184 break;
@@ -226,18 +184,9 @@
226 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 );
231 -
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 -
188 + $error = $this->model->update_language( $_POST );
240 189 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
241 190 break;
242 191
243 192 case 'default-lang':
@@ -266,25 +215,15 @@
266 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 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 227 break;
289 228
290 229 default:
@@ -318,11 +257,10 @@
318 257 break;
319 258 }
320 259
321 260 // 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
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 }
@@ -354,9 +292,9 @@
354 292 if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) {
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,9 +306,9 @@
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 }
@@ -383,12 +321,12 @@
383 321 * Get the list of predefined languages
384 322 *
385 323 * @since 2.3
386 324 */
387 - public static function get_predefined_languages() {
388 - 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';
389 328
390 - $languages = include PLL_SETTINGS_INC . '/languages.php';
391 329 $translations = wp_get_available_translations();
392 330
393 331 // Keep only languages with existing WP language pack
394 332 // Unless the transient has expired and we don't have an internet connection to refresh it