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 +65 -56 2.93.6.7 View file →
@@ -3,36 +3,30 @@
3 3 * @package Polylang
4 4 */
5 5
6 6 /**
7 - * A class for the Polylang settings pages
8 - * accessible in $polylang global object
7 + * A class for the Polylang settings pages, accessible from @see PLL().
9 8 *
10 - * Properties:
11 - * options => inherited, reference to Polylang options array
12 - * model => inherited, reference to PLL_Model object
13 - * links_model => inherited, reference to PLL_Links_Model object
14 - * links => inherited, reference to PLL_Admin_Links object
15 - * static_pages => inherited, reference to PLL_Admin_Static_Pages object
16 - * filters_links => inherited, reference to PLL_Filters_Links object
17 - * curlang => inherited, optional, current language used to filter admin content
18 - * pref_lang => inherited, preferred language used as default when saving posts or terms
19 - *
20 9 * @since 1.2
21 10 */
22 11 class PLL_Settings extends PLL_Admin_Base {
23 12
24 13 /**
25 - * Name of the active module
14 + * @var PLL_Admin_Model
15 + */
16 + public $model;
17 +
18 + /**
19 + * Name of the active module.
26 20 *
27 - * @var string $active_tab
21 + * @var string|null
28 22 */
29 23 protected $active_tab;
30 24
31 25 /**
32 - * Array of modules classes
26 + * Array of modules classes.
33 27 *
34 - * @var array $modules
28 + * @var PLL_Settings_Module[]|null
35 29 */
36 30 protected $modules;
37 31
38 32 /**
@@ -39,9 +33,9 @@
39 33 * Constructor
40 34 *
41 35 * @since 1.2
42 36 *
43 - * @param object $links_model
37 + * @param PLL_Links_Model $links_model Reference to the links model.
44 38 */
45 39 public function __construct( &$links_model ) {
46 40 parent::__construct( $links_model );
47 41
@@ -52,14 +46,15 @@
52 46 PLL_Admin_Strings::init();
53 47
54 48 add_action( 'admin_init', array( $this, 'register_settings_modules' ) );
55 49
56 - // 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.
57 51 add_action( 'load-toplevel_page_mlang', array( $this, 'load_page' ) );
58 52 add_action( 'load-languages_page_mlang_strings', array( $this, 'load_page_strings' ) );
59 53
60 - // Saves per-page value in screen option
61 - 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 );
62 57 }
63 58
64 59 /**
65 60 * Initializes the modules
@@ -64,13 +59,15 @@
64 59 /**
65 60 * Initializes the modules
66 61 *
67 62 * @since 1.8
63 + *
64 + * @return void
68 65 */
69 66 public function register_settings_modules() {
70 67 $modules = array();
71 68
72 - if ( $this->model->get_languages_list() ) {
69 + if ( $this->model->has_languages() ) {
73 70 $modules = array(
74 71 'PLL_Settings_Url',
75 72 'PLL_Settings_Browser',
76 73 'PLL_Settings_Media',
@@ -98,8 +95,10 @@
98 95 /**
99 96 * Loads the about metabox
100 97 *
101 98 * @since 0.8
99 + *
100 + * @return void
102 101 */
103 102 public function metabox_about() {
104 103 include __DIR__ . '/view-about.php';
105 104 }
@@ -107,8 +106,10 @@
107 106 /**
108 107 * Adds screen options and the about box in the languages admin panel
109 108 *
110 109 * @since 0.9.5
110 + *
111 + * @return void
111 112 */
112 113 public function load_page() {
113 114 if ( ! defined( 'PLL_DISPLAY_ABOUT' ) || PLL_DISPLAY_ABOUT ) {
114 115 add_meta_box(
@@ -135,8 +136,10 @@
135 136 /**
136 137 * Adds screen options in the strings translations admin panel
137 138 *
138 139 * @since 2.1
140 + *
141 + * @return void
139 142 */
140 143 public function load_page_strings() {
141 144 add_screen_option(
142 145 'per_page',
@@ -148,28 +151,28 @@
148 151 );
149 152 }
150 153
151 154 /**
152 - * 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.
153 156 *
154 157 * @since 0.9.5
155 158 *
156 - * @param mixed $status false or value returned by previous filter
157 - * @param string $option Name of the option being changed
158 - * @param string $value Value of the option
159 - *
160 - * @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.
161 163 */
162 - public function set_screen_option( $status, $option, $value ) {
163 - 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;
164 166 }
165 167
166 168 /**
167 - * Manages the user input for the languages pages
169 + * Manages the user input for the languages pages.
168 170 *
169 171 * @since 1.9
170 172 *
171 - * @param string $action
173 + * @param string $action The action name.
174 + * @return void
172 175 */
173 176 public function handle_actions( $action ) {
174 177 switch ( $action ) {
175 178 case 'add':
@@ -176,20 +179,18 @@
176 179 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
177 180 $errors = $this->model->add_language( $_POST );
178 181
179 182 if ( is_wp_error( $errors ) ) {
180 - foreach ( $errors->get_error_messages() as $message ) {
181 - add_settings_error( 'general', 'pll_add_language', $message );
182 - }
183 + pll_add_notice( $errors );
183 184 } 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
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
186 187
187 188 if ( 'en_US' !== $locale && current_user_can( 'install_languages' ) ) {
188 189 // Attempts to install the language pack
189 190 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
190 191 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 + 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' ) );
192 193 }
193 194
194 195 // Force checking for themes and plugins translations updates
195 196 wp_clean_themes_cache();
@@ -202,9 +203,9 @@
202 203 case 'delete':
203 204 check_admin_referer( 'delete-lang' );
204 205
205 206 if ( ! empty( $_GET['lang'] ) && $this->model->delete_language( (int) $_GET['lang'] ) ) {
206 - 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' ) );
207 208 }
208 209
209 210 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
210 211 break;
@@ -213,13 +214,11 @@
213 214 check_admin_referer( 'add-lang', '_wpnonce_add-lang' );
214 215 $errors = $this->model->update_language( $_POST );
215 216
216 217 if ( is_wp_error( $errors ) ) {
217 - foreach ( $errors->get_error_messages() as $message ) {
218 - add_settings_error( 'general', 'pll_update_language', $message );
219 - }
218 + pll_add_notice( $errors );
220 219 } else {
221 - 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' ) );
222 221 }
223 222
224 223 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
225 224 break;
@@ -236,16 +235,9 @@
236 235
237 236 case 'content-default-lang':
238 237 check_admin_referer( 'content-default-lang' );
239 238
240 - if ( $nolang = $this->model->get_objects_with_no_lang() ) {
241 - if ( ! empty( $nolang['posts'] ) ) {
242 - $this->model->set_language_in_mass( 'post', $nolang['posts'], $this->options['default_lang'] );
243 - }
244 - if ( ! empty( $nolang['terms'] ) ) {
245 - $this->model->set_language_in_mass( 'term', $nolang['terms'], $this->options['default_lang'] );
246 - }
247 - }
239 + $this->model->set_language_in_mass();
248 240
249 241 self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true )
250 242 break;
251 243
@@ -286,8 +278,10 @@
286 278 * Displays the 3 tabs pages: languages, strings translations, settings
287 279 * Also manages user input for these pages
288 280 *
289 281 * @since 0.1
282 + *
283 + * @return void
290 284 */
291 285 public function languages_page() {
292 286 switch ( $this->active_tab ) {
293 287 case 'lang':
@@ -316,8 +310,10 @@
316 310 }
317 311
318 312 /**
319 313 * Enqueues scripts and styles
314 + *
315 + * @return void
320 316 */
321 317 public function admin_enqueue_scripts() {
322 318 parent::admin_enqueue_scripts();
323 319
@@ -322,13 +318,12 @@
322 318 parent::admin_enqueue_scripts();
323 319
324 320 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
325 321
326 - wp_enqueue_script( 'pll_admin', plugins_url( '/js/admin' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu' ), POLYLANG_VERSION );
327 - wp_localize_script( 'pll_admin', 'pll_flag_base_url', plugins_url( '/flags/', POLYLANG_FILE ) );
328 - wp_localize_script( 'pll_admin', 'pll_dismiss_notice', esc_html__( 'Dismiss this notice.', 'polylang' ) );
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' ) ) );
329 324
330 - 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 );
331 326 }
332 327
333 328 /**
334 329 * Displays a notice when there are objects with no language assigned
@@ -333,8 +328,10 @@
333 328 /**
334 329 * Displays a notice when there are objects with no language assigned
335 330 *
336 331 * @since 1.8
332 + *
333 + * @return void
337 334 */
338 335 public function notice_objects_with_no_lang() {
339 336 if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) {
340 337 printf(
@@ -352,11 +349,13 @@
352 349 *
353 350 * @since 1.5
354 351 *
355 352 * @param array $args query arguments to add to the url
353 + * @return void
356 354 */
357 355 public static function redirect( $args = array() ) {
358 - if ( $errors = get_settings_errors() ) {
356 + $errors = get_settings_errors( 'polylang' );
357 + if ( ! empty( $errors ) ) {
359 358 set_transient( 'settings_errors', $errors, 30 );
360 359 $args['settings-updated'] = 1;
361 360 }
362 361 // Remove possible 'pll_action' and 'lang' query args from the referer before redirecting
@@ -367,8 +366,18 @@
367 366 /**
368 367 * Get the list of predefined languages
369 368 *
370 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 + * }
371 380 */
372 381 public static function get_predefined_languages() {
373 382 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
374 383
@@ -392,9 +401,9 @@
392 401 * @param array $languages
393 402 */
394 403 $languages = apply_filters( 'pll_predefined_languages', $languages );
395 404
396 - // Keep only languages with all necessary informations
405 + // Keep only languages with all necessary information
397 406 foreach ( $languages as $k => $lang ) {
398 407 if ( ! isset( $lang['code'], $lang['locale'], $lang['name'], $lang['dir'], $lang['flag'] ) ) {
399 408 unset( $languages[ $k ] );
400 409 }