PluginProbe
Polylang / 2.5
Polylang v2.5
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 +58 -115 3.02.5 View file →
@@ -1,51 +1,42 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 - * A class for the Polylang settings pages, accessible from @see PLL().
4 + * A class for the Polylang settings pages
5 + * accessible in $polylang global object
8 6 *
7 + * Properties:
8 + * options => inherited, reference to Polylang options array
9 + * model => inherited, reference to PLL_Model object
10 + * links_model => inherited, reference to PLL_Links_Model object
11 + * links => inherited, reference to PLL_Admin_Links object
12 + * static_pages => inherited, reference to PLL_Admin_Static_Pages object
13 + * filters_links => inherited, reference to PLL_Filters_Links object
14 + * curlang => inherited, optional, current language used to filter admin content
15 + * pref_lang => inherited, preferred language used as default when saving posts or terms
16 + *
9 17 * @since 1.2
10 18 */
11 19 class PLL_Settings extends PLL_Admin_Base {
20 + protected $active_tab, $modules;
12 21
13 22 /**
14 - * @var PLL_Admin_Model
15 - */
16 - public $model;
17 -
18 - /**
19 - * Name of the active module.
20 - *
21 - * @var string
22 - */
23 - protected $active_tab;
24 -
25 - /**
26 - * Array of modules classes.
27 - *
28 - * @var PLL_Settings_Module[]
29 - */
30 - protected $modules;
31 -
32 - /**
33 23 * Constructor
34 24 *
35 25 * @since 1.2
36 26 *
37 - * @param PLL_Links_Model $links_model Reference to the links model.
27 + * @param object $links_model
38 28 */
39 29 public function __construct( &$links_model ) {
40 30 parent::__construct( $links_model );
41 31
42 - if ( isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
43 - $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 );
44 34 }
45 35
46 36 PLL_Admin_Strings::init();
47 37
38 + // FIXME put this as late as possible
48 39 add_action( 'admin_init', array( $this, 'register_settings_modules' ) );
49 40
50 41 // Adds screen options and the about box in the languages admin panel
51 42 add_action( 'load-toplevel_page_mlang', array( $this, 'load_page' ) );
@@ -58,25 +49,31 @@
58 49 /**
59 50 * Initializes the modules
60 51 *
61 52 * @since 1.8
62 - *
63 - * @return void
64 53 */
65 54 public function register_settings_modules() {
66 - $modules = array();
55 + $modules = array(
56 + 'PLL_Settings_Tools',
57 + 'PLL_Settings_Licenses',
58 + );
67 59
68 60 if ( $this->model->get_languages_list() ) {
69 - $modules = array(
70 - 'PLL_Settings_Url',
71 - 'PLL_Settings_Browser',
72 - 'PLL_Settings_Media',
73 - '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
74 73 );
75 74 }
76 75
77 - $modules[] = 'PLL_Settings_Licenses';
78 -
79 76 /**
80 77 * Filter the list of setting modules
81 78 *
82 79 * @since 1.8
@@ -94,13 +91,11 @@
94 91 /**
95 92 * Loads the about metabox
96 93 *
97 94 * @since 0.8
98 - *
99 - * @return void
100 95 */
101 96 public function metabox_about() {
102 - include __DIR__ . '/view-about.php';
97 + include PLL_SETTINGS_INC . '/view-about.php';
103 98 }
104 99
105 100 /**
106 101 * Adds screen options and the about box in the languages admin panel
@@ -105,10 +100,8 @@
105 100 /**
106 101 * Adds screen options and the about box in the languages admin panel
107 102 *
108 103 * @since 0.9.5
109 - *
110 - * @return void
111 104 */
112 105 public function load_page() {
113 106 if ( ! defined( 'PLL_DISPLAY_ABOUT' ) || PLL_DISPLAY_ABOUT ) {
114 107 add_meta_box(
@@ -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
@@ -135,10 +128,8 @@
135 128 /**
136 129 * Adds screen options in the strings translations admin panel
137 130 *
138 131 * @since 2.1
139 - *
140 - * @return void
141 132 */
142 133 public function load_page_strings() {
143 134 add_screen_option(
144 135 'per_page',
@@ -170,35 +161,24 @@
170 161 *
171 162 * @since 1.9
172 163 *
173 164 * @param string $action
174 - * @return void
175 165 */
176 166 public function handle_actions( $action ) {
177 167 switch ( $action ) {
178 168 case 'add':
179 169 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
180 - $errors = $this->model->add_language( $_POST );
181 170
182 - if ( is_wp_error( $errors ) ) {
183 - foreach ( $errors->get_error_messages() as $message ) {
184 - 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' ) );
185 176 }
186 - } else {
187 - add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' );
188 - $locale = sanitize_text_field( wp_unslash( $_POST['locale'] ) ); // phpcs:ignore WordPress.Security
189 177
190 - if ( 'en_US' !== $locale && current_user_can( 'install_languages' ) ) {
191 - // Attempts to install the language pack
192 - require_once ABSPATH . 'wp-admin/includes/translation-install.php';
193 - if ( ! wp_download_language_pack( $locale ) ) {
194 - add_settings_error( 'general', 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ) );
195 - }
196 -
197 - // Force checking for themes and plugins translations updates
198 - wp_clean_themes_cache();
199 - wp_clean_plugins_cache();
200 - }
178 + // Force checking for themes and plugins translations updates
179 + wp_clean_themes_cache();
180 + wp_clean_plugins_cache();
201 181 }
202 182 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
203 183 break;
204 184
@@ -204,10 +184,10 @@
204 184
205 185 case 'delete':
206 186 check_admin_referer( 'delete-lang' );
207 187
208 - if ( ! empty( $_GET['lang'] ) && $this->model->delete_language( (int) $_GET['lang'] ) ) {
209 - add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' );
188 + if ( ! empty( $_GET['lang'] ) ) {
189 + $this->model->delete_language( (int) $_GET['lang'] );
210 190 }
211 191
212 192 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
213 193 break;
@@ -213,18 +193,9 @@
213 193 break;
214 194
215 195 case 'update':
216 196 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
217 - $errors = $this->model->update_language( $_POST );
218 -
219 - if ( is_wp_error( $errors ) ) {
220 - foreach ( $errors->get_error_messages() as $message ) {
221 - add_settings_error( 'general', 'pll_update_language', $message );
222 - }
223 - } else {
224 - add_settings_error( 'general', 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'updated' );
225 - }
226 -
197 + $error = $this->model->update_language( $_POST );
227 198 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
228 199 break;
229 200
230 201 case 'default-lang':
@@ -253,25 +224,15 @@
253 224 break;
254 225
255 226 case 'activate':
256 227 check_admin_referer( 'pll_activate' );
257 - if ( isset( $_GET['module'] ) ) {
258 - $module = sanitize_key( $_GET['module'] );
259 - if ( isset( $this->modules[ $module ] ) ) {
260 - $this->modules[ $module ]->activate();
261 - }
262 - }
228 + $this->modules[ $_GET['module'] ]->activate();
263 229 self::redirect();
264 230 break;
265 231
266 232 case 'deactivate':
267 233 check_admin_referer( 'pll_deactivate' );
268 - if ( isset( $_GET['module'] ) ) {
269 - $module = sanitize_key( $_GET['module'] );
270 - if ( isset( $this->modules[ $module ] ) ) {
271 - $this->modules[ $module ]->deactivate();
272 - }
273 - }
234 + $this->modules[ $_GET['module'] ]->deactivate();
274 235 self::redirect();
275 236 break;
276 237
277 238 default:
@@ -289,10 +250,8 @@
289 250 * Displays the 3 tabs pages: languages, strings translations, settings
290 251 * Also manages user input for these pages
291 252 *
292 253 * @since 0.1
293 - *
294 - * @return void
295 254 */
296 255 public function languages_page() {
297 256 switch ( $this->active_tab ) {
298 257 case 'lang':
@@ -307,11 +266,10 @@
307 266 break;
308 267 }
309 268
310 269 // Handle user input
311 - $action = isset( $_REQUEST['pll_action'] ) ? sanitize_key( $_REQUEST['pll_action'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
312 - if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
313 - // phpcs:ignore WordPress.Security.NonceVerification, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
270 + $action = isset( $_REQUEST['pll_action'] ) ? $_REQUEST['pll_action'] : '';
271 + if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) {
314 272 $edit_lang = $this->model->get_language( (int) $_GET['lang'] );
315 273 } else {
316 274 $this->handle_actions( $action );
317 275 }
@@ -316,15 +274,13 @@
316 274 $this->handle_actions( $action );
317 275 }
318 276
319 277 // Displays the page
320 - include __DIR__ . '/view-languages.php';
278 + include PLL_SETTINGS_INC . '/view-languages.php';
321 279 }
322 280
323 281 /**
324 282 * Enqueues scripts and styles
325 - *
326 - * @return void
327 283 */
328 284 public function admin_enqueue_scripts() {
329 285 parent::admin_enqueue_scripts();
330 286
@@ -329,12 +285,12 @@
329 285 parent::admin_enqueue_scripts();
330 286
331 287 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
332 288
333 - wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $suffix . '.js', POLYLANG_BASENAME ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true );
334 - wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) );
289 + wp_enqueue_script( 'pll_admin', plugins_url( '/js/admin' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu' ), POLYLANG_VERSION );
290 + wp_localize_script( 'pll_admin', 'pll_flag_base_url', plugins_url( '/flags/', POLYLANG_FILE ) );
335 291
336 - wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/build/selectmenu' . $suffix . '.css', POLYLANG_BASENAME ), array(), POLYLANG_VERSION );
292 + wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/selectmenu' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION );
337 293 }
338 294
339 295 /**
340 296 * Displays a notice when there are objects with no language assigned
@@ -339,10 +295,8 @@
339 295 /**
340 296 * Displays a notice when there are objects with no language assigned
341 297 *
342 298 * @since 1.8
343 - *
344 - * @return void
345 299 */
346 300 public function notice_objects_with_no_lang() {
347 301 if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) {
348 302 printf(
@@ -347,9 +301,9 @@
347 301 if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) {
348 302 printf(
349 303 '<div class="error"><p>%s <a href="%s">%s</a></p></div>',
350 304 esc_html__( 'There are posts, pages, categories or tags without language.', 'polylang' ),
351 - 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' ),
352 306 esc_html__( 'You can set them all to the default language.', 'polylang' )
353 307 );
354 308 }
355 309 }
@@ -360,9 +314,8 @@
360 314 *
361 315 * @since 1.5
362 316 *
363 317 * @param array $args query arguments to add to the url
364 - * @return void
365 318 */
366 319 public static function redirect( $args = array() ) {
367 320 if ( $errors = get_settings_errors() ) {
368 321 set_transient( 'settings_errors', $errors, 30 );
@@ -376,23 +329,13 @@
376 329 /**
377 330 * Get the list of predefined languages
378 331 *
379 332 * @since 2.3
380 - *
381 - * @return string[] {
382 - * @type string $code ISO 639-1 language code.
383 - * @type string $locale WordPress locale.
384 - * @type string $name Native language name.
385 - * @type string $dir Text direction: 'ltr' or 'rtl'.
386 - * @type string $flag Flag code, generally the country code.
387 - * @type string $w3c W3C locale.
388 - * @type string $facebook Facebook locale.
389 - * }
390 333 */
391 - public static function get_predefined_languages() {
334 + public function get_predefined_languages() {
392 335 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
336 + include PLL_SETTINGS_INC . '/languages.php';
393 337
394 - $languages = include __DIR__ . '/languages.php';
395 338 $translations = wp_get_available_translations();
396 339
397 340 // Keep only languages with existing WP language pack
398 341 // Unless the transient has expired and we don't have an internet connection to refresh it
@@ -405,9 +348,9 @@
405 348 * Filter the list of predefined languages
406 349 *
407 350 * @since 1.7.10
408 351 * @since 2.3 The languages arrays use associative keys instead of numerical keys
409 - * @see https://github.com/polylang/polylang/blob/2.8.2/settings/languages.php the list of predefined languages
352 + * @see settings/languages.php
410 353 *
411 354 * @param array $languages
412 355 */
413 356 $languages = apply_filters( 'pll_predefined_languages', $languages );