| @@ -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 | |
| 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[] | |
| 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 | |
| @@ -64,8 +58,10 @@ | ||
| 64 | 58 | /** |
| 65 | 59 | * Initializes the modules |
| 66 | 60 | * |
| 67 | 61 | * @since 1.8 |
| 62 | + * | |
| 63 | + * @return void | |
| 68 | 64 | */ |
| 69 | 65 | public function register_settings_modules() { |
| 70 | 66 | $modules = array(); |
| 71 | 67 | |
| @@ -98,8 +94,10 @@ | ||
| 98 | 94 | /** |
| 99 | 95 | * Loads the about metabox |
| 100 | 96 | * |
| 101 | 97 | * @since 0.8 |
| 98 | + * | |
| 99 | + * @return void | |
| 102 | 100 | */ |
| 103 | 101 | public function metabox_about() { |
| 104 | 102 | include __DIR__ . '/view-about.php'; |
| 105 | 103 | } |
| @@ -107,8 +105,10 @@ | ||
| 107 | 105 | /** |
| 108 | 106 | * Adds screen options and the about box in the languages admin panel |
| 109 | 107 | * |
| 110 | 108 | * @since 0.9.5 |
| 109 | + * | |
| 110 | + * @return void | |
| 111 | 111 | */ |
| 112 | 112 | public function load_page() { |
| 113 | 113 | if ( ! defined( 'PLL_DISPLAY_ABOUT' ) || PLL_DISPLAY_ABOUT ) { |
| 114 | 114 | add_meta_box( |
| @@ -135,8 +135,10 @@ | ||
| 135 | 135 | /** |
| 136 | 136 | * Adds screen options in the strings translations admin panel |
| 137 | 137 | * |
| 138 | 138 | * @since 2.1 |
| 139 | + * | |
| 140 | + * @return void | |
| 139 | 141 | */ |
| 140 | 142 | public function load_page_strings() { |
| 141 | 143 | add_screen_option( |
| 142 | 144 | 'per_page', |
| @@ -168,8 +170,9 @@ | ||
| 168 | 170 | * |
| 169 | 171 | * @since 1.9 |
| 170 | 172 | * |
| 171 | 173 | * @param string $action |
| 174 | + * @return void | |
| 172 | 175 | */ |
| 173 | 176 | public function handle_actions( $action ) { |
| 174 | 177 | switch ( $action ) { |
| 175 | 178 | case 'add': |
| @@ -183,9 +186,9 @@ | ||
| 183 | 186 | } else { |
| 184 | 187 | add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' ); |
| 185 | 188 | $locale = sanitize_text_field( wp_unslash( $_POST['locale'] ) ); // phpcs:ignore WordPress.Security |
| 186 | 189 | |
| 187 | - if ( 'en_US' !== $locale ) { | |
| 190 | + if ( 'en_US' !== $locale && current_user_can( 'install_languages' ) ) { | |
| 188 | 191 | // Attempts to install the language pack |
| 189 | 192 | require_once ABSPATH . 'wp-admin/includes/translation-install.php'; |
| 190 | 193 | if ( ! wp_download_language_pack( $locale ) ) { |
| 191 | 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' ) ); |
| @@ -286,8 +289,10 @@ | ||
| 286 | 289 | * Displays the 3 tabs pages: languages, strings translations, settings |
| 287 | 290 | * Also manages user input for these pages |
| 288 | 291 | * |
| 289 | 292 | * @since 0.1 |
| 293 | + * | |
| 294 | + * @return void | |
| 290 | 295 | */ |
| 291 | 296 | public function languages_page() { |
| 292 | 297 | switch ( $this->active_tab ) { |
| 293 | 298 | case 'lang': |
| @@ -304,9 +309,9 @@ | ||
| 304 | 309 | |
| 305 | 310 | // Handle user input |
| 306 | 311 | $action = isset( $_REQUEST['pll_action'] ) ? sanitize_key( $_REQUEST['pll_action'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
| 307 | 312 | if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 308 | - // phpcs:ignore WordPress.Security.NonceVerification, WordPressVIPMinimum.Variables.VariableAnalysis.UnusedVariable | |
| 313 | + // phpcs:ignore WordPress.Security.NonceVerification, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 309 | 314 | $edit_lang = $this->model->get_language( (int) $_GET['lang'] ); |
| 310 | 315 | } else { |
| 311 | 316 | $this->handle_actions( $action ); |
| 312 | 317 | } |
| @@ -316,8 +321,10 @@ | ||
| 316 | 321 | } |
| 317 | 322 | |
| 318 | 323 | /** |
| 319 | 324 | * Enqueues scripts and styles |
| 325 | + * | |
| 326 | + * @return void | |
| 320 | 327 | */ |
| 321 | 328 | public function admin_enqueue_scripts() { |
| 322 | 329 | parent::admin_enqueue_scripts(); |
| 323 | 330 | |
| @@ -322,12 +329,12 @@ | ||
| 322 | 329 | parent::admin_enqueue_scripts(); |
| 323 | 330 | |
| 324 | 331 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 325 | 332 | |
| 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 ) ); | |
| 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' ) ) ); | |
| 328 | 335 | |
| 329 | - 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 ); | |
| 330 | 337 | } |
| 331 | 338 | |
| 332 | 339 | /** |
| 333 | 340 | * Displays a notice when there are objects with no language assigned |
| @@ -332,8 +339,10 @@ | ||
| 332 | 339 | /** |
| 333 | 340 | * Displays a notice when there are objects with no language assigned |
| 334 | 341 | * |
| 335 | 342 | * @since 1.8 |
| 343 | + * | |
| 344 | + * @return void | |
| 336 | 345 | */ |
| 337 | 346 | public function notice_objects_with_no_lang() { |
| 338 | 347 | if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) { |
| 339 | 348 | printf( |
| @@ -351,8 +360,9 @@ | ||
| 351 | 360 | * |
| 352 | 361 | * @since 1.5 |
| 353 | 362 | * |
| 354 | 363 | * @param array $args query arguments to add to the url |
| 364 | + * @return void | |
| 355 | 365 | */ |
| 356 | 366 | public static function redirect( $args = array() ) { |
| 357 | 367 | if ( $errors = get_settings_errors() ) { |
| 358 | 368 | set_transient( 'settings_errors', $errors, 30 ); |
| @@ -366,8 +376,18 @@ | ||
| 366 | 376 | /** |
| 367 | 377 | * Get the list of predefined languages |
| 368 | 378 | * |
| 369 | 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 | + * } | |
| 370 | 390 | */ |
| 371 | 391 | public static function get_predefined_languages() { |
| 372 | 392 | require_once ABSPATH . 'wp-admin/includes/translation-install.php'; |
| 373 | 393 | |
| @@ -385,9 +405,9 @@ | ||
| 385 | 405 | * Filter the list of predefined languages |
| 386 | 406 | * |
| 387 | 407 | * @since 1.7.10 |
| 388 | 408 | * @since 2.3 The languages arrays use associative keys instead of numerical keys |
| 389 | - * @see settings/languages.php | |
| 409 | + * @see https://github.com/polylang/polylang/blob/2.8.2/settings/languages.php the list of predefined languages | |
| 390 | 410 | * |
| 391 | 411 | * @param array $languages |
| 392 | 412 | */ |
| 393 | 413 | $languages = apply_filters( 'pll_predefined_languages', $languages ); |