PluginProbe
Polylang / 3.6.7
Polylang v3.6.7
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 +81 -87 2.73.6.7 View file →
@@ -1,44 +1,34 @@
1 1 <?php
2 +/**
3 + * @package Polylang
4 + */
2 5
3 6 /**
4 - * A class for the Polylang settings pages
5 - * accessible in $polylang global object
7 + * A class for the Polylang settings pages, accessible from @see PLL().
6 8 *
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 - *
17 9 * @since 1.2
18 10 */
19 11 class PLL_Settings extends PLL_Admin_Base {
20 12
21 13 /**
22 - * Name of the active module
23 - *
24 - * @var string $active_tab
14 + * @var PLL_Admin_Model
25 15 */
26 - protected $active_tab;
16 + public $model;
27 17
28 18 /**
29 - * Array of modules classes
19 + * Name of the active module.
30 20 *
31 - * @var array $modules
21 + * @var string|null
32 22 */
33 - protected $modules;
23 + protected $active_tab;
34 24
35 25 /**
36 - * Reference to PLL_Import_Export
26 + * Array of modules classes.
37 27 *
38 - * @var PLL_Import_Export $import_export
28 + * @var PLL_Settings_Module[]|null
39 29 */
40 - protected $import_export;
30 + protected $modules;
41 31
42 32 /**
43 33 * Constructor
44 34 *
@@ -43,9 +33,9 @@
43 33 * Constructor
44 34 *
45 35 * @since 1.2
46 36 *
47 - * @param object $links_model
37 + * @param PLL_Links_Model $links_model Reference to the links model.
48 38 */
49 39 public function __construct( &$links_model ) {
50 40 parent::__construct( $links_model );
51 41
@@ -54,21 +44,17 @@
54 44 }
55 45
56 46 PLL_Admin_Strings::init();
57 47
58 - if ( class_exists( 'PLL_Import_Export' ) ) {
59 - $this->import_export = new PLL_Import_Export( $this );
60 - }
61 -
62 - // FIXME put this as late as possible
63 48 add_action( 'admin_init', array( $this, 'register_settings_modules' ) );
64 49
65 - // Adds screen options and the about box in the languages admin panel
50 + // Adds screen options and the about box in the languages admin panel.
66 51 add_action( 'load-toplevel_page_mlang', array( $this, 'load_page' ) );
67 52 add_action( 'load-languages_page_mlang_strings', array( $this, 'load_page_strings' ) );
68 53
69 - // Saves per-page value in screen option
70 - add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
54 + // Saves the per-page value in screen options.
55 + add_filter( 'set_screen_option_pll_lang_per_page', array( $this, 'set_screen_option' ), 10, 3 );
56 + add_filter( 'set_screen_option_pll_strings_per_page', array( $this, 'set_screen_option' ), 10, 3 );
71 57 }
72 58
73 59 /**
74 60 * Initializes the modules
@@ -73,30 +59,25 @@
73 59 /**
74 60 * Initializes the modules
75 61 *
76 62 * @since 1.8
63 + *
64 + * @return void
77 65 */
78 66 public function register_settings_modules() {
79 - $modules = array(
80 - 'PLL_Settings_Licenses',
81 - );
67 + $modules = array();
82 68
83 - 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
69 + if ( $this->model->has_languages() ) {
70 + $modules = array(
71 + 'PLL_Settings_Url',
72 + 'PLL_Settings_Browser',
73 + 'PLL_Settings_Media',
74 + 'PLL_Settings_CPT',
96 75 );
97 76 }
98 77
78 + $modules[] = 'PLL_Settings_Licenses';
79 +
99 80 /**
100 81 * Filter the list of setting modules
101 82 *
102 83 * @since 1.8
@@ -114,11 +95,13 @@
114 95 /**
115 96 * Loads the about metabox
116 97 *
117 98 * @since 0.8
99 + *
100 + * @return void
118 101 */
119 102 public function metabox_about() {
120 - include PLL_SETTINGS_INC . '/view-about.php';
103 + include __DIR__ . '/view-about.php';
121 104 }
122 105
123 106 /**
124 107 * Adds screen options and the about box in the languages admin panel
@@ -123,8 +106,10 @@
123 106 /**
124 107 * Adds screen options and the about box in the languages admin panel
125 108 *
126 109 * @since 0.9.5
110 + *
111 + * @return void
127 112 */
128 113 public function load_page() {
129 114 if ( ! defined( 'PLL_DISPLAY_ABOUT' ) || PLL_DISPLAY_ABOUT ) {
130 115 add_meta_box(
@@ -151,8 +136,10 @@
151 136 /**
152 137 * Adds screen options in the strings translations admin panel
153 138 *
154 139 * @since 2.1
140 + *
141 + * @return void
155 142 */
156 143 public function load_page_strings() {
157 144 add_screen_option(
158 145 'per_page',
@@ -164,28 +151,28 @@
164 151 );
165 152 }
166 153
167 154 /**
168 - * Save the "Views/Uploads per page" option set by this user
155 + * Saves the number of rows in the languages or strings table set by this user.
169 156 *
170 157 * @since 0.9.5
171 158 *
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
175 - *
176 - * @return string New value if this is our option, otherwise nothing
159 + * @param mixed $screen_option False or value returned by a previous filter, not used.
160 + * @param string $option The name of the option, not used.
161 + * @param int $value The new value of the option to save.
162 + * @return int The new value of the option.
177 163 */
178 - public function set_screen_option( $status, $option, $value ) {
179 - return 'pll_lang_per_page' === $option || 'pll_strings_per_page' === $option ? $value : $status;
164 + public function set_screen_option( $screen_option, $option, $value ) {
165 + return (int) $value;
180 166 }
181 167
182 168 /**
183 - * Manages the user input for the languages pages
169 + * Manages the user input for the languages pages.
184 170 *
185 171 * @since 1.9
186 172 *
187 - * @param string $action
173 + * @param string $action The action name.
174 + * @return void
188 175 */
189 176 public function handle_actions( $action ) {
190 177 switch ( $action ) {
191 178 case 'add':
@@ -192,20 +179,18 @@
192 179 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
193 180 $errors = $this->model->add_language( $_POST );
194 181
195 182 if ( is_wp_error( $errors ) ) {
196 - foreach ( $errors->get_error_messages() as $message ) {
197 - add_settings_error( 'general', 'pll_add_language', $message );
198 - }
183 + pll_add_notice( $errors );
199 184 } 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
185 + pll_add_notice( new WP_Error( 'pll_languages_created', __( 'Language added.', 'polylang' ), 'success' ) );
186 + $locale = sanitize_locale_name( $_POST['locale'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
202 187
203 - if ( 'en_US' !== $locale ) {
188 + if ( 'en_US' !== $locale && current_user_can( 'install_languages' ) ) {
204 189 // Attempts to install the language pack
205 190 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
206 191 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' ) );
192 + pll_add_notice( new WP_Error( 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ), 'warning' ) );
208 193 }
209 194
210 195 // Force checking for themes and plugins translations updates
211 196 wp_clean_themes_cache();
@@ -218,9 +203,9 @@
218 203 case 'delete':
219 204 check_admin_referer( 'delete-lang' );
220 205
221 206 if ( ! empty( $_GET['lang'] ) && $this->model->delete_language( (int) $_GET['lang'] ) ) {
222 - add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' );
207 + pll_add_notice( new WP_Error( 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'success' ) );
223 208 }
224 209
225 210 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
226 211 break;
@@ -229,13 +214,11 @@
229 214 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
230 215 $errors = $this->model->update_language( $_POST );
231 216
232 217 if ( is_wp_error( $errors ) ) {
233 - foreach ( $errors->get_error_messages() as $message ) {
234 - add_settings_error( 'general', 'pll_update_language', $message );
235 - }
218 + pll_add_notice( $errors );
236 219 } else {
237 - add_settings_error( 'general', 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'updated' );
220 + pll_add_notice( new WP_Error( 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'success' ) );
238 221 }
239 222
240 223 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
241 224 break;
@@ -252,16 +235,9 @@
252 235
253 236 case 'content-default-lang':
254 237 check_admin_referer( 'content-default-lang' );
255 238
256 - if ( $nolang = $this->model->get_objects_with_no_lang() ) {
257 - if ( ! empty( $nolang['posts'] ) ) {
258 - $this->model->set_language_in_mass( 'post', $nolang['posts'], $this->options['default_lang'] );
259 - }
260 - if ( ! empty( $nolang['terms'] ) ) {
261 - $this->model->set_language_in_mass( 'term', $nolang['terms'], $this->options['default_lang'] );
262 - }
263 - }
239 + $this->model->set_language_in_mass();
264 240
265 241 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
266 242 break;
267 243
@@ -302,8 +278,10 @@
302 278 * Displays the 3 tabs pages: languages, strings translations, settings
303 279 * Also manages user input for these pages
304 280 *
305 281 * @since 0.1
282 + *
283 + * @return void
306 284 */
307 285 public function languages_page() {
308 286 switch ( $this->active_tab ) {
309 287 case 'lang':
@@ -320,9 +298,9 @@
320 298
321 299 // Handle user input
322 300 $action = isset( $_REQUEST['pll_action'] ) ? sanitize_key( $_REQUEST['pll_action'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
323 301 if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
324 - // phpcs:ignore WordPress.Security.NonceVerification, WordPressVIPMinimum.Variables.VariableAnalysis.UnusedVariable
302 + // phpcs:ignore WordPress.Security.NonceVerification, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
325 303 $edit_lang = $this->model->get_language( (int) $_GET['lang'] );
326 304 } else {
327 305 $this->handle_actions( $action );
328 306 }
@@ -327,13 +305,15 @@
327 305 $this->handle_actions( $action );
328 306 }
329 307
330 308 // Displays the page
331 - include PLL_SETTINGS_INC . '/view-languages.php';
309 + include __DIR__ . '/view-languages.php';
332 310 }
333 311
334 312 /**
335 313 * Enqueues scripts and styles
314 + *
315 + * @return void
336 316 */
337 317 public function admin_enqueue_scripts() {
338 318 parent::admin_enqueue_scripts();
339 319
@@ -338,12 +318,12 @@
338 318 parent::admin_enqueue_scripts();
339 319
340 320 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
341 321
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 );
343 - wp_localize_script( 'pll_admin', 'pll_flag_base_url', plugins_url( '/flags/', POLYLANG_FILE ) );
322 + wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $suffix . '.js', POLYLANG_ROOT_FILE ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu', 'wp-hooks' ), POLYLANG_VERSION, true );
323 + wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) );
344 324
345 - wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/selectmenu' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION );
325 + wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/build/selectmenu' . $suffix . '.css', POLYLANG_ROOT_FILE ), array(), POLYLANG_VERSION );
346 326 }
347 327
348 328 /**
349 329 * Displays a notice when there are objects with no language assigned
@@ -348,8 +328,10 @@
348 328 /**
349 329 * Displays a notice when there are objects with no language assigned
350 330 *
351 331 * @since 1.8
332 + *
333 + * @return void
352 334 */
353 335 public function notice_objects_with_no_lang() {
354 336 if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) {
355 337 printf(
@@ -367,11 +349,13 @@
367 349 *
368 350 * @since 1.5
369 351 *
370 352 * @param array $args query arguments to add to the url
353 + * @return void
371 354 */
372 355 public static function redirect( $args = array() ) {
373 - if ( $errors = get_settings_errors() ) {
356 + $errors = get_settings_errors( 'polylang' );
357 + if ( ! empty( $errors ) ) {
374 358 set_transient( 'settings_errors', $errors, 30 );
375 359 $args['settings-updated'] = 1;
376 360 }
377 361 // Remove possible 'pll_action' and 'lang' query args from the referer before redirecting
@@ -382,13 +366,23 @@
382 366 /**
383 367 * Get the list of predefined languages
384 368 *
385 369 * @since 2.3
370 + *
371 + * @return string[] {
372 + * @type string $code ISO 639-1 language code.
373 + * @type string $locale WordPress locale.
374 + * @type string $name Native language name.
375 + * @type string $dir Text direction: 'ltr' or 'rtl'.
376 + * @type string $flag Flag code, generally the country code.
377 + * @type string $w3c W3C locale.
378 + * @type string $facebook Facebook locale.
379 + * }
386 380 */
387 381 public static function get_predefined_languages() {
388 382 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
389 383
390 - $languages = include PLL_SETTINGS_INC . '/languages.php';
384 + $languages = include __DIR__ . '/languages.php';
391 385 $translations = wp_get_available_translations();
392 386
393 387 // Keep only languages with existing WP language pack
394 388 // Unless the transient has expired and we don't have an internet connection to refresh it
@@ -401,15 +395,15 @@
401 395 * Filter the list of predefined languages
402 396 *
403 397 * @since 1.7.10
404 398 * @since 2.3 The languages arrays use associative keys instead of numerical keys
405 - * @see settings/languages.php
399 + * @see https://github.com/polylang/polylang/blob/2.8.2/settings/languages.php the list of predefined languages
406 400 *
407 401 * @param array $languages
408 402 */
409 403 $languages = apply_filters( 'pll_predefined_languages', $languages );
410 404
411 - // Keep only languages with all necessary informations
405 + // Keep only languages with all necessary information
412 406 foreach ( $languages as $k => $lang ) {
413 407 if ( ! isset( $lang['code'], $lang['locale'], $lang['name'], $lang['dir'], $lang['flag'] ) ) {
414 408 unset( $languages[ $k ] );
415 409 }