PluginProbe
Polylang / 2.6.2
Polylang v2.6.2
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 +42 -70 3.02.6.2 View file →
@@ -1,41 +1,31 @@
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
@@ -44,8 +34,9 @@
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,9 +161,8 @@
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':
@@ -186,9 +176,9 @@
186 176 } else {
187 177 add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' );
188 178 $locale = sanitize_text_field( wp_unslash( $_POST['locale'] ) ); // phpcs:ignore WordPress.Security
189 179
190 - if ( 'en_US' !== $locale && current_user_can( 'install_languages' ) ) {
180 + if ( 'en_US' !== $locale ) {
191 181 // Attempts to install the language pack
192 182 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
193 183 if ( ! wp_download_language_pack( $locale ) ) {
194 184 add_settings_error( 'general', 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ) );
@@ -289,10 +279,8 @@
289 279 * Displays the 3 tabs pages: languages, strings translations, settings
290 280 * Also manages user input for these pages
291 281 *
292 282 * @since 0.1
293 - *
294 - * @return void
295 283 */
296 284 public function languages_page() {
297 285 switch ( $this->active_tab ) {
298 286 case 'lang':
@@ -309,22 +297,19 @@
309 297
310 298 // Handle user input
311 299 $action = isset( $_REQUEST['pll_action'] ) ? sanitize_key( $_REQUEST['pll_action'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
312 300 if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
313 - // phpcs:ignore WordPress.Security.NonceVerification, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
314 - $edit_lang = $this->model->get_language( (int) $_GET['lang'] );
301 + $edit_lang = $this->model->get_language( (int) $_GET['lang'] ); // phpcs:ignore WordPress.Security.NonceVerification
315 302 } else {
316 303 $this->handle_actions( $action );
317 304 }
318 305
319 306 // Displays the page
320 - include __DIR__ . '/view-languages.php';
307 + include PLL_SETTINGS_INC . '/view-languages.php';
321 308 }
322 309
323 310 /**
324 311 * Enqueues scripts and styles
325 - *
326 - * @return void
327 312 */
328 313 public function admin_enqueue_scripts() {
329 314 parent::admin_enqueue_scripts();
330 315
@@ -329,12 +314,12 @@
329 314 parent::admin_enqueue_scripts();
330 315
331 316 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
332 317
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' ) ) );
318 + wp_enqueue_script( 'pll_admin', plugins_url( '/js/admin' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu' ), POLYLANG_VERSION );
319 + wp_localize_script( 'pll_admin', 'pll_flag_base_url', plugins_url( '/flags/', POLYLANG_FILE ) );
335 320
336 - wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/build/selectmenu' . $suffix . '.css', POLYLANG_BASENAME ), array(), POLYLANG_VERSION );
321 + wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/selectmenu' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION );
337 322 }
338 323
339 324 /**
340 325 * Displays a notice when there are objects with no language assigned
@@ -339,10 +324,8 @@
339 324 /**
340 325 * Displays a notice when there are objects with no language assigned
341 326 *
342 327 * @since 1.8
343 - *
344 - * @return void
345 328 */
346 329 public function notice_objects_with_no_lang() {
347 330 if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) {
348 331 printf(
@@ -360,9 +343,8 @@
360 343 *
361 344 * @since 1.5
362 345 *
363 346 * @param array $args query arguments to add to the url
364 - * @return void
365 347 */
366 348 public static function redirect( $args = array() ) {
367 349 if ( $errors = get_settings_errors() ) {
368 350 set_transient( 'settings_errors', $errors, 30 );
@@ -376,23 +358,13 @@
376 358 /**
377 359 * Get the list of predefined languages
378 360 *
379 361 * @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 362 */
391 - public static function get_predefined_languages() {
363 + public function get_predefined_languages() {
392 364 require_once ABSPATH . 'wp-admin/includes/translation-install.php';
393 365
394 - $languages = include __DIR__ . '/languages.php';
366 + $languages = include PLL_SETTINGS_INC . '/languages.php';
395 367 $translations = wp_get_available_translations();
396 368
397 369 // Keep only languages with existing WP language pack
398 370 // Unless the transient has expired and we don't have an internet connection to refresh it
@@ -405,9 +377,9 @@
405 377 * Filter the list of predefined languages
406 378 *
407 379 * @since 1.7.10
408 380 * @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
381 + * @see settings/languages.php
410 382 *
411 383 * @param array $languages
412 384 */
413 385 $languages = apply_filters( 'pll_predefined_languages', $languages );