PluginProbe
Polylang / 3.1.4
Polylang v3.1.4
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 +56 -52 2.7.23.1.4 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
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[]
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,13 +44,8 @@
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 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' ) );
@@ -73,30 +58,25 @@
73 58 /**
74 59 * Initializes the modules
75 60 *
76 61 * @since 1.8
62 + *
63 + * @return void
77 64 */
78 65 public function register_settings_modules() {
79 - $modules = array(
80 - 'PLL_Settings_Licenses',
81 - );
66 + $modules = array();
82 67
83 68 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 + $modules = array(
70 + 'PLL_Settings_Url',
71 + 'PLL_Settings_Browser',
72 + 'PLL_Settings_Media',
73 + 'PLL_Settings_CPT',
96 74 );
97 75 }
98 76
77 + $modules[] = 'PLL_Settings_Licenses';
78 +
99 79 /**
100 80 * Filter the list of setting modules
101 81 *
102 82 * @since 1.8
@@ -114,11 +94,13 @@
114 94 /**
115 95 * Loads the about metabox
116 96 *
117 97 * @since 0.8
98 + *
99 + * @return void
118 100 */
119 101 public function metabox_about() {
120 - include PLL_SETTINGS_INC . '/view-about.php';
102 + include __DIR__ . '/view-about.php';
121 103 }
122 104
123 105 /**
124 106 * Adds screen options and the about box in the languages admin panel
@@ -123,8 +105,10 @@
123 105 /**
124 106 * Adds screen options and the about box in the languages admin panel
125 107 *
126 108 * @since 0.9.5
109 + *
110 + * @return void
127 111 */
128 112 public function load_page() {
129 113 if ( ! defined( 'PLL_DISPLAY_ABOUT' ) || PLL_DISPLAY_ABOUT ) {
130 114 add_meta_box(
@@ -151,8 +135,10 @@
151 135 /**
152 136 * Adds screen options in the strings translations admin panel
153 137 *
154 138 * @since 2.1
139 + *
140 + * @return void
155 141 */
156 142 public function load_page_strings() {
157 143 add_screen_option(
158 144 'per_page',
@@ -184,8 +170,9 @@
184 170 *
185 171 * @since 1.9
186 172 *
187 173 * @param string $action
174 + * @return void
188 175 */
189 176 public function handle_actions( $action ) {
190 177 switch ( $action ) {
191 178 case 'add':
@@ -199,9 +186,9 @@
199 186 } else {
200 187 add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' );
201 188 $locale = sanitize_text_field( wp_unslash( $_POST['locale'] ) ); // phpcs:ignore WordPress.Security
202 189
203 - if ( 'en_US' !== $locale ) {
190 + if ( 'en_US' !== $locale && current_user_can( 'install_languages' ) ) {
204 191 // Attempts to install the language pack
205 192 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
206 193 if ( ! wp_download_language_pack( $locale ) ) {
207 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' ) );
@@ -302,8 +289,10 @@
302 289 * Displays the 3 tabs pages: languages, strings translations, settings
303 290 * Also manages user input for these pages
304 291 *
305 292 * @since 0.1
293 + *
294 + * @return void
306 295 */
307 296 public function languages_page() {
308 297 switch ( $this->active_tab ) {
309 298 case 'lang':
@@ -320,9 +309,9 @@
320 309
321 310 // Handle user input
322 311 $action = isset( $_REQUEST['pll_action'] ) ? sanitize_key( $_REQUEST['pll_action'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
323 312 if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
324 - // phpcs:ignore WordPress.Security.NonceVerification, WordPressVIPMinimum.Variables.VariableAnalysis.UnusedVariable
313 + // phpcs:ignore WordPress.Security.NonceVerification, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
325 314 $edit_lang = $this->model->get_language( (int) $_GET['lang'] );
326 315 } else {
327 316 $this->handle_actions( $action );
328 317 }
@@ -327,13 +316,15 @@
327 316 $this->handle_actions( $action );
328 317 }
329 318
330 319 // Displays the page
331 - include PLL_SETTINGS_INC . '/view-languages.php';
320 + include __DIR__ . '/view-languages.php';
332 321 }
333 322
334 323 /**
335 324 * Enqueues scripts and styles
325 + *
326 + * @return void
336 327 */
337 328 public function admin_enqueue_scripts() {
338 329 parent::admin_enqueue_scripts();
339 330
@@ -338,12 +329,12 @@
338 329 parent::admin_enqueue_scripts();
339 330
340 331 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
341 332
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 ) );
333 + wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $suffix . '.js', POLYLANG_ROOT_FILE ), 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' ) ) );
344 335
345 - wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/selectmenu' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION );
336 + wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/build/selectmenu' . $suffix . '.css', POLYLANG_ROOT_FILE ), array(), POLYLANG_VERSION );
346 337 }
347 338
348 339 /**
349 340 * Displays a notice when there are objects with no language assigned
@@ -348,8 +339,10 @@
348 339 /**
349 340 * Displays a notice when there are objects with no language assigned
350 341 *
351 342 * @since 1.8
343 + *
344 + * @return void
352 345 */
353 346 public function notice_objects_with_no_lang() {
354 347 if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) {
355 348 printf(
@@ -367,8 +360,9 @@
367 360 *
368 361 * @since 1.5
369 362 *
370 363 * @param array $args query arguments to add to the url
364 + * @return void
371 365 */
372 366 public static function redirect( $args = array() ) {
373 367 if ( $errors = get_settings_errors() ) {
374 368 set_transient( 'settings_errors', $errors, 30 );
@@ -382,13 +376,23 @@
382 376 /**
383 377 * Get the list of predefined languages
384 378 *
385 379 * @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 + * }
386 390 */
387 391 public static function get_predefined_languages() {
388 392 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
389 393
390 - $languages = include PLL_SETTINGS_INC . '/languages.php';
394 + $languages = include __DIR__ . '/languages.php';
391 395 $translations = wp_get_available_translations();
392 396
393 397 // Keep only languages with existing WP language pack
394 398 // Unless the transient has expired and we don't have an internet connection to refresh it
@@ -401,9 +405,9 @@
401 405 * Filter the list of predefined languages
402 406 *
403 407 * @since 1.7.10
404 408 * @since 2.3 The languages arrays use associative keys instead of numerical keys
405 - * @see settings/languages.php
409 + * @see https://github.com/polylang/polylang/blob/2.8.2/settings/languages.php the list of predefined languages
406 410 *
407 411 * @param array $languages
408 412 */
409 413 $languages = apply_filters( 'pll_predefined_languages', $languages );